Package: autorefine
autorefineMechanize the refactoring process to operate on a large scale.The project is aimed to provide a framework for the process of refactoring Python projects
from the very beginning to the very end:autorefine analyze→analyze the projectwith linters and type checkers,autorefine roadmap→create a refactoring roadmap(likehttps://github.com/CERT-Polska/malduck/issues/110, but with more details available as a specialized document),autorefine plan→create a delivery plan(like in the issue above) to split the refactoring process intoa sequence of iterations,autorefine autopilot→apply automatic fixesand commit them in reviewable and git-bisectable chunks with meaningful descriptions,autorefine audit→ typicallyrun testsand other tools that determine whether the project runs safe,autorefine troubleshoot→ using the configuredauditing task,git bisecttofind out what fix went wrong, describe the problem,leave the rest for manual work,autorefine finalize→create a PR(likehttps://github.com/CERT-Polska/malduck/issues/111) to finalize the current iteration of refactoring with a detailed description of the changes and a link to the roadmap, delivery plan and all commits.Created to accomplishhttps://github.com/jaraco/skeleton/issues/98and for personal use to raise awareness of best practices across the Python community globally.Planned toolingThe project is planned to be a wrapper around the following well-tested & recognized tools:MonkeyTypefor automatic type annotations generation,Fixitfor automatic fixes that require static analysis and scope analysis and planning of manual refactoring steps,Rufffor automatic fixes and planning of manual refactoring steps,Static type checking:mypy,pyre,pytype,diff-coverforcoveragereports on fixes,smokeshowfor hosting detailed refactoring roadmaps and delivery plans,pandasfor collecting tasks and creating markdown tables,GitHub CLIfor creating tickets.Refactoring workflowautorefinewill be a CLI tool that will help you refactor a project in a few simple steps:Fork a repository you want to refactor.Create a new branch for refactoring.Runautorefine configureto run a wizard that will help you configureautorefine, configure audits (autorefinewill typically detect doctest, pytest and other tools that determine whether the project runs safe) and refactor the project for a specific choice of linting tools.Runautorefine analyzeto analyze the project with linters and type checkers.autorefinenow knows what needs to be fixed in the current HEAD.Runautorefine roadmapto create a refactoring roadmap. You will have a checklist of all the things that need to be fixed in the project automatically and manually.Runautorefine planto create a delivery plan and set up iterations of the refactoring process. For example, you can start off by a PR that aims to modernize the codebase and does not change the implementation (fixes in the roadmap will be grouped and you will be able to select which ones you want to apply in this iteration), that would be the first iteration, and then apply some implementation-changing autofixes, such as replacingf"'{x}'"withf"{x!r}"—that could be the second iteration. Having a delivery plan will makeautorefinecreate a PR for each iteration, so that you can review the changes and merge them separately.Runautorefine autopilotto apply automatic fixes and commit them in reviewable and git-bisectable chunks with meaningful descriptions.Runautorefine auditto prevent future regressions.Runautorefine troubleshootto repeatedly callautorefine auditwithingit bisectto find out what fix went wrong, and get a detailed description of the problem and suggestions on how to fix it.Manually fix the problems that cannot be fixed automatically. You will find them in the roadmap (autorefine roadmap).Runautorefine finalizeto finalize the current iteration and create a PR with a detailed description of the changes and a link to the roadmap, delivery plan and all commits of the current refactor iteration.Non-MVP ideasautorefine cito create a dedicated CI pipeline (which will, by default, runautorefine analyzeandautorefine auditon every PR) for your Git hosting provider (GitHub, GitLab, Bitbucket, etc.),autorefine template [TEMPLATE_NAME]to configure Quality Assurance and CI/CD tooling (Ruff, tox, towncrier, Sphinx, etc.) by smart copying what is seen a specified repository (e.g.autorefine template jaraco/skeleton+jaraco.developcould be used to copy tox.ini, GitHub Actions etc.)—feature for projects that don't intend to use a skeleton.autorefine breakdownto create separate tickets for each fix in the roadmap in your workflow management tool (GitHub Projects, Jira, ClickUp, Asana, Trello, etc.).Get inspiredhttps://instagram-engineering.com/static-analysis-at-scale-an-instagram-story-8f498ab71a0cInstallationIf you want to……use this tool in your project 💻You might simply install it withpipx:pipxinstallautorefine…contribute toautorefine🚀[!Note]
If you use Windows, it is highly recommended to complete the installation in the way presented below throughWSL2.Fork theautorefine repositoryon GitHub.Install Poetry.Poetry is an amazing tool for managing dependencies & virtual environments, building packages and publishing them.
You might usepipxto install it globally (recommended):pipxinstallpoetryIf you encounter any problems, refer tothe official documentationfor the most up-to-date installation instructions.If you want to use pipx to install dev dependencies as well, install thepoetry appsplugin:pipxinjectpoetrypoetry-appsBe sure to have Python 3.8 installed—if you usepyenv, simply run:pyenvinstall3.8Clone your fork locally and install dependencies.gitclonehttps://github.com/your-username/autorefinepath/to/autorefinecdpath/to/autorefine
poetryenvuse$(cat.python-version)poetryinstallNext up, simply activate the virtual environment and install pre-commit hooks:poetryshell
pre-commitinstall--hook-typepre-commit--hook-typepre-pushFor more information on how to contribute, check outCONTRIBUTING.md.Always happy to accept contributions! ❤️Legal info© Copyright by Bartosz Sławecki (@bswck).This software is licensed under the terms ofGPL-3.0 License.