Skip to content

Commit 4224559

Browse files
committed
Update README for clarity and conciseness; enhance feature descriptions and installation instructions. Increment version to 1.0.4.
1 parent 53a1eda commit 4224559

2 files changed

Lines changed: 62 additions & 200 deletions

File tree

README.md

Lines changed: 61 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -1,210 +1,113 @@
11
# PyRefactor
22

3-
A powerful Python refactoring and optimization linter that analyzes your code for performance issues, complexity problems, and opportunities for improvement.
3+
A Python refactoring and optimization linter that uses AST analysis to identify performance issues, complexity problems, and code improvements.
44

55
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
66

7-
## Overview
8-
9-
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.
10-
117
## Features
128

13-
- **Multi-threaded Analysis**: Analyze multiple files in parallel for faster results
14-
- **Configurable Detectors**: Enable or disable specific detectors based on your needs
15-
- **Severity Levels**: Issues categorized as INFO, LOW, MEDIUM, or HIGH severity
16-
- **Multiple Output Formats**: Group results by file or severity level
17-
- **Flexible Configuration**: Configure via `pyproject.toml`, custom config files, or command-line arguments
9+
- **Multi-threaded Analysis**: Fast parallel file processing
10+
- **Configurable Detectors**: Enable/disable specific detectors
11+
- **Severity Levels**: Issues categorized as INFO, LOW, MEDIUM, or HIGH
12+
- **Flexible Output**: Group by file or severity
1813
- **Cross-platform**: Works on Windows, macOS, and Linux
1914

2015
## Detectors
2116

22-
PyRefactor includes the following specialized detectors:
23-
24-
### Complexity Detector
25-
Identifies functions and methods with high cyclomatic complexity that should be refactored for better maintainability.
26-
27-
### Performance Detector
28-
Finds performance anti-patterns including:
29-
- Inefficient string concatenation in loops
30-
- Multiple function calls that could be cached
31-
- Inefficient list operations
32-
- Unnecessary comprehensions
33-
34-
### Boolean Logic Detector
35-
Detects overcomplicated boolean expressions and suggests simplifications:
36-
- Complex conditional chains
37-
- Redundant boolean operations
38-
- Opportunities for boolean algebra simplification
39-
40-
### Loops Detector
41-
Identifies loop-related issues:
42-
- Nested loops that could be optimized
43-
- Loop invariant code that should be hoisted
44-
- Loops that could be replaced with comprehensions or built-in functions
45-
46-
### Duplication Detector
47-
Finds duplicated code blocks that should be extracted into reusable functions.
48-
49-
### Context Manager Detector
50-
Detects resource-allocating operations that should use `with` statements:
51-
- File operations (`open()`, etc.)
52-
- Lock acquisitions
53-
- Context managers not used properly
54-
- **Impact**: Prevents resource leaks and ensures proper cleanup
55-
56-
### Control Flow Detector
57-
Identifies unnecessary control flow patterns:
58-
- Unnecessary `else` after `return` statement
59-
- Unnecessary `else` after `raise` statement
60-
- Unnecessary `else` after `break` statement
61-
- Unnecessary `else` after `continue` statement
62-
- **Impact**: Reduces nesting and improves code readability
63-
64-
### Dictionary Operations Detector
65-
Finds inefficient or non-idiomatic dictionary operations:
66-
- Opportunities to use `dict.get(key, default)` instead of if/else
67-
- Unnecessary `.keys()` calls when iterating
68-
- Loops that should use `.items()` instead of indexing
69-
- Opportunities for dictionary comprehensions
70-
- **Impact**: More Pythonic and performant code
71-
72-
### Comparisons Detector
73-
Detects non-idiomatic comparison patterns:
74-
- Multiple `==` comparisons that could use `in` operator
75-
- Comparisons that could be chained (e.g., `a < b < c`)
76-
- Singleton comparisons with `==` instead of `is` (for `None`, `True`, `False`)
77-
- Using `type()` instead of `isinstance()` for type checking
78-
- **Impact**: Cleaner, more idiomatic code
17+
- **Complexity**: High cyclomatic complexity functions
18+
- **Performance**: String concatenation in loops, uncached calls, inefficient operations
19+
- **Boolean Logic**: Overcomplicated boolean expressions
20+
- **Loops**: Nested loops, invariant code, comprehension opportunities
21+
- **Duplication**: Duplicate code blocks
22+
- **Context Manager**: Missing `with` statements for resource operations
23+
- **Control Flow**: Unnecessary `else` after `return`/`raise`/`break`/`continue`
24+
- **Dictionary Operations**: Non-idiomatic dict patterns, missing `.get()`, unnecessary `.keys()`
25+
- **Comparisons**: Chained comparisons, singleton checks, `type()` vs `isinstance()`
7926

8027
## Installation
8128

29+
### Recommended: Via pip
30+
31+
```bash
32+
pip install pyrefactor
33+
```
34+
35+
### Standalone Executable
36+
37+
Download the latest release from the [Releases](https://github.com/tboy1337/PyRefactor/releases/latest) section. No Python installation required.
38+
8239
### From Source
8340

84-
```powershell
85-
# Clone the repository
41+
```bash
8642
git clone https://github.com/tboy1337/PyRefactor.git
8743
cd PyRefactor
88-
89-
# Install dependencies
90-
py -m pip install -r requirements.txt
91-
92-
# Install in development mode
93-
py -m pip install -e .
44+
pip install -e .
9445
```
9546

96-
### Requirements
97-
98-
- Python 3.13 or higher
99-
- colorama (for colored console output)
47+
**Requirements**: Python 3.9+
10048

10149
## Usage
10250

103-
### Basic Usage
104-
105-
```powershell
106-
# Analyze a single file
51+
```bash
52+
# Analyze a file or directory
10753
pyrefactor myfile.py
108-
109-
# Analyze a directory
11054
pyrefactor src/
11155

112-
# Analyze multiple files
113-
pyrefactor file1.py file2.py src/module.py
114-
115-
# Analyze with custom configuration
116-
pyrefactor --config custom.toml src/
117-
```
118-
119-
### Command-line Options
120-
121-
```
122-
positional arguments:
123-
paths Python files or directories to analyze
124-
125-
options:
126-
-h, --help show this help message and exit
127-
-c CONFIG, --config CONFIG
128-
Path to configuration file (default: pyproject.toml)
129-
-g {file,severity}, --group-by {file,severity}
130-
Group output by file or severity (default: file)
131-
--min-severity {info,low,medium,high}
132-
Minimum severity level to report (default: info)
133-
-j JOBS, --jobs JOBS Number of parallel jobs (default: 4)
134-
-v, --verbose Enable verbose logging
135-
--version Show version and exit
136-
```
137-
138-
### Examples
139-
140-
```powershell
141-
# Show only HIGH and MEDIUM severity issues
56+
# Show only medium/high severity issues
14257
pyrefactor --min-severity medium src/
14358

144-
# Group results by severity level
59+
# Group by severity level
14560
pyrefactor --group-by severity src/
14661

147-
# Use 8 parallel workers for faster analysis
148-
pyrefactor --jobs 8 large_project/
62+
# Use more workers for faster analysis
63+
pyrefactor --jobs 8 src/
14964

150-
# Verbose output with detailed logging
151-
pyrefactor -v src/
65+
# Custom configuration file
66+
pyrefactor --config custom.toml src/
15267
```
15368

154-
### Exit Codes
69+
### Options
15570

156-
PyRefactor uses the following exit codes:
71+
- `-c, --config`: Configuration file path (default: `pyproject.toml`)
72+
- `-g, --group-by`: Group by `file` or `severity` (default: `file`)
73+
- `--min-severity`: Minimum severity to report: `info`, `low`, `medium`, `high` (default: `info`)
74+
- `-j, --jobs`: Number of parallel workers (default: 4)
75+
- `-v, --verbose`: Enable verbose logging
76+
- `--version`: Show version
15777

158-
- `0` - No issues found, or only INFO/LOW severity issues
159-
- `1` - MEDIUM or HIGH severity issues found
160-
- `2` - Error during analysis (syntax errors, invalid paths, etc.)
78+
### Exit Codes
16179

162-
This makes PyRefactor suitable for use in CI/CD pipelines where you can fail builds based on code quality issues.
80+
- `0` - No issues or only INFO/LOW severity
81+
- `1` - MEDIUM/HIGH severity issues found
82+
- `2` - Analysis error (syntax errors, invalid paths)
16383

16484
## Configuration
16585

166-
PyRefactor can be configured using a TOML configuration file. By default, it looks for configuration in `pyproject.toml` or a file specified with `--config`.
167-
168-
### Example Configuration
86+
Configure via TOML file (e.g., `pyproject.toml`):
16987

17088
```toml
17189
[tool.pyrefactor]
172-
# Patterns to exclude from analysis
173-
exclude_patterns = [
174-
"__pycache__",
175-
".venv",
176-
"venv",
177-
".git",
178-
"build",
179-
"dist",
180-
]
90+
exclude_patterns = ["__pycache__", ".venv", "build", "dist"]
18191

18292
[tool.pyrefactor.complexity]
183-
# Maximum allowed cyclomatic complexity
18493
max_complexity = 10
18594

18695
[tool.pyrefactor.performance]
18796
enabled = true
188-
# Minimum number of string concatenations to report
18997
min_concatenations = 3
190-
# Minimum number of duplicate calls to report
19198
min_duplicate_calls = 3
19299

193100
[tool.pyrefactor.boolean_logic]
194101
enabled = true
195-
# Minimum depth of nested boolean expressions to report
196102
min_depth = 3
197103

198104
[tool.pyrefactor.loops]
199105
enabled = true
200-
# Maximum allowed nesting depth for loops
201106
max_nesting = 3
202107

203108
[tool.pyrefactor.duplication]
204109
enabled = true
205-
# Minimum number of lines for a code block to be considered for duplication detection
206110
min_lines = 5
207-
# Minimum similarity threshold (0.0 to 1.0)
208111
similarity_threshold = 0.8
209112

210113
[tool.pyrefactor.context_manager]
@@ -220,21 +123,12 @@ enabled = true
220123
enabled = true
221124
```
222125

223-
### Configuration File Location
224-
225-
PyRefactor searches for configuration in the following order:
126+
Configuration is searched in: `--config``pyproject.toml``pyrefactor.ini` → defaults
226127

227-
1. Path specified with `--config` option
228-
2. `pyproject.toml` in the current directory
229-
3. `pyrefactor.ini` in the current directory
230-
4. Default configuration values
231-
232-
## Integration
128+
## CI/CD Integration
233129

234130
### Pre-commit Hook
235131

236-
Add PyRefactor to your `.pre-commit-config.yaml`:
237-
238132
```yaml
239133
repos:
240134
- repo: local
@@ -247,64 +141,32 @@ repos:
247141
args: [--min-severity=medium]
248142
```
249143
250-
### CI/CD Integration
251-
252-
#### GitHub Actions
144+
### GitHub Actions
253145
254146
```yaml
255147
name: Code Quality
256-
257148
on: [push, pull_request]
258149

259150
jobs:
260151
pyrefactor:
261-
runs-on: windows-latest
152+
runs-on: ubuntu-latest
262153
steps:
263154
- uses: actions/checkout@v3
264-
- name: Set up Python
265-
uses: actions/setup-python@v4
155+
- uses: actions/setup-python@v4
266156
with:
267-
python-version: '3.13'
268-
- name: Install dependencies
269-
run: |
270-
py -m pip install --upgrade pip
271-
py -m pip install pyrefactor
272-
- name: Run PyRefactor
273-
run: pyrefactor --min-severity medium src/
157+
python-version: '3.9'
158+
- run: pip install pyrefactor
159+
- run: pyrefactor --min-severity medium src/
274160
```
275161
276-
## Troubleshooting
277-
278-
### Common Issues
279-
280-
**Issue**: `ModuleNotFoundError: No module named 'pyrefactor'`
281-
282-
**Solution**: Make sure PyRefactor is installed: `py -m pip install -e .`
283-
284-
---
285-
286-
**Issue**: Syntax errors when analyzing Python 3.12 or older code
287-
288-
**Solution**: PyRefactor requires Python 3.13+. Ensure your environment is using Python 3.13 or newer.
289-
290-
---
291-
292-
**Issue**: Analysis is slow on large codebases
293-
294-
**Solution**: Increase the number of parallel workers: `pyrefactor --jobs 8 src/`
295-
296162
## Contributing
297163
298-
Contributions are welcome! Please note that this project is under a Commercial Restricted License (CRL). For commercial use, please contact the copyright holder.
299-
300-
### Guidelines
164+
Contributions are welcome! This project is under a Commercial Restricted License (CRL). For commercial use, contact the copyright holder.
301165
302-
1. Follow the existing code style (Black, isort)
303-
2. Add tests for new features
304-
3. Ensure all tests pass and coverage remains >95%
305-
4. Update documentation as needed
306-
5. Run type checking and linting before submitting
166+
1. Follow existing code style (Black, isort)
167+
2. Add tests for new features (>95% coverage)
168+
3. Run type checking and linting
307169
308170
## License
309171
310-
This project is licensed under the CRL license - see [LICENSE.md](LICENSE.md) for details.
172+
Licensed under the CRL license - see [LICENSE.md](LICENSE.md) for details.

src/pyrefactor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""PyRefactor - A Python refactoring and optimization linter."""
22

3-
__version__ = "1.0.3"
3+
__version__ = "1.0.4"

0 commit comments

Comments
 (0)