refactrail 0.3.1a0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. refactrail-0.3.1a0/.github/workflows/ci.yml +51 -0
  2. refactrail-0.3.1a0/CHANGELOG.md +100 -0
  3. refactrail-0.3.1a0/LICENSE +21 -0
  4. refactrail-0.3.1a0/MANIFEST.in +13 -0
  5. refactrail-0.3.1a0/PKG-INFO +233 -0
  6. refactrail-0.3.1a0/README.md +203 -0
  7. refactrail-0.3.1a0/docs/BENCHMARKS.md +97 -0
  8. refactrail-0.3.1a0/docs/DESIGN.md +70 -0
  9. refactrail-0.3.1a0/docs/DUAL_ENGINES.md +205 -0
  10. refactrail-0.3.1a0/docs/EXPANSION_ROADMAP.md +52 -0
  11. refactrail-0.3.1a0/docs/EXPANSION_USAGE.md +102 -0
  12. refactrail-0.3.1a0/docs/INDEPENDENT_ENGINES.md +100 -0
  13. refactrail-0.3.1a0/docs/RELEASE_PREPARATION.md +85 -0
  14. refactrail-0.3.1a0/docs/RULES.md +355 -0
  15. refactrail-0.3.1a0/editor/refactrail/LICENSE +21 -0
  16. refactrail-0.3.1a0/editor/refactrail/README.md +38 -0
  17. refactrail-0.3.1a0/editor/refactrail/extension.js +128 -0
  18. refactrail-0.3.1a0/editor/refactrail/package.json +126 -0
  19. refactrail-0.3.1a0/editor/refactrail/runner.js +89 -0
  20. refactrail-0.3.1a0/editor/refactrail/setup.js +128 -0
  21. refactrail-0.3.1a0/editor/refactrail/test/host.js +66 -0
  22. refactrail-0.3.1a0/editor/refactrail/test/host_workflows.js +183 -0
  23. refactrail-0.3.1a0/editor/refactrail/test/runner.test.js +86 -0
  24. refactrail-0.3.1a0/editor/refactrail/test/setup.test.js +128 -0
  25. refactrail-0.3.1a0/examples/correctness_findings.py +9 -0
  26. refactrail-0.3.1a0/examples/general_demo.py +6 -0
  27. refactrail-0.3.1a0/examples/project_demo/invoice.py +8 -0
  28. refactrail-0.3.1a0/examples/project_demo/main.py +6 -0
  29. refactrail-0.3.1a0/pyproject.toml +48 -0
  30. refactrail-0.3.1a0/scripts/compare_engines.py +106 -0
  31. refactrail-0.3.1a0/scripts/compare_lint.py +48 -0
  32. refactrail-0.3.1a0/scripts/compile_parity.py +167 -0
  33. refactrail-0.3.1a0/scripts/dump_tokens.py +62 -0
  34. refactrail-0.3.1a0/scripts/format_parity.py +118 -0
  35. refactrail-0.3.1a0/scripts/gen_ast.py +390 -0
  36. refactrail-0.3.1a0/scripts/gen_identifier_tables.py +71 -0
  37. refactrail-0.3.1a0/scripts/gen_lexical_tables.py +52 -0
  38. refactrail-0.3.1a0/scripts/gen_nfkc_tables.py +103 -0
  39. refactrail-0.3.1a0/scripts/gen_parser_cases.py +118 -0
  40. refactrail-0.3.1a0/scripts/gen_third_party_licenses.py +101 -0
  41. refactrail-0.3.1a0/scripts/gen_unicode_tables.py +111 -0
  42. refactrail-0.3.1a0/scripts/lexer_fuzz.py +104 -0
  43. refactrail-0.3.1a0/scripts/lexer_parity.py +112 -0
  44. refactrail-0.3.1a0/scripts/nfkc_parity.py +97 -0
  45. refactrail-0.3.1a0/scripts/package_editor.py +79 -0
  46. refactrail-0.3.1a0/scripts/parser_fuzz.py +125 -0
  47. refactrail-0.3.1a0/scripts/parser_parity.py +139 -0
  48. refactrail-0.3.1a0/scripts/release_check.py +199 -0
  49. refactrail-0.3.1a0/scripts/scope_parity.py +103 -0
  50. refactrail-0.3.1a0/scripts/symtable_parity.py +169 -0
  51. refactrail-0.3.1a0/scripts/verify.py +42 -0
  52. refactrail-0.3.1a0/setup.cfg +4 -0
  53. refactrail-0.3.1a0/src/refactrail/__init__.py +32 -0
  54. refactrail-0.3.1a0/src/refactrail/__main__.py +6 -0
  55. refactrail-0.3.1a0/src/refactrail/_version.py +3 -0
  56. refactrail-0.3.1a0/src/refactrail/analysis_cli.py +82 -0
  57. refactrail-0.3.1a0/src/refactrail/cli.py +227 -0
  58. refactrail-0.3.1a0/src/refactrail/config.py +136 -0
  59. refactrail-0.3.1a0/src/refactrail/correctness.py +94 -0
  60. refactrail-0.3.1a0/src/refactrail/correctness_batch.py +145 -0
  61. refactrail-0.3.1a0/src/refactrail/correctness_checks.py +228 -0
  62. refactrail-0.3.1a0/src/refactrail/data/generic_names.txt +19 -0
  63. refactrail-0.3.1a0/src/refactrail/data/protocol_hooks.txt +14 -0
  64. refactrail-0.3.1a0/src/refactrail/data/verbs.txt +484 -0
  65. refactrail-0.3.1a0/src/refactrail/discovery.py +62 -0
  66. refactrail-0.3.1a0/src/refactrail/engine.py +389 -0
  67. refactrail-0.3.1a0/src/refactrail/facts.py +321 -0
  68. refactrail-0.3.1a0/src/refactrail/fixes.py +196 -0
  69. refactrail-0.3.1a0/src/refactrail/fixing.py +190 -0
  70. refactrail-0.3.1a0/src/refactrail/format_operators.py +97 -0
  71. refactrail-0.3.1a0/src/refactrail/format_statements.py +662 -0
  72. refactrail-0.3.1a0/src/refactrail/format_tokens.py +144 -0
  73. refactrail-0.3.1a0/src/refactrail/format_wrapping.py +392 -0
  74. refactrail-0.3.1a0/src/refactrail/formatting.py +304 -0
  75. refactrail-0.3.1a0/src/refactrail/general_cli.py +193 -0
  76. refactrail-0.3.1a0/src/refactrail/json_spans.py +97 -0
  77. refactrail-0.3.1a0/src/refactrail/lexical.py +346 -0
  78. refactrail-0.3.1a0/src/refactrail/lexical_scopes.py +263 -0
  79. refactrail-0.3.1a0/src/refactrail/models.py +145 -0
  80. refactrail-0.3.1a0/src/refactrail/notebooks.py +188 -0
  81. refactrail-0.3.1a0/src/refactrail/project_index.py +268 -0
  82. refactrail-0.3.1a0/src/refactrail/py.typed +0 -0
  83. refactrail-0.3.1a0/src/refactrail/rename.py +269 -0
  84. refactrail-0.3.1a0/src/refactrail/report.py +98 -0
  85. refactrail-0.3.1a0/src/refactrail/rules/__init__.py +51 -0
  86. refactrail-0.3.1a0/src/refactrail/rules/annotations.py +61 -0
  87. refactrail-0.3.1a0/src/refactrail/rules/context.py +160 -0
  88. refactrail-0.3.1a0/src/refactrail/rules/docs.py +287 -0
  89. refactrail-0.3.1a0/src/refactrail/rules/layout.py +216 -0
  90. refactrail-0.3.1a0/src/refactrail/rules/naming.py +284 -0
  91. refactrail-0.3.1a0/src/refactrail/rules/signatures.py +103 -0
  92. refactrail-0.3.1a0/src/refactrail/rules/size.py +55 -0
  93. refactrail-0.3.1a0/src/refactrail/sarif.py +61 -0
  94. refactrail-0.3.1a0/src/refactrail/scopes.py +430 -0
  95. refactrail-0.3.1a0/src/refactrail/source.py +176 -0
  96. refactrail-0.3.1a0/src/refactrail/validation.py +26 -0
  97. refactrail-0.3.1a0/src/refactrail/wordlists.py +20 -0
  98. refactrail-0.3.1a0/src/refactrail.egg-info/PKG-INFO +233 -0
  99. refactrail-0.3.1a0/src/refactrail.egg-info/SOURCES.txt +111 -0
  100. refactrail-0.3.1a0/src/refactrail.egg-info/dependency_links.txt +1 -0
  101. refactrail-0.3.1a0/src/refactrail.egg-info/entry_points.txt +2 -0
  102. refactrail-0.3.1a0/src/refactrail.egg-info/requires.txt +9 -0
  103. refactrail-0.3.1a0/src/refactrail.egg-info/top_level.txt +1 -0
  104. refactrail-0.3.1a0/tests/test_engine_parity.py +205 -0
  105. refactrail-0.3.1a0/tests/test_fixes.py +151 -0
  106. refactrail-0.3.1a0/tests/test_format_expansion.py +190 -0
  107. refactrail-0.3.1a0/tests/test_formatting.py +138 -0
  108. refactrail-0.3.1a0/tests/test_general_cli.py +96 -0
  109. refactrail-0.3.1a0/tests/test_lexical.py +121 -0
  110. refactrail-0.3.1a0/tests/test_project_analysis.py +180 -0
  111. refactrail-0.3.1a0/tests/test_release_safety.py +82 -0
  112. refactrail-0.3.1a0/tests/test_report.py +61 -0
  113. refactrail-0.3.1a0/tests/test_rules.py +330 -0
@@ -0,0 +1,51 @@
1
+ name: Local-contract checks
2
+ on: [push, pull_request, workflow_dispatch]
3
+ permissions:
4
+ contents: read
5
+ jobs:
6
+ python:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os: [ubuntu-latest, windows-latest, macos-latest]
11
+ python: ['3.12', '3.13', '3.14']
12
+ runs-on: ${{ matrix.os }}
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-python@v5
16
+ with:
17
+ python-version: ${{ matrix.python }}
18
+ - run: python -m pip install --upgrade pip
19
+ # Test against FuncLoom's current main branch from its public
20
+ # repository (a FUNCLOOM_READ_TOKEN secret is used only if one exists).
21
+ - uses: actions/checkout@v4
22
+ with:
23
+ repository: SAMtheROCKET/funcloom
24
+ path: funcloom-src
25
+ token: ${{ secrets.FUNCLOOM_READ_TOKEN || github.token }}
26
+ - run: python -m pip install ./funcloom-src
27
+ # refactrail-core is a dependency; before publication the local
28
+ # pure-Python fallback wheel satisfies it (Python engine).
29
+ - run: python -m pip install ./rust/fallback
30
+ - run: python -m pip install -e ".[release]"
31
+ - run: python -m unittest discover -s tests
32
+ - run: python -m build
33
+ - run: python -m twine check --strict dist/*
34
+ editor:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+ - uses: actions/setup-node@v4
39
+ with:
40
+ node-version: '22'
41
+ - run: node --test editor/refactrail/test/runner.test.js editor/refactrail/test/setup.test.js
42
+ rust:
43
+ strategy:
44
+ fail-fast: false
45
+ matrix:
46
+ os: [ubuntu-latest, windows-latest, macos-latest]
47
+ runs-on: ${{ matrix.os }}
48
+ steps:
49
+ - uses: actions/checkout@v4
50
+ - run: cargo test --locked -p refactrail-lexer -p refactrail-parser -p refactrail-engine -p refactrail-cli
51
+ working-directory: rust
@@ -0,0 +1,100 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - Easy installation: `pip install refactrail` now also installs the Rust
6
+ engine (refactrail-core). Native wheels cover Windows x86_64, macOS arm64
7
+ and x86_64, and Linux x86_64 and ARM64 (glibc and musl); every other
8
+ system gets a pure-Python fallback wheel, so installation never needs
9
+ Rust. refactrail-core no longer depends back on refactrail.
10
+ - `refactrail` without arguments shows a short quick start.
11
+ - VS Code: the extension uses the interpreter selected in the Python
12
+ extension when `refactrail.pythonPath` is empty (the new default), and
13
+ offers one-click Install/Update when RefacTrail is missing or outdated.
14
+ - pre-commit hooks: refactrail-lint, refactrail-format,
15
+ refactrail-format-check and refactrail-check.
16
+ - Identifier parity with CPython in the Rust engine: NFKC normalization
17
+ of non-ASCII names (`file` is `file`), and CPython's rejection of
18
+ characters that cannot appear in names (`a = €`, `x² = 1`,
19
+ U+00A0 inside a name) with its exact messages and columns. Previously
20
+ such files were accepted or reported differently.
21
+ - `refactrail lint` and `refactrail format` take `--engine
22
+ auto|python|rust`; the Rust engine lints and formats through
23
+ refactrail-core with byte-identical output (31/31 recorded runs).
24
+ - Native `refactrail-native lint` refuses notebooks like the Python CLI.
25
+ - Rust third-party license bundle regenerated from the locked dependency
26
+ graph (`scripts/gen_third_party_licenses.py`); it no longer lists the
27
+ removed Ruff crates.
28
+ - Package metadata: RefacTrail is described as the Python refactorizer,
29
+ with keywords and family links to FuncLoom.
30
+
31
+ ## 0.3.1a0 - statement layout and rule fixes, local candidate, 2026-10-02
32
+
33
+ - Formatter: new whole-statement layout engine. Over-long statements are
34
+ joined and split again inside existing brackets (right-hand split,
35
+ left-hand for definition headers, fewest lines), with delimiter
36
+ priorities for comprehensions, commas, conditionals, boolean,
37
+ string-concatenation, comparison and arithmetic splits. Long
38
+ `from ... import` lines gain parentheses; continuation lines are
39
+ re-packed. `--bracket-style own-line|hug` (editor: `refactrail.bracketStyle`).
40
+ Spacing re-runs after layout so one run is idempotent (found on
41
+ `http/server.py`). AST and literal-token validation still guard writes.
42
+ - Rules (contract 3, both engines): module-level type aliases (`type X =`,
43
+ `X: TypeAlias =`, PascalCase `X = tuple[...]`) are no longer reported as
44
+ misnamed variables, as code before constants, or as import-time code.
45
+ 14 verbs added to the shared verb list.
46
+ - RC2 scope evidence: a name such as `locals` that is only assigned (for
47
+ example a dataclass field) no longer disables RC201/RC202 for the file.
48
+ - Caches key on a fingerprint of RefacTrail's own code and word lists, not
49
+ only its version, so engine changes never reuse stale results.
50
+ - refactrail-core is versioned with RefacTrail (0.3.1a0, contract 3); the
51
+ previous pins required refactrail 0.1.1a0 and could not be installed.
52
+ - Editor: automated extension-host workflow test covering every command.
53
+
54
+ ## 0.3.0a0 - resumed independent engines, 2026-10-01
55
+
56
+ - Add compiler-backed partial scope evidence, RC201 unresolved-name checks and
57
+ RC202 imports without lexical use; retain explicit unknowns and type comments.
58
+ - Add independent bracket-group wrapping and byte-local Python notebook source
59
+ edits; preserve outputs, metadata, directives, literals and original endings.
60
+ - Discover Python stubs and optionally notebook containers.
61
+ - Add project symbol/import inventories and possible transitive impact queries,
62
+ including cycles, stubs, re-exports and explicitly changed deleted modules.
63
+ - Add bounded local-variable rename review proposals with original source hashes,
64
+ collision/reflection/scope refusals and structural validation; no rename apply.
65
+ - Add source/configuration/version-aware RC caching and parallel snapshot checks.
66
+ - Add editor scope, project index and rename commands and notebook formatting.
67
+ - Preserve the native RT contract and one-way FuncLoom dependency. Publication
68
+ remains held; this does not establish universal feature or speed superiority.
69
+
70
+ ## 0.2.0a0 - independent engine increment, 2026-10-01
71
+
72
+ - Add `lint`: seven independent correctness checks, separate from the RT
73
+ style profiles. Diagnose mutable defaults, duplicate literal keys,
74
+ identity/literal comparisons, bare except, directly unreachable code,
75
+ tuple assertions and control-flow exits from finally.
76
+ - Add `format`: independent bounded whitespace proposals, check/diff modes
77
+ and explicit hash-checked atomic writes. Preserve literal/comment tokens,
78
+ directives, BOM and original line endings; validate compilation and ASTs.
79
+ - Add SARIF 2.1.0 reporting for `lint` and `check`; keep statistics on stderr
80
+ so JSON/SARIF stdout remains parseable.
81
+ - Add public correctness/formatting APIs, examples and editor commands.
82
+ - Keep the existing RT native contract unchanged. New engines use CPython
83
+ AST/tokenize and do not invoke Ruff, Black or an LLM. Native RT parsing
84
+ still uses the previously documented Ruff parser crates.
85
+ - Document the larger independent-engine roadmap and current limitations.
86
+ This is an experimental increment, not complete formatter parity or a
87
+ demonstrated replacement for every existing refactoring tool.
88
+
89
+ ## 0.1.1a0 - local candidate, 2026-10-01
90
+
91
+ - Validate compilation in both engines without executing source.
92
+ - Honor suppression comments only outside strings; retain parse errors.
93
+ - Add strict return and parameter suffix checks (RT206, RT207).
94
+ - Avoid assuming rich comparisons return bool.
95
+ - Validate configurations and ignore damaged caches.
96
+ - Reject linked sources; check source hashes before atomic fix writes.
97
+ - Skip return-annotation edits on decorated functions.
98
+ - Add a native rule-contract compatibility check and interpreter cache key.
99
+ - Add a local VS Code extension, CI configuration and release checks.
100
+ - Keep FuncLoom as the one-way rewrite dependency; publish nothing.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sambit Supriya Dash
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ include README.md LICENSE pyproject.toml CHANGELOG.md
2
+ recursive-include docs *.md
3
+ recursive-include tests *.py
4
+ recursive-include examples *.py
5
+ recursive-include scripts *.py
6
+ recursive-include editor *.js *.json *.md LICENSE
7
+ include .github/workflows/ci.yml
8
+ prune reports
9
+ prune dist
10
+ prune .venv
11
+ prune rust
12
+ global-exclude *.py[cod]
13
+ exclude AGENTS.md
@@ -0,0 +1,233 @@
1
+ Metadata-Version: 2.4
2
+ Name: refactrail
3
+ Version: 0.3.1a0
4
+ Summary: The Python refactorizer: linter, formatter and verified refactoring with independent pure-Python and Rust engines
5
+ Author: Sambit Supriya Dash
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/SAMtheROCKET/refactrail
8
+ Project-URL: Repository, https://github.com/SAMtheROCKET/refactrail
9
+ Project-URL: Issues, https://github.com/SAMtheROCKET/refactrail/issues
10
+ Keywords: python,refactorizer,linter,formatter,refactoring,static-analysis,code-quality,python-linter,code-formatter,sarif,rust,developer-tools
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Software Development :: Quality Assurance
19
+ Requires-Python: >=3.12
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: funcloom<0.11,>=0.10.2a0
23
+ Requires-Dist: refactrail-core==0.3.1a0
24
+ Provides-Extra: fast
25
+ Provides-Extra: release
26
+ Requires-Dist: build<2,>=1.2; extra == "release"
27
+ Requires-Dist: setuptools>=77; extra == "release"
28
+ Requires-Dist: twine<7,>=6; extra == "release"
29
+ Dynamic: license-file
30
+
31
+ # RefacTrail
32
+
33
+ **The Python refactorizer.** A linter, formatter and verified refactoring
34
+ tool with two independent engines, pure Python and Rust, built on its own
35
+ parser. Run correctness checks and bounded formatting, or check structure,
36
+ naming, types and documentation against a chosen profile.
37
+
38
+ Part of a family of standalone Python tools: [FuncLoom](https://github.com/SAMtheROCKET/funcloom) (functionizer), [RefacTrail](https://github.com/SAMtheROCKET/refactrail) (refactorizer) and RepoContour (architect, planned). Each installs and works on its own.
39
+
40
+ **0.3.1a0 is an unpublished experimental alpha.** Python 3.12 or newer is
41
+ required. RefacTrail has its own package, CLI and VS Code extension. It
42
+ installs FuncLoom automatically for its rewrite API; FuncLoom has no
43
+ dependency on RefacTrail. No LLM, account or network is needed at runtime.
44
+
45
+ ## Quick start
46
+
47
+ ```bash
48
+ pip install refactrail
49
+ ```
50
+
51
+ That one command also installs FuncLoom and the fast Rust engine (a native
52
+ wheel for Windows, macOS and Linux; on other systems a small fallback is
53
+ installed and the Python engine gives the same results, so nothing ever
54
+ needs compiling). Python 3.12 or newer is required. Until the first PyPI
55
+ release, install from GitHub instead:
56
+ `pip install git+https://github.com/SAMtheROCKET/refactrail.git`.
57
+
58
+ Then, in any project folder:
59
+
60
+ ```bash
61
+ refactrail # the most useful commands
62
+ refactrail lint # find likely bugs
63
+ refactrail format --diff # preview formatting; --write applies it
64
+ refactrail check # structure, naming, type hints, docstrings
65
+ refactrail fix --diff # preview safe fixes; drop --diff to apply
66
+ ```
67
+
68
+ Paths default to the current folder; pass files or folders to narrow it.
69
+ Exit codes are 0 (clean), 1 (findings) and 2 (error), ready for CI. If your
70
+ system blocks the `refactrail` command, use `python -m refactrail`.
71
+
72
+ **In VS Code**, install the RefacTrail extension and run *RefacTrail: ...*
73
+ from the Command Palette. It uses the Python interpreter selected in VS Code
74
+ and offers to install RefacTrail there with one click.
75
+
76
+ **On every commit**, add the hooks to `.pre-commit-config.yaml`:
77
+
78
+ ```yaml
79
+ repos:
80
+ - repo: https://github.com/SAMtheROCKET/refactrail
81
+ rev: v0.3.1a0
82
+ hooks:
83
+ - id: refactrail-lint
84
+ - id: refactrail-format
85
+ ```
86
+
87
+ `refactrail-format-check` (fails instead of rewriting) and
88
+ `refactrail-check` are also available.
89
+
90
+ ### From source (development)
91
+
92
+ Install FuncLoom from its source folder and the local engine fallback
93
+ first, then RefacTrail:
94
+
95
+ ```bash
96
+ python -m pip install -e ../funcloom ./rust/fallback
97
+ python -m pip install -e .
98
+ ```
99
+
100
+ Nothing is uploaded by these local tools.
101
+
102
+ ## General correctness and independent formatting
103
+
104
+ ```powershell
105
+ python -m refactrail lint src
106
+ python -m refactrail lint src --output-format sarif
107
+ python -m refactrail format examples/general_demo.py --diff
108
+ python -m refactrail format examples/general_demo.py --check
109
+ python -m refactrail format examples/general_demo.py --write
110
+ ```
111
+
112
+ `lint` provides nine RC correctness checks without imposing personal naming
113
+ rules. `format` uses an independent CPython AST/tokenize implementation; its
114
+ default is a read-only preview. It makes bounded whitespace edits and retains
115
+ literal/comment spelling, directives, BOM and original line endings.
116
+ Use `--line-length 79` for bracketed comma-group wrapping. Explicit Python
117
+ notebooks and discovered stubs are supported; `--notebooks` includes notebooks
118
+ in folder formatting. This is a documented style subset, not full Black parity.
119
+
120
+ ```powershell
121
+ python -m refactrail format examples/analysis.ipynb --line-length 79 --diff
122
+ python -m refactrail scope examples/project_demo/invoice.py
123
+ python -m refactrail index examples/project_demo --changed invoice.py
124
+ python -m refactrail rename examples/project_demo/invoice.py --function calculate_total --old amount --new base_amount_int
125
+ ```
126
+
127
+ `scope` exposes partial compiler binding evidence. `index` inventories symbols
128
+ and possible import impact under an explicit import root. `rename` produces a
129
+ read-only, hash-linked proposal for a bounded local-variable subset; parameters,
130
+ public APIs, nested scopes and dynamic namespaces are refused. See
131
+ [the workflow and examples](docs/EXPANSION_USAGE.md).
132
+
133
+ `lint --jobs 4` enables worker processes on larger batches. Lint caching hashes
134
+ source bytes, rule selection, tool/interpreter version and path-sensitive policy;
135
+ use `--no-cache` to disable it. No cache is used to authorize source changes.
136
+
137
+ See [the independent engines](docs/INDEPENDENT_ENGINES.md) for contracts,
138
+ APIs and limitations, and [the expansion roadmap](docs/EXPANSION_ROADMAP.md)
139
+ for broader formatter, data-flow and repository-refactoring work. These
140
+ engines do not invoke or contain Ruff or Black. The FuncLoom
141
+ structural-rewrite dependency remains as documented below.
142
+
143
+ ## Checking and fixing
144
+
145
+ `check` reports line, function and main-block sizes; docstrings and their
146
+ sections; missing annotations; naming conventions and verb prefixes;
147
+ constants and their location; and top-level script execution. The strict
148
+ profile adds generic-name and dtype-suffix checks. Defaults are 79 columns,
149
+ 40 preferred / 50 maximum function lines, and 100 main-block lines.
150
+
151
+ ```powershell
152
+ python -m refactrail check src --profile strict --statistics
153
+ python -m refactrail check src --output-format json
154
+ python -m refactrail rules
155
+ python -m refactrail fix src --diff
156
+ python -m refactrail fix src
157
+ ```
158
+
159
+ `fix --diff` previews edits without writing. `fix` edits files in place:
160
+ selected fixes add eligible `-> None` annotations, create function docstring
161
+ skeletons, wrap supported lines and split supported long functions. It
162
+ checks compilation, rejects linked files and changed source, and replaces
163
+ each file atomically. Review diffs and run your project's tests. A failed
164
+ file does not roll back other files in a multi-file run.
165
+
166
+ These are structural checks, not proof of unchanged behavior. Annotations
167
+ and docstrings can affect reflection. There is no automatic domain naming,
168
+ public-API renaming, inferred annotation insertion beyond the bounded None
169
+ case, or arbitrary repository restructuring. Missing meanings need user
170
+ context. Unsupported functions can remain long. Use FuncLoom's explicit
171
+ `modularize` command to create a separate package draft.
172
+
173
+ Exit codes: check returns 0 with no findings, 1 for findings, 2 for usage
174
+ errors. `--exit-zero` explicitly overrides finding failures. Diff returns 1
175
+ when edits are proposed or files are skipped; fix returns 1 for skipped
176
+ files. Syntax, encoding and internal errors cannot be hidden by selection
177
+ or ignore lists. Suppression markers apply only inside real comment tokens.
178
+
179
+ ## Configuration
180
+
181
+ ```toml
182
+ [tool.refactrail]
183
+ profile = "strict"
184
+ line-length = 79
185
+ function-preferred-lines = 40
186
+ function-max-lines = 50
187
+ main-max-lines = 100
188
+ select = ["RT"]
189
+ ignore = []
190
+ ```
191
+
192
+ Widths must be 40-200; the preferred function size cannot exceed the maximum.
193
+ See [the rule contract](docs/RULES.md) and [design](docs/DESIGN.md).
194
+
195
+ ## The Rust engine
196
+
197
+ `--engine auto` selects a compatible `refactrail-core` when installed and
198
+ otherwise uses Python. `--engine python` selects the reference implementation.
199
+ The native core is a separate PyO3/Rayon distribution built on
200
+ RefacTrail's own Rust lexer, parser, compile checks and symbol table; it
201
+ contains no Ruff code. `check`, `lint` and `format` accept `--engine`, and
202
+ the standalone `refactrail-native` binary runs `check`, `lint`, `scope`,
203
+ `format` and `index` without Python. Outputs are byte-identical to the
204
+ Python engine on the recorded corpora and fuzzed inputs, with CPython as the
205
+ oracle; see [the dual-engine record](docs/DUAL_ENGINES.md). Parity evidence
206
+ is not a guarantee for every Python program.
207
+
208
+ Native wheels (CPython 3.12+ ABI3) are built and tested in CI for Linux
209
+ x86_64 (manylinux2014), Windows x86_64 and macOS arm64; other platforms use
210
+ the Python engine. Install a local wheel with
211
+ `pip install --no-index --no-deps WHEEL`. See
212
+ [benchmark evidence](docs/BENCHMARKS.md) for measured timings and their
213
+ limits.
214
+
215
+ ## Editor and release preparation
216
+
217
+ [The VS Code extension](editor/refactrail/README.md) provides explicit check,
218
+ diff-preview and fix commands. Install its local VSIX, select the Python
219
+ environment containing these packages, and use a trusted workspace.
220
+
221
+ ```powershell
222
+ python scripts/verify.py
223
+ python scripts/release_check.py --output dist/0.3.1a0 --dependency-wheel path/to/funcloom-0.10.3a0-py3-none-any.whl
224
+ ```
225
+
226
+ The release script builds and checks a wheel and source archive, installs
227
+ both in fresh environments, tests installed code and checks uninstallation.
228
+ CI runs the tests on Windows, Linux and macOS with Python 3.12-3.14, and
229
+ the Release check workflow verifies the identical built files on all three
230
+ systems. [Release preparation](docs/RELEASE_PREPARATION.md) lists the
231
+ remaining launch work. No public release has been made.
232
+
233
+ [MIT](LICENSE), copyright 2026 Sambit Supriya Dash.
@@ -0,0 +1,203 @@
1
+ # RefacTrail
2
+
3
+ **The Python refactorizer.** A linter, formatter and verified refactoring
4
+ tool with two independent engines, pure Python and Rust, built on its own
5
+ parser. Run correctness checks and bounded formatting, or check structure,
6
+ naming, types and documentation against a chosen profile.
7
+
8
+ Part of a family of standalone Python tools: [FuncLoom](https://github.com/SAMtheROCKET/funcloom) (functionizer), [RefacTrail](https://github.com/SAMtheROCKET/refactrail) (refactorizer) and RepoContour (architect, planned). Each installs and works on its own.
9
+
10
+ **0.3.1a0 is an unpublished experimental alpha.** Python 3.12 or newer is
11
+ required. RefacTrail has its own package, CLI and VS Code extension. It
12
+ installs FuncLoom automatically for its rewrite API; FuncLoom has no
13
+ dependency on RefacTrail. No LLM, account or network is needed at runtime.
14
+
15
+ ## Quick start
16
+
17
+ ```bash
18
+ pip install refactrail
19
+ ```
20
+
21
+ That one command also installs FuncLoom and the fast Rust engine (a native
22
+ wheel for Windows, macOS and Linux; on other systems a small fallback is
23
+ installed and the Python engine gives the same results, so nothing ever
24
+ needs compiling). Python 3.12 or newer is required. Until the first PyPI
25
+ release, install from GitHub instead:
26
+ `pip install git+https://github.com/SAMtheROCKET/refactrail.git`.
27
+
28
+ Then, in any project folder:
29
+
30
+ ```bash
31
+ refactrail # the most useful commands
32
+ refactrail lint # find likely bugs
33
+ refactrail format --diff # preview formatting; --write applies it
34
+ refactrail check # structure, naming, type hints, docstrings
35
+ refactrail fix --diff # preview safe fixes; drop --diff to apply
36
+ ```
37
+
38
+ Paths default to the current folder; pass files or folders to narrow it.
39
+ Exit codes are 0 (clean), 1 (findings) and 2 (error), ready for CI. If your
40
+ system blocks the `refactrail` command, use `python -m refactrail`.
41
+
42
+ **In VS Code**, install the RefacTrail extension and run *RefacTrail: ...*
43
+ from the Command Palette. It uses the Python interpreter selected in VS Code
44
+ and offers to install RefacTrail there with one click.
45
+
46
+ **On every commit**, add the hooks to `.pre-commit-config.yaml`:
47
+
48
+ ```yaml
49
+ repos:
50
+ - repo: https://github.com/SAMtheROCKET/refactrail
51
+ rev: v0.3.1a0
52
+ hooks:
53
+ - id: refactrail-lint
54
+ - id: refactrail-format
55
+ ```
56
+
57
+ `refactrail-format-check` (fails instead of rewriting) and
58
+ `refactrail-check` are also available.
59
+
60
+ ### From source (development)
61
+
62
+ Install FuncLoom from its source folder and the local engine fallback
63
+ first, then RefacTrail:
64
+
65
+ ```bash
66
+ python -m pip install -e ../funcloom ./rust/fallback
67
+ python -m pip install -e .
68
+ ```
69
+
70
+ Nothing is uploaded by these local tools.
71
+
72
+ ## General correctness and independent formatting
73
+
74
+ ```powershell
75
+ python -m refactrail lint src
76
+ python -m refactrail lint src --output-format sarif
77
+ python -m refactrail format examples/general_demo.py --diff
78
+ python -m refactrail format examples/general_demo.py --check
79
+ python -m refactrail format examples/general_demo.py --write
80
+ ```
81
+
82
+ `lint` provides nine RC correctness checks without imposing personal naming
83
+ rules. `format` uses an independent CPython AST/tokenize implementation; its
84
+ default is a read-only preview. It makes bounded whitespace edits and retains
85
+ literal/comment spelling, directives, BOM and original line endings.
86
+ Use `--line-length 79` for bracketed comma-group wrapping. Explicit Python
87
+ notebooks and discovered stubs are supported; `--notebooks` includes notebooks
88
+ in folder formatting. This is a documented style subset, not full Black parity.
89
+
90
+ ```powershell
91
+ python -m refactrail format examples/analysis.ipynb --line-length 79 --diff
92
+ python -m refactrail scope examples/project_demo/invoice.py
93
+ python -m refactrail index examples/project_demo --changed invoice.py
94
+ python -m refactrail rename examples/project_demo/invoice.py --function calculate_total --old amount --new base_amount_int
95
+ ```
96
+
97
+ `scope` exposes partial compiler binding evidence. `index` inventories symbols
98
+ and possible import impact under an explicit import root. `rename` produces a
99
+ read-only, hash-linked proposal for a bounded local-variable subset; parameters,
100
+ public APIs, nested scopes and dynamic namespaces are refused. See
101
+ [the workflow and examples](docs/EXPANSION_USAGE.md).
102
+
103
+ `lint --jobs 4` enables worker processes on larger batches. Lint caching hashes
104
+ source bytes, rule selection, tool/interpreter version and path-sensitive policy;
105
+ use `--no-cache` to disable it. No cache is used to authorize source changes.
106
+
107
+ See [the independent engines](docs/INDEPENDENT_ENGINES.md) for contracts,
108
+ APIs and limitations, and [the expansion roadmap](docs/EXPANSION_ROADMAP.md)
109
+ for broader formatter, data-flow and repository-refactoring work. These
110
+ engines do not invoke or contain Ruff or Black. The FuncLoom
111
+ structural-rewrite dependency remains as documented below.
112
+
113
+ ## Checking and fixing
114
+
115
+ `check` reports line, function and main-block sizes; docstrings and their
116
+ sections; missing annotations; naming conventions and verb prefixes;
117
+ constants and their location; and top-level script execution. The strict
118
+ profile adds generic-name and dtype-suffix checks. Defaults are 79 columns,
119
+ 40 preferred / 50 maximum function lines, and 100 main-block lines.
120
+
121
+ ```powershell
122
+ python -m refactrail check src --profile strict --statistics
123
+ python -m refactrail check src --output-format json
124
+ python -m refactrail rules
125
+ python -m refactrail fix src --diff
126
+ python -m refactrail fix src
127
+ ```
128
+
129
+ `fix --diff` previews edits without writing. `fix` edits files in place:
130
+ selected fixes add eligible `-> None` annotations, create function docstring
131
+ skeletons, wrap supported lines and split supported long functions. It
132
+ checks compilation, rejects linked files and changed source, and replaces
133
+ each file atomically. Review diffs and run your project's tests. A failed
134
+ file does not roll back other files in a multi-file run.
135
+
136
+ These are structural checks, not proof of unchanged behavior. Annotations
137
+ and docstrings can affect reflection. There is no automatic domain naming,
138
+ public-API renaming, inferred annotation insertion beyond the bounded None
139
+ case, or arbitrary repository restructuring. Missing meanings need user
140
+ context. Unsupported functions can remain long. Use FuncLoom's explicit
141
+ `modularize` command to create a separate package draft.
142
+
143
+ Exit codes: check returns 0 with no findings, 1 for findings, 2 for usage
144
+ errors. `--exit-zero` explicitly overrides finding failures. Diff returns 1
145
+ when edits are proposed or files are skipped; fix returns 1 for skipped
146
+ files. Syntax, encoding and internal errors cannot be hidden by selection
147
+ or ignore lists. Suppression markers apply only inside real comment tokens.
148
+
149
+ ## Configuration
150
+
151
+ ```toml
152
+ [tool.refactrail]
153
+ profile = "strict"
154
+ line-length = 79
155
+ function-preferred-lines = 40
156
+ function-max-lines = 50
157
+ main-max-lines = 100
158
+ select = ["RT"]
159
+ ignore = []
160
+ ```
161
+
162
+ Widths must be 40-200; the preferred function size cannot exceed the maximum.
163
+ See [the rule contract](docs/RULES.md) and [design](docs/DESIGN.md).
164
+
165
+ ## The Rust engine
166
+
167
+ `--engine auto` selects a compatible `refactrail-core` when installed and
168
+ otherwise uses Python. `--engine python` selects the reference implementation.
169
+ The native core is a separate PyO3/Rayon distribution built on
170
+ RefacTrail's own Rust lexer, parser, compile checks and symbol table; it
171
+ contains no Ruff code. `check`, `lint` and `format` accept `--engine`, and
172
+ the standalone `refactrail-native` binary runs `check`, `lint`, `scope`,
173
+ `format` and `index` without Python. Outputs are byte-identical to the
174
+ Python engine on the recorded corpora and fuzzed inputs, with CPython as the
175
+ oracle; see [the dual-engine record](docs/DUAL_ENGINES.md). Parity evidence
176
+ is not a guarantee for every Python program.
177
+
178
+ Native wheels (CPython 3.12+ ABI3) are built and tested in CI for Linux
179
+ x86_64 (manylinux2014), Windows x86_64 and macOS arm64; other platforms use
180
+ the Python engine. Install a local wheel with
181
+ `pip install --no-index --no-deps WHEEL`. See
182
+ [benchmark evidence](docs/BENCHMARKS.md) for measured timings and their
183
+ limits.
184
+
185
+ ## Editor and release preparation
186
+
187
+ [The VS Code extension](editor/refactrail/README.md) provides explicit check,
188
+ diff-preview and fix commands. Install its local VSIX, select the Python
189
+ environment containing these packages, and use a trusted workspace.
190
+
191
+ ```powershell
192
+ python scripts/verify.py
193
+ python scripts/release_check.py --output dist/0.3.1a0 --dependency-wheel path/to/funcloom-0.10.3a0-py3-none-any.whl
194
+ ```
195
+
196
+ The release script builds and checks a wheel and source archive, installs
197
+ both in fresh environments, tests installed code and checks uninstallation.
198
+ CI runs the tests on Windows, Linux and macOS with Python 3.12-3.14, and
199
+ the Release check workflow verifies the identical built files on all three
200
+ systems. [Release preparation](docs/RELEASE_PREPARATION.md) lists the
201
+ remaining launch work. No public release has been made.
202
+
203
+ [MIT](LICENSE), copyright 2026 Sambit Supriya Dash.