refactor-utils 2.0.0__tar.gz → 4.0.1__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 (44) hide show
  1. refactor_utils-4.0.1/LICENSE +21 -0
  2. refactor_utils-4.0.1/PKG-INFO +127 -0
  3. refactor_utils-4.0.1/README.md +90 -0
  4. refactor_utils-4.0.1/pyproject.toml +62 -0
  5. refactor_utils-4.0.1/src/refactor_utils/__init__.py +18 -0
  6. refactor_utils-4.0.1/src/refactor_utils/__main__.py +8 -0
  7. refactor_utils-4.0.1/src/refactor_utils/bundle.py +1288 -0
  8. refactor_utils-4.0.1/src/refactor_utils/cli.py +470 -0
  9. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils/core.py +155 -171
  10. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils/discovery.py +94 -115
  11. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils/imports.py +8 -25
  12. refactor_utils-4.0.1/src/refactor_utils/logging_setup.py +107 -0
  13. refactor_utils-4.0.1/src/refactor_utils/merged_file.py +122 -0
  14. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils/models.py +26 -27
  15. refactor_utils-4.0.1/src/refactor_utils/modernize.py +262 -0
  16. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils/ordering.py +15 -19
  17. refactor_utils-4.0.1/src/refactor_utils/parser.py +830 -0
  18. refactor_utils-4.0.1/src/refactor_utils/py.typed +0 -0
  19. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils/resolver.py +175 -243
  20. refactor_utils-4.0.1/src/refactor_utils/resources.py +234 -0
  21. refactor_utils-4.0.1/src/refactor_utils/writer.py +130 -0
  22. refactor_utils-4.0.1/src/refactor_utils.egg-info/PKG-INFO +127 -0
  23. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils.egg-info/SOURCES.txt +8 -5
  24. refactor_utils-4.0.1/src/refactor_utils.egg-info/requires.txt +16 -0
  25. refactor_utils-4.0.1/tests/test_smoke.py +215 -0
  26. refactor_utils-2.0.0/PKG-INFO +0 -212
  27. refactor_utils-2.0.0/README.md +0 -195
  28. refactor_utils-2.0.0/pyproject.toml +0 -43
  29. refactor_utils-2.0.0/src/refactor_utils/__init__.py +0 -6
  30. refactor_utils-2.0.0/src/refactor_utils/cli.py +0 -271
  31. refactor_utils-2.0.0/src/refactor_utils/data/README.md +0 -25
  32. refactor_utils-2.0.0/src/refactor_utils/data/config.ini +0 -5
  33. refactor_utils-2.0.0/src/refactor_utils/data/example.csv +0 -4
  34. refactor_utils-2.0.0/src/refactor_utils/data/sample.json +0 -6
  35. refactor_utils-2.0.0/src/refactor_utils/logging_setup.py +0 -15
  36. refactor_utils-2.0.0/src/refactor_utils/parser.py +0 -831
  37. refactor_utils-2.0.0/src/refactor_utils/writer.py +0 -100
  38. refactor_utils-2.0.0/src/refactor_utils.egg-info/PKG-INFO +0 -212
  39. refactor_utils-2.0.0/src/refactor_utils.egg-info/requires.txt +0 -13
  40. refactor_utils-2.0.0/tests/test_consolidate.py +0 -666
  41. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/setup.cfg +0 -0
  42. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils.egg-info/dependency_links.txt +0 -0
  43. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils.egg-info/entry_points.txt +0 -0
  44. {refactor_utils-2.0.0 → refactor_utils-4.0.1}/src/refactor_utils.egg-info/top_level.txt +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Z User
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,127 @@
1
+ Metadata-Version: 2.4
2
+ Name: refactor-utils
3
+ Version: 4.0.1
4
+ Summary: Consolidate a Python package into one dependency-ordered file, or pack it into a self-extracting zip bundle.
5
+ Author-email: Isaac Onagh <hellboynaz@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/i4147/refactor-utils
8
+ Project-URL: Repository, https://github.com/i4147/refactor-utils
9
+ Project-URL: Issues, https://github.com/i4147/refactor-utils/issues
10
+ Keywords: consolidate,bundle,merge,python,single-file,zip,modernize,six,pathlib
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Code Generators
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: libcst>=1.1.0
26
+ Requires-Dist: tomli>=2.0.0; python_version < "3.11"
27
+ Provides-Extra: format
28
+ Requires-Dist: black>=23.0; extra == "format"
29
+ Requires-Dist: ruff>=0.1.0; extra == "format"
30
+ Provides-Extra: progress
31
+ Requires-Dist: tqdm>=4.0; extra == "progress"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.0; extra == "dev"
34
+ Requires-Dist: black; extra == "dev"
35
+ Requires-Dist: ruff; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # refactor-utils (`pyrefactor`)
39
+
40
+ Consolidate a Python package / project into a **single dependency-ordered `.py`
41
+ file**, or pack it into a **self-extracting zip bundle**. Optionally apply
42
+ **modernization passes** (`six` → Python 3, `os.path` → `pathlib`) to the
43
+ output.
44
+
45
+ This is the merger of three earlier prototypes:
46
+
47
+ | origin | what it contributed |
48
+ | --- | --- |
49
+ | `ru.txt` (the original `refactor_utils`) | the libcst-based source consolidator: parallel parsing, import pruning/keep/strict, topological ordering, deduplication, name-conflict resolution, `__main__`-guard merging, data-file copy/embed, `pyproject.toml` config, black/ruff formatting |
50
+ | `consolidator.py` | **bundle mode** (`--bundle`): self-extracting zip standalone script, third-party package inclusion, `-m` module mode, `--main-module` synthesis, compression, deterministic builds |
51
+ | `consolidate.py` | **`--merged-file`** input (the `# File:` header format) and **`--modernize`** passes (`six`, `ospath`) |
52
+
53
+ ## Install
54
+
55
+ ```bash
56
+ pip install -e . # core (libcst only)
57
+ pip install -e ".[format]" # + black & ruff for --format
58
+ pip install -e ".[progress]" # + tqdm for --progress
59
+ ```
60
+
61
+ Provides the `pyrefactor` console script and `python -m refactor_utils`.
62
+
63
+ ## Quick start
64
+
65
+ ### Source consolidation (default)
66
+
67
+ ```bash
68
+ pyrefactor my_pkg/ -o out/ # out/my_pkg.py
69
+ pyrefactor my_pkg/ --format --imports strict
70
+ pyrefactor my_pkg/ --embed-data # fully self-contained .py
71
+ pyrefactor my_pkg/ --dry-run
72
+ pyrefactor my_pkg/ --check # CI: fail if output would change
73
+ pyrefactor my_pkg/ --modernize six,ospath # modernize the output
74
+ ```
75
+
76
+ ### Bundle mode (`--bundle`)
77
+
78
+ Produces a runnable `*_standalone.py` that embeds the package as a base64 zip
79
+ and extracts it to a temp dir at runtime:
80
+
81
+ ```bash
82
+ pyrefactor my_pkg/ --bundle -o out/run.py
83
+ pyrefactor my_pkg/ --bundle --include-package rich --site-path vendor
84
+ pyrefactor app/main.py --bundle -p src --include-data 'assets/*.json'
85
+ pyrefactor my_pkg/ --bundle --main-module cli # synthesize __main__.py
86
+ pyrefactor -m my.pkg --bundle # python -m emulation
87
+ ./out/run.py # runs the program unchanged
88
+ ```
89
+
90
+ Bundle runtime env vars: `PYREFACTOR_BUNDLE_DEBUG=1` (print extraction dir),
91
+ `PYREFACTOR_BUNDLE_KEEP=1` (keep the temp dir).
92
+
93
+ ### Merged-file input (`--merged-file` / `-f`)
94
+
95
+ Read a source tree from a single file using `# File: <relpath>` section headers
96
+ (the format produced by `pyrefactor --stdout` dumps and by this project's own
97
+ `ru.txt` archive):
98
+
99
+ ```bash
100
+ pyrefactor -f ru.txt -o out/ru.py
101
+ ```
102
+
103
+ ## Configuration
104
+
105
+ A `[tool.pyrefactor]` section in `pyproject.toml` is picked up automatically
106
+ (or pass `--config PATH`). Recognised keys: `exclude`, `include`, `entry`,
107
+ `imports`, `format`, `formatter`, `copy_data`, `embed_data`, `data_glob`,
108
+ `modernize`.
109
+
110
+ ## Notable fixes since v3
111
+
112
+ * **TRACE log level actually works** — the root logger was capped at `DEBUG=10`,
113
+ which silently dropped every `TRACE` (level 5) record before it reached the
114
+ handler. The logger now sits at or below TRACE so the handler decides.
115
+ * **Formatter failures are no longer silent** — `--format` now logs a warning
116
+ when black/ruff is missing or errors, and checks the ruff subprocess exit code
117
+ instead of swallowing every exception.
118
+ * Added `__main__.py` (`python -m refactor_utils`) and a proper `pyproject.toml`
119
+ entry point.
120
+
121
+ ## What was *not* ported
122
+
123
+ `consolidate.py`'s `LoggingTransformer` (logging → loguru) and
124
+ `ExecutorTransformer` (concurrent.futures → multiprocessing.Pool) were left out:
125
+ both assume a specific runtime convention (`logger` is loguru; a `MAX_WORKERS`/
126
+ `mp.Pool` shape) that does not generalise to arbitrary projects. The general
127
+ `six` and `os.path` passes are available under `--modernize`.
@@ -0,0 +1,90 @@
1
+ # refactor-utils (`pyrefactor`)
2
+
3
+ Consolidate a Python package / project into a **single dependency-ordered `.py`
4
+ file**, or pack it into a **self-extracting zip bundle**. Optionally apply
5
+ **modernization passes** (`six` → Python 3, `os.path` → `pathlib`) to the
6
+ output.
7
+
8
+ This is the merger of three earlier prototypes:
9
+
10
+ | origin | what it contributed |
11
+ | --- | --- |
12
+ | `ru.txt` (the original `refactor_utils`) | the libcst-based source consolidator: parallel parsing, import pruning/keep/strict, topological ordering, deduplication, name-conflict resolution, `__main__`-guard merging, data-file copy/embed, `pyproject.toml` config, black/ruff formatting |
13
+ | `consolidator.py` | **bundle mode** (`--bundle`): self-extracting zip standalone script, third-party package inclusion, `-m` module mode, `--main-module` synthesis, compression, deterministic builds |
14
+ | `consolidate.py` | **`--merged-file`** input (the `# File:` header format) and **`--modernize`** passes (`six`, `ospath`) |
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pip install -e . # core (libcst only)
20
+ pip install -e ".[format]" # + black & ruff for --format
21
+ pip install -e ".[progress]" # + tqdm for --progress
22
+ ```
23
+
24
+ Provides the `pyrefactor` console script and `python -m refactor_utils`.
25
+
26
+ ## Quick start
27
+
28
+ ### Source consolidation (default)
29
+
30
+ ```bash
31
+ pyrefactor my_pkg/ -o out/ # out/my_pkg.py
32
+ pyrefactor my_pkg/ --format --imports strict
33
+ pyrefactor my_pkg/ --embed-data # fully self-contained .py
34
+ pyrefactor my_pkg/ --dry-run
35
+ pyrefactor my_pkg/ --check # CI: fail if output would change
36
+ pyrefactor my_pkg/ --modernize six,ospath # modernize the output
37
+ ```
38
+
39
+ ### Bundle mode (`--bundle`)
40
+
41
+ Produces a runnable `*_standalone.py` that embeds the package as a base64 zip
42
+ and extracts it to a temp dir at runtime:
43
+
44
+ ```bash
45
+ pyrefactor my_pkg/ --bundle -o out/run.py
46
+ pyrefactor my_pkg/ --bundle --include-package rich --site-path vendor
47
+ pyrefactor app/main.py --bundle -p src --include-data 'assets/*.json'
48
+ pyrefactor my_pkg/ --bundle --main-module cli # synthesize __main__.py
49
+ pyrefactor -m my.pkg --bundle # python -m emulation
50
+ ./out/run.py # runs the program unchanged
51
+ ```
52
+
53
+ Bundle runtime env vars: `PYREFACTOR_BUNDLE_DEBUG=1` (print extraction dir),
54
+ `PYREFACTOR_BUNDLE_KEEP=1` (keep the temp dir).
55
+
56
+ ### Merged-file input (`--merged-file` / `-f`)
57
+
58
+ Read a source tree from a single file using `# File: <relpath>` section headers
59
+ (the format produced by `pyrefactor --stdout` dumps and by this project's own
60
+ `ru.txt` archive):
61
+
62
+ ```bash
63
+ pyrefactor -f ru.txt -o out/ru.py
64
+ ```
65
+
66
+ ## Configuration
67
+
68
+ A `[tool.pyrefactor]` section in `pyproject.toml` is picked up automatically
69
+ (or pass `--config PATH`). Recognised keys: `exclude`, `include`, `entry`,
70
+ `imports`, `format`, `formatter`, `copy_data`, `embed_data`, `data_glob`,
71
+ `modernize`.
72
+
73
+ ## Notable fixes since v3
74
+
75
+ * **TRACE log level actually works** — the root logger was capped at `DEBUG=10`,
76
+ which silently dropped every `TRACE` (level 5) record before it reached the
77
+ handler. The logger now sits at or below TRACE so the handler decides.
78
+ * **Formatter failures are no longer silent** — `--format` now logs a warning
79
+ when black/ruff is missing or errors, and checks the ruff subprocess exit code
80
+ instead of swallowing every exception.
81
+ * Added `__main__.py` (`python -m refactor_utils`) and a proper `pyproject.toml`
82
+ entry point.
83
+
84
+ ## What was *not* ported
85
+
86
+ `consolidate.py`'s `LoggingTransformer` (logging → loguru) and
87
+ `ExecutorTransformer` (concurrent.futures → multiprocessing.Pool) were left out:
88
+ both assume a specific runtime convention (`logger` is loguru; a `MAX_WORKERS`/
89
+ `mp.Pool` shape) that does not generalise to arbitrary projects. The general
90
+ `six` and `os.path` passes are available under `--modernize`.
@@ -0,0 +1,62 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "refactor-utils"
7
+ version = "4.0.1"
8
+ description = "Consolidate a Python package into one dependency-ordered file, or pack it into a self-extracting zip bundle."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "MIT" }
12
+ keywords = ["consolidate", "bundle", "merge", "python", "single-file", "zip", "modernize", "six", "pathlib"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Environment :: Console",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Topic :: Software Development :: Code Generators",
24
+ "Topic :: Utilities",
25
+ ]
26
+ dependencies = [
27
+ "libcst>=1.1.0",
28
+ "tomli>=2.0.0; python_version < '3.11'",
29
+ ]
30
+
31
+ [[project.authors]]
32
+ name = "Isaac Onagh"
33
+ email = "hellboynaz@gmail.com"
34
+ [project.optional-dependencies]
35
+ format = ["black>=23.0", "ruff>=0.1.0"]
36
+ progress = ["tqdm>=4.0"]
37
+ dev = ["pytest>=7.0", "black", "ruff"]
38
+
39
+ [project.scripts]
40
+ pyrefactor = "refactor_utils.cli:main"
41
+
42
+ [project.urls]
43
+ Homepage = "https://github.com/i4147/refactor-utils"
44
+ Repository = "https://github.com/i4147/refactor-utils"
45
+ Issues = "https://github.com/i4147/refactor-utils/issues"
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["src"]
49
+
50
+ [tool.setuptools.package-data]
51
+ refactor_utils = ["py.typed"]
52
+
53
+ [tool.pyrefactor]
54
+ # Self-consolidation config used by `pyrefactor .` on this very package.
55
+ # (Demonstrates the config-file feature; not required for installation.)
56
+ imports = "prune"
57
+ keep_docstrings = true
58
+ keep_comments = true
59
+
60
+ [tool.ruff]
61
+ line-length = 120
62
+ target-version = "py311"
@@ -0,0 +1,18 @@
1
+ from .core import (
2
+ ConsolidationError,
3
+ ConsolidationResult,
4
+ consolidate,
5
+ validate_syntax,
6
+ )
7
+ from .resolver import Plan
8
+
9
+ __version__ = "4.0.1"
10
+
11
+ __all__ = [
12
+ "ConsolidationError",
13
+ "ConsolidationResult",
14
+ "Plan",
15
+ "consolidate",
16
+ "validate_syntax",
17
+ "__version__",
18
+ ]
@@ -0,0 +1,8 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+
5
+ from .cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())