Skip to content

Commit

Permalink
Merge branch 'master' into autoimport_autodetect
Browse files Browse the repository at this point in the history
  • Loading branch information
bagel897 authored Jan 22, 2024
2 parents ef1c0a8 + faddd3a commit ef237d4
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,15 @@
"contributions": [
"code"
]
},
{
"login": "raymyers",
"name": "Ray Myers",
"avatar_url": "https://avatars.githubusercontent.com/u/3324?v=4",
"profile": "http://mender.ai",
"contributions": [
"code"
]
}
],
"projectName": "rope",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# **Upcoming release**

- #516 Autoimport Now automatically detects project dependencies and can read TOML configuration

# Release 1.12.0

- #733 skip directories with perm error when building autoimport index (@MrBago)
- #722, #723 Remove site-packages from packages search tree (@tkrabel)
- #738 Implement os.PathLike on Resource (@lieryan)
- #739, #736 Ensure autoimport requests uses indexes (@lieryan)
- #734, #735 raise exception when extracting the start of a block without the end

# Release 1.11.0

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/apmorton"><img src="https://avatars.githubusercontent.com/u/63636?v=4?s=100" width="100px;" alt="Austin Morton"/><br /><sub><b>Austin Morton</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=apmorton" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://bamboolib.8080labs.com"><img src="https://avatars.githubusercontent.com/u/13402027?v=4?s=100" width="100px;" alt="Tobias Krabel"/><br /><sub><b>Tobias Krabel</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=tkrabel" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/MrBago"><img src="https://avatars.githubusercontent.com/u/223219?v=4?s=100" width="100px;" alt="Bago Amirbekian"/><br /><sub><b>Bago Amirbekian</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=MrBago" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://mender.ai"><img src="https://avatars.githubusercontent.com/u/3324?v=4?s=100" width="100px;" alt="Ray Myers"/><br /><sub><b>Ray Myers</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=raymyers" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
15 changes: 8 additions & 7 deletions docs/release-process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ Release

1. Ensure tickets assigned to Milestones are up to date
2. Update ``CHANGELOG.md``
3. Increment version number in ``pyproject.toml``
4. `git commit && git push`
5. Tag the release with the tag annotation containing the release information,
3. Close milestone
4. Increment version number in ``pyproject.toml``
5. `git commit && git push`
6. Tag the release with the tag annotation containing the release information,
``python bin/tag-release.py``
6. ``python3 -m build``
7. ``twine upload dist/rope-$VERSION.{tar.gz,whl}``
8. Publish to Discussions Announcement
9. Close milestone
7. ``python3 -m build``
8. ``twine upload dist/rope-$VERSION.{tar.gz,whl}``
9. Publish to Discussions Announcement
10. Create Github Release


Release Schedule
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
'Programming Language :: Python :: 3.12',
'Topic :: Software Development',
]
version = '1.11.0'
version = '1.12.0'
dependencies = ['pytoolconfig[global] >= 1.2.2']

[[project.authors]]
Expand Down
38 changes: 38 additions & 0 deletions rope/refactor/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,10 @@ def __call__(self, info):
def base_conditions(self, info):
if info.region[1] > info.scope_region[1]:
raise RefactoringError("Bad region selected for extract method")

end_line = info.region_lines[1]
end_scope = info.global_scope.get_inner_scope_for_line(end_line)

if end_scope != info.scope and end_scope.get_end() != end_line:
raise RefactoringError("Bad region selected for extract method")
try:
Expand Down Expand Up @@ -497,6 +499,14 @@ def multi_line_conditions(self, info):
raise RefactoringError(
"Extracted piece should contain complete statements."
)
unbalanced_region_finder = _UnbalancedRegionFinder(
info.region_lines[0], info.region_lines[1]
)
unbalanced_region_finder.visit(info.pymodule.ast_node)
if unbalanced_region_finder.error:
raise RefactoringError(
"Extracted piece cannot contain the start of a block without the end."
)

def _is_region_on_a_word(self, info):
if (
Expand Down Expand Up @@ -1093,6 +1103,34 @@ def _ClassDef(self, node):
pass


class _UnbalancedRegionFinder(_BaseErrorFinder):
"""
Flag an error if we are including the start of a block without the end.
We detect this by ensuring there is no AST node that starts inside the
selected range but ends outside of it.
"""

def __init__(self, line_start: int, line_end: int):
self.error = False
self.line_start = line_start
self.line_end = line_end

def generic_visit(self, node: ast.AST):
if not hasattr(node, "end_lineno"):
super().generic_visit(node) # Visit children
return
ends_before_range_starts = node.end_lineno < self.line_start
starts_after_range_ends = node.lineno > self.line_end
if ends_before_range_starts or starts_after_range_ends:
return # Don't visit children
starts_on_or_after_range_start = node.lineno >= self.line_start
ends_after_range_ends = node.end_lineno > self.line_end
if starts_on_or_after_range_start and ends_after_range_ends:
self.error = True
return # Don't visit children
super().generic_visit(node) # Visit children


class _GlobalFinder(ast.RopeNodeVisitor):
def __init__(self):
self.globals_ = OrderedSet()
Expand Down
58 changes: 58 additions & 0 deletions ropetest/refactor/extracttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,64 @@ def xxx_test_raising_exception_on_function_parens(self):
end = code.rindex(")") + 1
with self.assertRaises(rope.base.exceptions.RefactoringError):
self.do_extract_method(code, start, end, "new_func")

def test_raising_exception_on_incomplete_block(self):
code = dedent("""\
if True:
a = 1
b = 2
""")
start = code.index("if")
end = code.index("1") + 1
with self.assertRaises(rope.base.exceptions.RefactoringError):
self.do_extract_method(code, start, end, "new_func")

def test_raising_exception_on_incomplete_block_2(self):
code = dedent("""\
if True:
a = 1
#
b = 2
""")
start = code.index("if")
end = code.index("1") + 1
with self.assertRaises(rope.base.exceptions.RefactoringError):
self.do_extract_method(code, start, end, "new_func")

def test_raising_exception_on_incomplete_block_3(self):
code = dedent("""\
if True:
a = 1
b = 2
""")
start = code.index("if")
end = code.index("1") + 1
with self.assertRaises(rope.base.exceptions.RefactoringError):
self.do_extract_method(code, start, end, "new_func")

def test_raising_exception_on_incomplete_block_4(self):
code = dedent("""\
#
if True:
a = 1
b = 2
""")
start = code.index("#")
end = code.index("1") + 1
with self.assertRaises(rope.base.exceptions.RefactoringError):
self.do_extract_method(code, start, end, "new_func")

def test_raising_exception_on_incomplete_block_5(self):
code = dedent("""\
if True:
if 0:
a = 1
""")
start = code.index("if")
end = code.index("0:") + 2
with self.assertRaises(rope.base.exceptions.RefactoringError):
self.do_extract_method(code, start, end, "new_func")

def test_extract_method_and_extra_blank_lines(self):
code = dedent("""\
Expand Down

0 comments on commit ef237d4

Please sign in to comment.