Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandonwillard/python-custom-refactors
Custom Python project refactors
https://github.com/brandonwillard/python-custom-refactors
Last synced: 26 days ago
JSON representation
Custom Python project refactors
- Host: GitHub
- URL: https://github.com/brandonwillard/python-custom-refactors
- Owner: brandonwillard
- Created: 2020-10-03T20:15:55.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-04T23:16:04.000Z (about 4 years ago)
- Last Synced: 2024-06-11T22:57:58.999Z (5 months ago)
- Language: Python
- Size: 14.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![refactors-tests](https://github.com/brandonwillard/python-custom-refactors/workflows/refactors-tests/badge.svg)
# Python Custom Refactors
Custom refactors written in LibCST.
## Installation
To install from source:
```bash
git clone [email protected]:brandonwillard/python-custom-refactors.git
cd python-custom-refactors
pip install -r requirements.txt
```# Implemented Refactors
## Convert "indirect" module/package references into "direct" references.
For example, consider the package, `pkg`, defined by the following files:
`pkg/__init__.py`:
```python
import pkg.mod1 as foofrom pkg.mod1 import var1
var2 = 0
````pkg/mod1.py`:
```python
var1 = 10
````pkg/mod2.py`:
```python
import pkgfrom pkg import foo, var1, var2
print(pkg.foo)
print(pkg.var1)
print(pkg.var2)
print(var1)
print(foo.var1)
```Refactoring would produce the following new package files:
`pkg/__init__.py`:
```python
var2 = 0
````pkg/mod1.py`:
```python
var1 = 10
````pkg/mod2.py`:
```python
import pkg
import pkg.mod1
import pkg.mod1 as foofrom pkg import var2
from pkg.mod1 import var1print(pkg.mod1)
print(pkg.mod1.var1)
print(pkg.var2)
print(var1)
print(foo.var1)
```