pyrefactor 1.0.1__py3-none-any.whl

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.
@@ -0,0 +1,353 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyrefactor
3
+ Version: 1.0.1
4
+ Summary: A Python refactoring and optimization linter that analyzes code for performance issues, complexity problems, and opportunities for improvement
5
+ Author: tboy1337
6
+ Maintainer: tboy1337
7
+ License: Commercial Restricted License (CRL)
8
+ Project-URL: Homepage, https://github.com/tboy1337/PyRefactor
9
+ Project-URL: Repository, https://github.com/tboy1337/PyRefactor
10
+ Project-URL: Issues, https://github.com/tboy1337/PyRefactor/issues
11
+ Project-URL: Changelog, https://github.com/tboy1337/PyRefactor/releases
12
+ Project-URL: Documentation, https://github.com/tboy1337/PyRefactor#readme
13
+ Keywords: refactoring,linter,code-quality,static-analysis,ast,optimization,performance,complexity,code-analysis,python-linter,code-smell,maintainability,best-practices,code-review,cyclomatic-complexity
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: Other/Proprietary License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: Operating System :: POSIX :: Linux
20
+ Classifier: Operating System :: MacOS
21
+ Classifier: Programming Language :: Python
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3.9
24
+ Classifier: Programming Language :: Python :: 3.10
25
+ Classifier: Programming Language :: Python :: 3.11
26
+ Classifier: Programming Language :: Python :: 3.12
27
+ Classifier: Programming Language :: Python :: 3.13
28
+ Classifier: Programming Language :: Python :: 3 :: Only
29
+ Classifier: Programming Language :: Python :: Implementation :: CPython
30
+ Classifier: Topic :: Software Development
31
+ Classifier: Topic :: Software Development :: Quality Assurance
32
+ Classifier: Topic :: Software Development :: Testing
33
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
34
+ Classifier: Topic :: Utilities
35
+ Classifier: Typing :: Typed
36
+ Classifier: Environment :: Console
37
+ Classifier: Natural Language :: English
38
+ Requires-Python: >=3.9
39
+ Description-Content-Type: text/markdown
40
+ License-File: LICENSE.md
41
+ Requires-Dist: colorama
42
+ Dynamic: license-file
43
+
44
+ # PyRefactor
45
+
46
+ A powerful Python refactoring and optimization linter that analyzes your code for performance issues, complexity problems, and opportunities for improvement.
47
+
48
+ [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
49
+
50
+ ## Overview
51
+
52
+ PyRefactor uses Abstract Syntax Tree (AST) analysis to identify code patterns that can be refactored for better performance, readability, and maintainability. It provides actionable insights with severity levels and detailed explanations for each detected issue.
53
+
54
+ ## Features
55
+
56
+ - **Multi-threaded Analysis**: Analyze multiple files in parallel for faster results
57
+ - **Configurable Detectors**: Enable or disable specific detectors based on your needs
58
+ - **Severity Levels**: Issues categorized as INFO, LOW, MEDIUM, or HIGH severity
59
+ - **Multiple Output Formats**: Group results by file or severity level
60
+ - **Flexible Configuration**: Configure via `pyproject.toml`, custom config files, or command-line arguments
61
+ - **Cross-platform**: Works on Windows, macOS, and Linux
62
+
63
+ ## Detectors
64
+
65
+ PyRefactor includes the following specialized detectors:
66
+
67
+ ### Complexity Detector
68
+ Identifies functions and methods with high cyclomatic complexity that should be refactored for better maintainability.
69
+
70
+ ### Performance Detector
71
+ Finds performance anti-patterns including:
72
+ - Inefficient string concatenation in loops
73
+ - Multiple function calls that could be cached
74
+ - Inefficient list operations
75
+ - Unnecessary comprehensions
76
+
77
+ ### Boolean Logic Detector
78
+ Detects overcomplicated boolean expressions and suggests simplifications:
79
+ - Complex conditional chains
80
+ - Redundant boolean operations
81
+ - Opportunities for boolean algebra simplification
82
+
83
+ ### Loops Detector
84
+ Identifies loop-related issues:
85
+ - Nested loops that could be optimized
86
+ - Loop invariant code that should be hoisted
87
+ - Loops that could be replaced with comprehensions or built-in functions
88
+
89
+ ### Duplication Detector
90
+ Finds duplicated code blocks that should be extracted into reusable functions.
91
+
92
+ ### Context Manager Detector
93
+ Detects resource-allocating operations that should use `with` statements:
94
+ - File operations (`open()`, etc.)
95
+ - Lock acquisitions
96
+ - Context managers not used properly
97
+ - **Impact**: Prevents resource leaks and ensures proper cleanup
98
+
99
+ ### Control Flow Detector
100
+ Identifies unnecessary control flow patterns:
101
+ - Unnecessary `else` after `return` statement
102
+ - Unnecessary `else` after `raise` statement
103
+ - Unnecessary `else` after `break` statement
104
+ - Unnecessary `else` after `continue` statement
105
+ - **Impact**: Reduces nesting and improves code readability
106
+
107
+ ### Dictionary Operations Detector
108
+ Finds inefficient or non-idiomatic dictionary operations:
109
+ - Opportunities to use `dict.get(key, default)` instead of if/else
110
+ - Unnecessary `.keys()` calls when iterating
111
+ - Loops that should use `.items()` instead of indexing
112
+ - Opportunities for dictionary comprehensions
113
+ - **Impact**: More Pythonic and performant code
114
+
115
+ ### Comparisons Detector
116
+ Detects non-idiomatic comparison patterns:
117
+ - Multiple `==` comparisons that could use `in` operator
118
+ - Comparisons that could be chained (e.g., `a < b < c`)
119
+ - Singleton comparisons with `==` instead of `is` (for `None`, `True`, `False`)
120
+ - Using `type()` instead of `isinstance()` for type checking
121
+ - **Impact**: Cleaner, more idiomatic code
122
+
123
+ ## Installation
124
+
125
+ ### From Source
126
+
127
+ ```powershell
128
+ # Clone the repository
129
+ git clone https://github.com/tboy1337/PyRefactor.git
130
+ cd PyRefactor
131
+
132
+ # Install dependencies
133
+ py -m pip install -r requirements.txt
134
+
135
+ # Install in development mode
136
+ py -m pip install -e .
137
+ ```
138
+
139
+ ### Requirements
140
+
141
+ - Python 3.13 or higher
142
+ - colorama (for colored console output)
143
+
144
+ ## Usage
145
+
146
+ ### Basic Usage
147
+
148
+ ```powershell
149
+ # Analyze a single file
150
+ pyrefactor myfile.py
151
+
152
+ # Analyze a directory
153
+ pyrefactor src/
154
+
155
+ # Analyze multiple files
156
+ pyrefactor file1.py file2.py src/module.py
157
+
158
+ # Analyze with custom configuration
159
+ pyrefactor --config custom.toml src/
160
+ ```
161
+
162
+ ### Command-line Options
163
+
164
+ ```
165
+ positional arguments:
166
+ paths Python files or directories to analyze
167
+
168
+ options:
169
+ -h, --help show this help message and exit
170
+ -c CONFIG, --config CONFIG
171
+ Path to configuration file (default: pyproject.toml)
172
+ -g {file,severity}, --group-by {file,severity}
173
+ Group output by file or severity (default: file)
174
+ --min-severity {info,low,medium,high}
175
+ Minimum severity level to report (default: info)
176
+ -j JOBS, --jobs JOBS Number of parallel jobs (default: 4)
177
+ -v, --verbose Enable verbose logging
178
+ --version Show version and exit
179
+ ```
180
+
181
+ ### Examples
182
+
183
+ ```powershell
184
+ # Show only HIGH and MEDIUM severity issues
185
+ pyrefactor --min-severity medium src/
186
+
187
+ # Group results by severity level
188
+ pyrefactor --group-by severity src/
189
+
190
+ # Use 8 parallel workers for faster analysis
191
+ pyrefactor --jobs 8 large_project/
192
+
193
+ # Verbose output with detailed logging
194
+ pyrefactor -v src/
195
+ ```
196
+
197
+ ### Exit Codes
198
+
199
+ PyRefactor uses the following exit codes:
200
+
201
+ - `0` - No issues found, or only INFO/LOW severity issues
202
+ - `1` - MEDIUM or HIGH severity issues found
203
+ - `2` - Error during analysis (syntax errors, invalid paths, etc.)
204
+
205
+ This makes PyRefactor suitable for use in CI/CD pipelines where you can fail builds based on code quality issues.
206
+
207
+ ## Configuration
208
+
209
+ PyRefactor can be configured using a TOML configuration file. By default, it looks for configuration in `pyproject.toml` or a file specified with `--config`.
210
+
211
+ ### Example Configuration
212
+
213
+ ```toml
214
+ [tool.pyrefactor]
215
+ # Patterns to exclude from analysis
216
+ exclude_patterns = [
217
+ "__pycache__",
218
+ ".venv",
219
+ "venv",
220
+ ".git",
221
+ "build",
222
+ "dist",
223
+ ]
224
+
225
+ [tool.pyrefactor.complexity]
226
+ # Maximum allowed cyclomatic complexity
227
+ max_complexity = 10
228
+
229
+ [tool.pyrefactor.performance]
230
+ enabled = true
231
+ # Minimum number of string concatenations to report
232
+ min_concatenations = 3
233
+ # Minimum number of duplicate calls to report
234
+ min_duplicate_calls = 3
235
+
236
+ [tool.pyrefactor.boolean_logic]
237
+ enabled = true
238
+ # Minimum depth of nested boolean expressions to report
239
+ min_depth = 3
240
+
241
+ [tool.pyrefactor.loops]
242
+ enabled = true
243
+ # Maximum allowed nesting depth for loops
244
+ max_nesting = 3
245
+
246
+ [tool.pyrefactor.duplication]
247
+ enabled = true
248
+ # Minimum number of lines for a code block to be considered for duplication detection
249
+ min_lines = 5
250
+ # Minimum similarity threshold (0.0 to 1.0)
251
+ similarity_threshold = 0.8
252
+
253
+ [tool.pyrefactor.context_manager]
254
+ enabled = true
255
+
256
+ [tool.pyrefactor.control_flow]
257
+ enabled = true
258
+
259
+ [tool.pyrefactor.dict_operations]
260
+ enabled = true
261
+
262
+ [tool.pyrefactor.comparisons]
263
+ enabled = true
264
+ ```
265
+
266
+ ### Configuration File Location
267
+
268
+ PyRefactor searches for configuration in the following order:
269
+
270
+ 1. Path specified with `--config` option
271
+ 2. `pyproject.toml` in the current directory
272
+ 3. `pyrefactor.ini` in the current directory
273
+ 4. Default configuration values
274
+
275
+ ## Integration
276
+
277
+ ### Pre-commit Hook
278
+
279
+ Add PyRefactor to your `.pre-commit-config.yaml`:
280
+
281
+ ```yaml
282
+ repos:
283
+ - repo: local
284
+ hooks:
285
+ - id: pyrefactor
286
+ name: PyRefactor
287
+ entry: pyrefactor
288
+ language: system
289
+ types: [python]
290
+ args: [--min-severity=medium]
291
+ ```
292
+
293
+ ### CI/CD Integration
294
+
295
+ #### GitHub Actions
296
+
297
+ ```yaml
298
+ name: Code Quality
299
+
300
+ on: [push, pull_request]
301
+
302
+ jobs:
303
+ pyrefactor:
304
+ runs-on: windows-latest
305
+ steps:
306
+ - uses: actions/checkout@v3
307
+ - name: Set up Python
308
+ uses: actions/setup-python@v4
309
+ with:
310
+ python-version: '3.13'
311
+ - name: Install dependencies
312
+ run: |
313
+ py -m pip install --upgrade pip
314
+ py -m pip install pyrefactor
315
+ - name: Run PyRefactor
316
+ run: pyrefactor --min-severity medium src/
317
+ ```
318
+
319
+ ## Troubleshooting
320
+
321
+ ### Common Issues
322
+
323
+ **Issue**: `ModuleNotFoundError: No module named 'pyrefactor'`
324
+
325
+ **Solution**: Make sure PyRefactor is installed: `py -m pip install -e .`
326
+
327
+ ---
328
+
329
+ **Issue**: Syntax errors when analyzing Python 3.12 or older code
330
+
331
+ **Solution**: PyRefactor requires Python 3.13+. Ensure your environment is using Python 3.13 or newer.
332
+
333
+ ---
334
+
335
+ **Issue**: Analysis is slow on large codebases
336
+
337
+ **Solution**: Increase the number of parallel workers: `pyrefactor --jobs 8 src/`
338
+
339
+ ## Contributing
340
+
341
+ Contributions are welcome! Please note that this project is under a Commercial Restricted License (CRL). For commercial use, please contact the copyright holder.
342
+
343
+ ### Guidelines
344
+
345
+ 1. Follow the existing code style (Black, isort)
346
+ 2. Add tests for new features
347
+ 3. Ensure all tests pass and coverage remains >95%
348
+ 4. Update documentation as needed
349
+ 5. Run type checking and linting before submitting
350
+
351
+ ## License
352
+
353
+ This project is licensed under the CRL license - see [LICENSE.md](LICENSE.md) for details.
@@ -0,0 +1,24 @@
1
+ pyrefactor/__init__.py,sha256=2177vJsLuSNphi6zgGTQI6QYJ0VvhEggqXbRxCv2XZg,91
2
+ pyrefactor/__main__.py,sha256=U4Emvi0l0-PEVZA2Kuco6TJuccdSPBckJsMXM03pZOE,7017
3
+ pyrefactor/analyzer.py,sha256=kuRhrR6R9vdrVh8CWcr_h0ibYFxvjxgOa5SwPYCOtpA,6538
4
+ pyrefactor/ast_visitor.py,sha256=pRb-_IMG5bx46eOcsR4yIxUBFUFvoYUVOhrTFhfBwx4,6802
5
+ pyrefactor/config.py,sha256=s1afhPkze8tUWdvAwhBK3V8_J2fCeexRc8HQ-0IYbyo,8237
6
+ pyrefactor/models.py,sha256=4kDW3sGzQ8ckvcQ3spdU57196iyC8sGkosbQYgWTENk,3111
7
+ pyrefactor/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ pyrefactor/reporter.py,sha256=72NA-M3oC9JbywbCDygVuufXbw2ZMJ2blbRJwLUcCPM,7624
9
+ pyrefactor/detectors/__init__.py,sha256=-JbOtWU5mFkS-IeBjxTBJeWxpsiWow9l6RIptPYA6b8,730
10
+ pyrefactor/detectors/boolean_logic.py,sha256=JCYzv4BrayMoCsI_Bp_6lrvTlKE2auK1biz7-P7wHQk,8350
11
+ pyrefactor/detectors/comparisons.py,sha256=QZ_KTudRCpbajcF2QIjPBfV6PbRKrLREy7kT3-hqT9A,12669
12
+ pyrefactor/detectors/complexity.py,sha256=BlW1LPRxPPNqSCs2dkiOQYLzzVckYWpaVQqXsuRDugg,8844
13
+ pyrefactor/detectors/context_manager.py,sha256=LIlfjeENkQiW2ahXmqyv54iol8yTwGriBcE2E7Ocfuo,6886
14
+ pyrefactor/detectors/control_flow.py,sha256=NPUUCEUHTdVT0FfAU5jGShmlPPHgtbJZrnJShEift7M,5358
15
+ pyrefactor/detectors/dict_operations.py,sha256=2muBMcIl-M9JJXmXQJ9DcBoG4xbhu2xfsHKBEsOjJsk,11817
16
+ pyrefactor/detectors/duplication.py,sha256=_ErnVlBlLQjc9dSkbYc5zfUxDVP-SPWNb_I2fQR4rsY,13569
17
+ pyrefactor/detectors/loops.py,sha256=9ZwiU9U_sv0E5tQeSlOjpOddSCks7mepUVGghxj2K7Y,9760
18
+ pyrefactor/detectors/performance.py,sha256=uu1kK2FvZ30PUm4RS8Jt9f3EqCUyZaOEtsIqdftV0gQ,9528
19
+ pyrefactor-1.0.1.dist-info/licenses/LICENSE.md,sha256=NYP65MjIOiBIzSEUIwUQw56lJYkP_7nGPFfgIgyl-iI,3035
20
+ pyrefactor-1.0.1.dist-info/METADATA,sha256=z97BTSt4x6ULoOJ5JwjP8b0TbsLd6d-R7Znl_CT9P4I,10775
21
+ pyrefactor-1.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ pyrefactor-1.0.1.dist-info/entry_points.txt,sha256=xRew-6hh_lJPnaHeYDgetD0sseRGxaaz6EGitj0ztYE,56
23
+ pyrefactor-1.0.1.dist-info/top_level.txt,sha256=gWLi3EgoB9D6SJvyeqPwvuQyoV3H-b4b6hFQ0_k2oSo,11
24
+ pyrefactor-1.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pyrefactor = pyrefactor.__main__:main
@@ -0,0 +1,70 @@
1
+ # Commercial Restricted License (CRL)
2
+
3
+ **Version 1.1**
4
+
5
+ **Copyright (c) 2025 tboy1337**
6
+
7
+ ## Grant of Rights
8
+
9
+ Subject to the terms and conditions of this license, the copyright holder grants you a worldwide, royalty-free, non-exclusive license to use, copy, modify, and distribute this software and associated documentation files (the "Software") for **Non-Commercial Use** only.
10
+
11
+ ## Definitions
12
+
13
+ **"Non-Commercial Use"** means use of the Software that is not primarily intended for or directed toward commercial advantage or monetary compensation. Non-Commercial Use includes:
14
+
15
+ - Personal use, learning, and experimentation
16
+ - Academic research and education
17
+ - Open source projects that are not monetized
18
+ - Internal evaluation within a commercial organization (limited to 30 days)
19
+ - Use by registered non-profit organizations for their non-profit activities
20
+
21
+ **"Commercial Use"** means any use of the Software that is primarily intended for or directed toward commercial advantage or monetary compensation, including but not limited to:
22
+
23
+ - Use in any product or service that generates revenue
24
+ - Use by for-profit organizations in their business operations
25
+ - Integration into commercial software or services
26
+ - Use in providing paid consulting, support, or services
27
+ - Use in any business process that contributes to revenue generation
28
+ - Use by organizations with annual revenue exceeding $100,000 USD
29
+
30
+ **Note:** Any Commercial Use of the Software requires a separate commercial license from the copyright holder.
31
+
32
+ ## Conditions
33
+
34
+ For Non-Commercial Use, you may:
35
+
36
+ - Use, copy, and modify the Software
37
+ - Distribute copies of the Software
38
+ - Distribute your modifications under this same license
39
+
40
+ You must:
41
+
42
+ - Include this license notice in all copies or substantial portions of the Software
43
+ - Not remove or alter any copyright notices
44
+
45
+ ## Restrictions
46
+
47
+ You may not:
48
+
49
+ - Use the Software for Commercial Use without a commercial license
50
+ - Sublicense the Software under different terms
51
+ - Use the Software in any way that violates applicable laws
52
+ - Remove, obscure, or modify any licensing, copyright, or other legal notices
53
+
54
+ ## No Warranty
55
+
56
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
62
+ SOFTWARE.
63
+
64
+ ## Termination
65
+
66
+ This license terminates automatically if you violate any of its terms. Upon termination, you must cease all use and distribution of the Software and destroy all copies in your possession.
67
+
68
+ ## Governing Law
69
+
70
+ This license shall be governed by and construed in accordance with the laws of the United Kingdom, without regard to its conflict of law provisions.
@@ -0,0 +1 @@
1
+ pyrefactor