Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tierra-colada/pythonguts
Tool aimed at python code correction that allows to automatically find and replace function definition
https://github.com/tierra-colada/pythonguts
Last synced: 4 days ago
JSON representation
Tool aimed at python code correction that allows to automatically find and replace function definition
- Host: GitHub
- URL: https://github.com/tierra-colada/pythonguts
- Owner: tierra-colada
- License: mit
- Created: 2021-10-05T15:46:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-06T15:26:35.000Z (over 3 years ago)
- Last Synced: 2024-12-19T22:49:05.740Z (about 1 month ago)
- Language: Python
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pythonguts
If your project depends on some external python projects and
you want to make some changes in external functions/methods
and then copy/paste these changes automatically - this package may help you.There is a tool `editpy` wich we will discuss.
Same tool aimed at editing `cpp` files is also available as [cppguts](https://github.com/tierra-colada/cppguts)
## Installation
`pythonguts` is available at [PyPI](https://pypi.org/project/pythonguts/):```bash
pip install pythonguts
```## The idea behind `editpy` tool
`editpy` uses [astor](https://github.com/berkerpeksag/astor) to find replaceable functions and replaces matching functions.To find common function `editpy` checks:
* are they both _functions?_
* do they both have the same name?
* do they both have the same args?
* do they both have the same parent (i.e. classname for example)?## Example
original function/method definition file **dest.py**:
```python
class MyClass:
def my_method(self, i: float, j: int, k: float) -> float:
return 0def foo(i: float) -> float:
return idef bar():
return 0# this function stays unchanged
def unchanged():
return 0
```new function/method definition file **src.py**:
```python
class MyClass:
def my_method(self, i: float, j: int, k: float) -> float:
print('new definition')
return 0def foo(i: float) -> float:
print('new definition')
return idef bar():
print('new definition')
return 0
```
Run:`editpy --src-file=src.py --dest-file=dest.py --oldfile-keep`
`--oldfile-keep` (default) is used to keep the original file (it will be renamed by adding `_OLD_N` suffix). Otherwise use `--oldfile-delete` to delete the original file.
Another option is to run the test (though the test deletes all the generated files so you better take a look in `/tests` dir):
`python -m unittest pythonguts.tests.test_pythonguts`