Skip to content

Commit 6e17b4a

Browse files
nikolay-eclaude
andcommitted
chore: Set up pre-commit hooks and fix linting issues
- Add pre-commit configuration with black, flake8, autoflake, mypy - Fix trailing whitespace and end-of-file issues across all files - Fix mypy error in tests/utils.py by handling return statements - Format code with black for consistency - All linting checks now pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e938784 commit 6e17b4a

File tree

14 files changed

+120
-91
lines changed

14 files changed

+120
-91
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,4 @@ jobs:
217217
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
218218
echo "Attempting to merge tag ${{ needs.prepare-release.outputs.tag_name }} into main"
219219
git merge ${{ needs.prepare-release.outputs.tag_name }} --no-ff -m "Merge tag ${{ needs.prepare-release.outputs.tag_name }} into main"
220-
git push origin main
220+
git push origin main

.github/workflows/ci.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
- main
1313

1414
jobs:
15-
15+
1616
lint-type-check:
1717
name: Lint & Type Check
1818
runs-on: ubuntu-latest
@@ -28,7 +28,7 @@ jobs:
2828
- name: Cache pip Dependencies
2929
uses: actions/cache@v4
3030
with:
31-
31+
3232
path: ~/.cache/pip
3333
key: ${{ runner.os }}-lint-pip-${{ hashFiles('**/pyproject.toml') }}
3434
restore-keys: |
@@ -37,9 +37,9 @@ jobs:
3737
- name: Install Linters and Type Checker
3838
run: |
3939
python -m pip install --upgrade pip
40-
40+
4141
pip install .[dev]
42-
42+
4343
4444
- name: Run Linters and Formatters Check
4545
run: |
@@ -48,10 +48,10 @@ jobs:
4848
4949
- name: Run Type Checker (Mypy)
5050
run: |
51-
51+
5252
mypy src tests
5353
54-
54+
5555
test:
5656
needs: lint-type-check
5757
strategy:
@@ -61,7 +61,7 @@ jobs:
6161
python-version: [ 3.9, '3.10', '3.11', '3.12' ]
6262

6363
runs-on: ${{ matrix.os }}
64-
64+
6565

6666
steps:
6767
- name: Checkout Code
@@ -76,7 +76,7 @@ jobs:
7676
uses: actions/cache@v4
7777
with:
7878
path: ~/.cache/pip
79-
79+
8080
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
8181
restore-keys: |
8282
${{ runner.os }}-pip-${{ matrix.python-version }}-
@@ -85,36 +85,36 @@ jobs:
8585
- name: Install Dependencies
8686
run: |
8787
python -m pip install --upgrade pip
88-
88+
8989
pip install -e .[dev]
9090
91-
91+
9292
9393
- name: Run Tests with Coverage
9494
run: |
95-
95+
9696
pytest -v --cov=src/treemapper --cov-report=xml
9797
9898
- name: Upload coverage reports to Codecov
99-
99+
100100
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
101101
uses: codecov/codecov-action@v5
102-
103-
104-
102+
103+
104+
105105
with:
106106
files: ./coverage.xml
107107
fail_ci_if_error: true
108108
verbose: true
109109

110-
110+
111111
test-pypy:
112112
needs: lint-type-check
113113
runs-on: ubuntu-latest
114114
strategy:
115115
fail-fast: false
116116
matrix:
117-
117+
118118
python-version: [ pypy-3.9, pypy-3.10 ]
119119

120120
steps:
@@ -137,12 +137,12 @@ jobs:
137137
- name: Install Dependencies
138138
run: |
139139
python -m pip install --upgrade pip
140-
140+
141141
pip install -e .[dev]
142-
143142
144-
143+
144+
145145
146146
- name: Run Tests
147147
run: |
148-
pytest -v
148+
pytest -v

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-merge-conflict
10+
- id: debug-statements
11+
12+
- repo: https://github.com/psf/black
13+
rev: 23.12.1
14+
hooks:
15+
- id: black
16+
language_version: python3
17+
18+
- repo: https://github.com/pycqa/flake8
19+
rev: 7.0.0
20+
hooks:
21+
- id: flake8
22+
args: ['--config=.flake8']
23+
24+
- repo: https://github.com/pycqa/autoflake
25+
rev: v2.2.1
26+
hooks:
27+
- id: autoflake
28+
args: ['--remove-all-unused-imports', '--in-place']
29+
30+
- repo: https://github.com/pre-commit/mirrors-mypy
31+
rev: v1.8.0
32+
hooks:
33+
- id: mypy
34+
additional_dependencies: [types-PyYAML]
35+
args: ['--ignore-missing-imports']

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
### Reliability Improvements
1919
- **Enhanced file permission handling**: Improved handling of permission-related errors for unreadable files and directories.
2020
- **Added WSL compatibility**: Added special handling for permission-related tests in Windows Subsystem for Linux (WSL) environments.
21-
- **Reduced verbosity**: Changed default verbosity level from INFO to ERROR to minimize console output unless errors occur.
21+
- **Reduced verbosity**: Changed default verbosity level from INFO to ERROR to minimize console output unless errors occur.

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ python -m build
111111

112112
# Create executable with PyInstaller
113113
pyinstaller treemapper.spec
114-
```
114+
```

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ A tool for converting directory structures to YAML format, designed for use with
44
TreeMapper maps your entire codebase into a structured YAML file, making it easy to analyze code, document projects, and
55
work with AI tools.
66

7-
[![Build Status](https://img.shields.io/github/actions/workflow/status/nikolay-e/TreeMapper/ci.yml)](https://github.com/nikolay-e/TreeMapper/actions)
8-
[![PyPI](https://img.shields.io/pypi/v/treemapper)](https://pypi.org/project/treemapper)
7+
[![Build Status](https://img.shields.io/github/actions/workflow/status/nikolay-e/TreeMapper/ci.yml)](https://github.com/nikolay-e/TreeMapper/actions)
8+
[![PyPI](https://img.shields.io/pypi/v/treemapper)](https://pypi.org/project/treemapper)
99
[![License](https://img.shields.io/github/license/nikolay-e/TreeMapper)](https://github.com/nikolay-e/TreeMapper/blob/main/LICENSE)
1010

1111
## Installation
@@ -22,7 +22,7 @@ Generate a YAML tree of a directory:
2222

2323
```bash
2424
# Map current directory
25-
treemapper .
25+
treemapper .
2626

2727
# Map specific directory
2828
treemapper /path/to/dir
@@ -88,4 +88,4 @@ children:
8888
8989
## License
9090
91-
Apache License 2.0 - see [LICENSE](LICENSE) for details.
91+
Apache License 2.0 - see [LICENSE](LICENSE) for details.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# setup.cfg
22

33
[flake8]
4-
max-line-length = 130
4+
max-line-length = 130

src/treemapper/tree.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ def create_node(
154154
if children:
155155
node["children"] = children
156156
elif node_type == "file":
157-
158157
node_content: Optional[str] = None
159158
try:
160159
# Try to read the file directly, and handle all possible errors

tests/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,14 @@ def _set_perms(path: Path, perms: int):
9292

9393
logging.debug(f"Cleaning up permissions for: {paths_changed}")
9494
for path in paths_changed:
95-
9695
if path.exists() and path in original_perms:
9796
try:
98-
9997
if original_perms[path] is not None:
10098
os.chmod(path, original_perms[path])
10199
logging.debug(f"Restored permissions for {path}")
102100
else:
103101
logging.warning(f"Original permissions for {path} were None, not restoring.")
104102
except OSError as e:
105-
106103
logging.warning(f"Could not restore permissions for {path}: {e}")
107104

108105

tests/test_errors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def test_output_path_is_directory(temp_project, run_mapper, caplog):
8989
output_should_be_file.mkdir()
9090

9191
with caplog.at_level(logging.ERROR):
92-
9392
run_mapper([".", "-o", str(output_should_be_file)])
9493

9594
assert any(

0 commit comments

Comments
 (0)