-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
188 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/maintainability)](https://codeclimate.com/github/lalmei/asunder/maintainability) | ||
|
||
[![Test Coverage](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/test_coverage)](https://codeclimate.com/github/lalmei/asunder/test_coverage) | ||
|
||
|
||
[![asunder](https://github.com/lalmei/asunder/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/lalmei/asunder/actions/workflows/main.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/maintainability)](https://codeclimate.com/github/lalmei/asunder/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/test_coverage)](https://codeclimate.com/github/lalmei/asunder/test_coverage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
* [Overview](index.md) | ||
* Initial Setup | ||
* [Get Started](get_started.md) | ||
* Basic Usage | ||
* [Refactoring](basic_usage/refactoring.md) | ||
* [Help & Get Help](help.md) | ||
* [Release Notes](changelog.md) | ||
* [Code Reference](reference/) | ||
* Initial Setup | ||
* [Get Started](get_started.md) | ||
* Basic Usage | ||
* [Refactoring](basic_usage/refactoring.md) | ||
* [Help & Get Help](help.md) | ||
* [Release Notes](changelog.md) | ||
* [Code Reference](reference/) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from asunder.rope_sdk.refactor.rename.rename import rename, rename_module | ||
|
||
__all__: list[str] = ["rename_module, rename"] | ||
__all__: list[str] = ["rename_module", "rename"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
from functools import partial | ||
from typing import Optional | ||
|
||
from rope.base.project import Project as RopeProject | ||
from rope.refactor.occurrences import Finder | ||
from rope.refactor.occurrences import Finder, Occurrence | ||
|
||
from asunder.utils.logging import get_logger_console | ||
|
||
|
||
def find_definition_in_resource( | ||
repo_project: RopeProject, name: str, resource: str | ||
): | ||
repo_project: RopeProject, name: Optional[str], resource: Optional[str] | ||
) -> Occurrence: | ||
FINDER = partial(Finder, repo_project) | ||
finder = FINDER(name) | ||
return next( | ||
occ | ||
for occ in finder.find_occurrences(resource=resource) | ||
if occ.is_defined() or occ.is_written() | ||
) | ||
logger, console = get_logger_console() | ||
console.print(finder.find_occurrences(resource=resource)) | ||
for occ in finder.find_occurrences(resource=resource): | ||
console.print(occ) | ||
if occ.is_defined(): | ||
return occ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,45 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from rope.base.change import ChangeSet | ||
from rope.base.project import Project as RopeProject | ||
from rope.refactor.rename import Rename | ||
|
||
from asunder.rope_sdk.find import find_definition_in_resource | ||
from asunder.utils.logging import get_logger_console | ||
|
||
logger = logging.getLogger("asunder") | ||
|
||
|
||
def rename_module( | ||
rope_project: RopeProject, module: str, to_name: str | ||
rope_project: RopeProject, module: Optional[str], to_name: Optional[str] | ||
) -> ChangeSet: | ||
module_resource = rope_project.get_resource(module) | ||
return Rename(rope_project, module_resource).get_changes(to_name) | ||
|
||
|
||
def rename( | ||
rope_project: RopeProject, module: str, from_name: str, to_name: str | ||
rope_project: RopeProject, | ||
resource: Path, | ||
from_name: Optional[str], | ||
to_name: Optional[str], | ||
) -> ChangeSet: | ||
module_resource = rope_project.get_resource(module) | ||
definition_occurrence = find_definition_in_resource( | ||
rope_project, from_name, module_resource | ||
) | ||
return Rename( | ||
rope_project, module_resource, definition_occurrence.offset | ||
).get_changes(to_name) | ||
module_resource = rope_project.get_resource(str(resource)) | ||
logger, console = get_logger_console() | ||
# console.print(dir(module_resource)) | ||
if module_resource.is_folder(): | ||
if from_name in [ | ||
Path(x._path).stem for x in module_resource.get_files() | ||
]: | ||
new_resource = resource / Path(from_name + ".py") | ||
changes = rename_module(rope_project, str(new_resource), to_name) | ||
return changes | ||
|
||
else: | ||
definition_occurrence = find_definition_in_resource( | ||
rope_project, from_name, module_resource | ||
) | ||
return Rename( | ||
rope_project, module_resource, definition_occurrence.offset | ||
).get_changes(to_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def my_function(): | ||
myresult = 1 + 1 | ||
|
||
return myresult |
Oops, something went wrong.