PyRef is a tool that automatically detect mainly method-level refactoring operations in Python projects.
Current supported refactoring operations:
- Rename Method
- Add Parameter
- Remove Parameter
- Change/Rename Parameter
- Extract Method
- Inline Method
- Move Method
- Pull Up Method
- Push Down Method
This tool was orinally developed by PyRef team, but the original repo is abanoned. MTS AI Research team is using PyRef tool in our work, so we decided to share its improved version. Please feel free to use it.
Clone a repository from GitHub using PyRef:
python3 main.py repoClone -u "username" -r "Repo Name"
You can also use git command to clone the repository.
Extract refactorings from a given repository
python3 main.py getrefs -r "[PATH_TO_REPOSITORY]"
You can also use flag -s to skip the commit which takes more than N minutes to extract the refactorings. For example, the following command skips commits which were processed for more than 10 minutes:
python3 main.py getrefs -r "[PATH_TO_REPOSITORY]" -s 10
If you want to look into specific commit, you can use flag -c. If you want to look into specific directory, you can use flag -d.
python3 main.py getrefs -r "[PATH_TO_REPOSITORY]" -c "[CommitHash]" -d "[Directory]"
The detected refactorings will be recorded in the current folder as a json file "[project]_data.json".
Firstly, you need to install Python3.9 version after that you will need to first install the third-party dependencies. You can use the following command in the folder of PyRef:
pip3 install -r requirements.txt
We provide a toy project for you to test PyRef, which can be found at https://github.com/PyRef/DummyRef Please execute the following commands in order:
python3 main.py repoClone -u "PyRef" -r "DummyRef"
python3 main.py getrefs -r "Repos/DummyRef"
The detected refactorings can be found in the file "DummyRef_data.json"
The original tool was part of the following study:
H. Atwi, B. Lin, N. Tsantalis, Y. Kashiwa, Y. Kamei, N. Ubayashi, G. Bavota and M. Lanza, "PyRef: Refactoring Detection in Python Projects," 2021 IEEE 21st International Working Conference on Source Code Analysis and Manipulation (SCAM), 2021, accepted.
The labeled oracle used in the paper can be found in the file "data/dataset.csv".