Metadata-Version: 2.3
Name: smart_code
Version: 0.5.0
Summary: Static analysis tool for Python code optimization suggestions
Author: mingchi.sun
Author-email: marshalx9@163.com
Requires-Python: >=3.8
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: libcst
Requires-Dist: mypy
Description-Content-Type: text/markdown

# smart_code

Current version: **0.5.0**

smart_code is a static analysis tool that detects inefficient Python code patterns (AST-based) and provides optimization suggestions. It covers Pandas/NumPy anti-patterns, algorithmic inefficiencies, and common Python pitfalls.

## Features

- **AST-Based Analysis**: Accurately detects code patterns without executing code.
- **Rich Pattern Library**: Covers a wide range of anti-patterns from Pandas usage to algorithmic mistakes.
- **Click-to-Navigate Output**: Terminal output is formatted as `file:line: message`, allowing you to jump directly to the code in modern IDEs (like VS Code or PyCharm).
- **Multi-language Support**: Suggestions can be displayed in English or Chinese.
- **Codemod Refactoring**: Optionally rewrite code in-place using built-in transformations.


## Usage

### Command-Line Interface

Analyze one or more Python files:
```bash
smart_code path/to/your_script.py [another_file.py ...]
```

To receive suggestions in Chinese, use the `--lang zh` flag:
```bash
smart_code path/to/your_script.py --lang en
```

To automatically rewrite files with codemods while still printing the detected issues, add the `--codemod` flag:
```bash
smart_code --codemod your_script.py
```

### Python API

You can also use `smart_code` programmatically in your own scripts.

```python
from smart_code.analyzer import CodeAnalyzer
from smart_code.suggest import format_issue

# Initialize the analyzer in a specific language ('zh' or 'en')
analyzer = CodeAnalyzer(lang='en')

issues = analyzer.analyze_file("script.py")

for issue in issues:
    # Format the output for printing
    formatted_message = format_issue(issue, lang='en')
    print(f"script.py:{issue['lineno']}: {formatted_message}")

# The raw issue dictionary is also available
# print(issues)
```

