Skip to content

Commit e80f2b5

Browse files
committed
feat: add pre-commit hooks and format codebase
- Add .pre-commit-config.yaml with black, isort, flake8 hooks - Configure black with 89 char line limit to match existing style - Configure isort to be compatible with black - Format entire codebase with black and isort - Fix trailing whitespace and missing newlines - Update CI workflows to use consistent linting - Add pre-commit workflow for automated checks - Add scripts for easy formatting and setup - Update documentation with pre-commit instructions All Python files now follow consistent formatting standards.
1 parent ef62eec commit e80f2b5

87 files changed

Lines changed: 7037 additions & 5372 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
[flake8]
2-
max-line-length = 89
2+
max-line-length = 89
3+
extend-ignore = E203, E266, E501, W503, E402
4+
max-complexity = 10
5+
exclude =
6+
.git,
7+
__pycache__,
8+
docs/source/conf.py,
9+
old,
10+
build,
11+
dist,
12+
.eggs,
13+
*.egg,
14+
work/,
15+
out/
16+
per-file-ignores =
17+
__init__.py:F401,F403
18+
tests/*:F401,F403,E501

.github/CI_CD_SETUP.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# CI/CD Setup for Locator
2+
3+
This repository uses GitHub Actions for continuous integration and deployment.
4+
5+
## Workflows
6+
7+
### 1. Tests (`.github/workflows/test.yml`)
8+
- **Triggers**: Push and pull requests to main/develop branches
9+
- **Python versions**: 3.9, 3.10, 3.11
10+
- **Features**:
11+
- Parallel test execution with pytest-xdist (`-n auto`)
12+
- Coverage reporting with pytest-cov
13+
- CPU-only mode (no GPU required)
14+
- Dependency caching for faster runs
15+
- Code linting with black, isort, and flake8
16+
17+
### 2. Documentation (`.github/workflows/docs.yml`)
18+
- Builds Sphinx documentation
19+
- Checks for documentation warnings
20+
- Uploads built docs as artifacts
21+
22+
### 3. Publishing (`.github/workflows/publish.yml`)
23+
- Triggered on GitHub releases
24+
- Publishes to PyPI and Test PyPI
25+
- Requires secrets: `PYPI_API_TOKEN`, `TEST_PYPI_API_TOKEN`
26+
27+
### 4. Manual Testing (`.github/workflows/manual-test.yml`)
28+
- Allows manual workflow triggers
29+
- Configurable Python version and test patterns
30+
31+
## Local Testing
32+
33+
Run tests locally with parallel execution:
34+
```bash
35+
# Run all tests in parallel
36+
pytest -n auto
37+
38+
# Run with 4 workers
39+
pytest -n 4
40+
41+
# Run without GPU (recommended)
42+
CUDA_VISIBLE_DEVICES=-1 pytest -n auto
43+
44+
# Run specific test file
45+
pytest tests/test_verbosity_control.py -n auto
46+
47+
# Run with coverage
48+
pytest -n auto --cov=locator --cov-report=html
49+
```
50+
51+
## Configuration
52+
53+
- **pytest configuration**: See `pyproject.toml`
54+
- **Coverage settings**: See `pyproject.toml`
55+
- **Dependabot**: See `.github/dependabot.yml`
56+
57+
## Required Secrets (for publishing)
58+
59+
Set these in your GitHub repository settings:
60+
- `CODECOV_TOKEN` (optional, for private repos)
61+
- `PYPI_API_TOKEN` (for PyPI publishing)
62+
- `TEST_PYPI_API_TOKEN` (for Test PyPI publishing)
63+
64+
## Status Badges
65+
66+
Add these to your README.md:
67+
```markdown
68+
[![Tests](https://github.com/YOUR_USERNAME/relocator/actions/workflows/test.yml/badge.svg)](https://github.com/YOUR_USERNAME/relocator/actions/workflows/test.yml)
69+
[![codecov](https://codecov.io/gh/YOUR_USERNAME/relocator/branch/main/graph/badge.svg)](https://codecov.io/gh/YOUR_USERNAME/relocator)
70+
```

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ If applicable, paste the full error traceback here.
4141
- CUDA/GPU info (if relevant): [e.g. CUDA 12.1, RTX 4090]
4242

4343
**Additional context**
44-
Add any other context about the problem here.
44+
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ import locator
2727
```
2828

2929
**Additional context**
30-
Add any other context or screenshots about the feature request here.
30+
Add any other context or screenshots about the feature request here.

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ updates:
3333
- "adkern"
3434
labels:
3535
- "dependencies"
36-
- "github-actions"
36+
- "github-actions"

.github/pull_request_template.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Description
2+
3+
Please include a summary of the changes and which issue is fixed. Include relevant motivation and context.
4+
5+
Fixes #(issue)
6+
7+
## Type of change
8+
9+
Please delete options that are not relevant.
10+
11+
- [ ] Bug fix (non-breaking change which fixes an issue)
12+
- [ ] New feature (non-breaking change which adds functionality)
13+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14+
- [ ] Documentation update
15+
- [ ] Performance improvement
16+
- [ ] Code refactoring
17+
18+
## How Has This Been Tested?
19+
20+
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
21+
22+
- [ ] Test A
23+
- [ ] Test B
24+
25+
**Test Configuration**:
26+
* Python version:
27+
* TensorFlow version:
28+
* Operating System:
29+
30+
## Checklist:
31+
32+
- [ ] My code follows the style guidelines of this project
33+
- [ ] I have performed a self-review of my own code
34+
- [ ] I have commented my code, particularly in hard-to-understand areas
35+
- [ ] I have made corresponding changes to the documentation
36+
- [ ] My changes generate no new warnings
37+
- [ ] I have added tests that prove my fix is effective or that my feature works
38+
- [ ] New and existing unit tests pass locally with my changes
39+
- [ ] Any dependent changes have been merged and published in downstream modules

.github/workflows/badges.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Add these badges to your README.md:
99
```
1010

1111
Replace YOUR_USERNAME with your GitHub username or organization name.
12-
EOF < /dev/null
12+
EOF < /dev/null

.github/workflows/docs.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ on:
99
jobs:
1010
build-docs:
1111
runs-on: ubuntu-latest
12-
12+
1313
steps:
1414
- uses: actions/checkout@v4
15-
15+
1616
- name: Set up Python
1717
uses: actions/setup-python@v5
1818
with:
1919
python-version: "3.11"
20-
20+
2121
- name: Cache pip packages
2222
uses: actions/cache@v4
2323
with:
@@ -26,37 +26,37 @@ jobs:
2626
restore-keys: |
2727
${{ runner.os }}-pip-docs-
2828
${{ runner.os }}-pip-
29-
29+
3030
- name: Install system dependencies
3131
run: |
3232
sudo apt-get update
3333
sudo apt-get install -y libproj-dev proj-data proj-bin libgeos-dev
3434
sudo apt-get install -y pandoc
35-
35+
3636
- name: Install package with docs dependencies
3737
env:
3838
CUDA_VISIBLE_DEVICES: "-1"
3939
run: |
4040
python -m pip install --upgrade pip
4141
pip install wheel
4242
pip install -e ".[docs]"
43-
43+
4444
- name: Build documentation
4545
run: |
4646
cd docs
4747
make clean
4848
make html
49-
49+
5050
- name: Check for documentation warnings
5151
run: |
5252
cd docs
5353
if make html 2>&1 | grep -i "warning"; then
5454
echo "Documentation build produced warnings"
5555
exit 1
5656
fi
57-
57+
5858
- name: Upload documentation artifacts
5959
uses: actions/upload-artifact@v4
6060
with:
6161
name: documentation
62-
path: docs/_build/html/
62+
path: docs/_build/html/

.github/workflows/manual-test.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ on:
2626
jobs:
2727
manual-test:
2828
runs-on: ubuntu-latest
29-
29+
3030
steps:
3131
- uses: actions/checkout@v4
32-
32+
3333
- name: Set up Python ${{ inputs.python-version }}
3434
uses: actions/setup-python@v5
3535
with:
3636
python-version: ${{ inputs.python-version }}
37-
37+
3838
- name: Cache pip packages
3939
uses: actions/cache@v4
4040
with:
@@ -43,20 +43,20 @@ jobs:
4343
restore-keys: |
4444
${{ runner.os }}-pip-${{ inputs.python-version }}-
4545
${{ runner.os }}-pip-
46-
46+
4747
- name: Install system dependencies
4848
run: |
4949
sudo apt-get update
5050
sudo apt-get install -y libproj-dev proj-data proj-bin libgeos-dev
51-
51+
5252
- name: Install package and dependencies
5353
env:
5454
CUDA_VISIBLE_DEVICES: "-1"
5555
run: |
5656
python -m pip install --upgrade pip
5757
pip install wheel
5858
pip install -e ".[dev]"
59-
59+
6060
- name: Show environment info
6161
run: |
6262
echo "Python version: $(python --version)"
@@ -67,7 +67,7 @@ jobs:
6767
echo "TensorFlow info:"
6868
python -c "import tensorflow as tf; print(f'TensorFlow version: {tf.__version__}')"
6969
python -c "import tensorflow as tf; print(f'GPU available: {tf.config.list_physical_devices(\"GPU\")}')"
70-
70+
7171
- name: Run specific tests
7272
if: inputs.test-pattern != ''
7373
env:
@@ -79,7 +79,7 @@ jobs:
7979
else
8080
pytest -n auto tests/${{ inputs.test-pattern }}
8181
fi
82-
82+
8383
- name: Run all tests
8484
if: inputs.test-pattern == ''
8585
env:
@@ -90,4 +90,4 @@ jobs:
9090
pytest -v -n auto --cov=locator --cov-report=xml --cov-report=term-missing
9191
else
9292
pytest -n auto --cov=locator --cov-report=xml --cov-report=term-missing
93-
fi
93+
fi

.github/workflows/pre-commit.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Pre-commit
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.11"
20+
21+
- name: Cache pre-commit environments
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.cache/pre-commit
25+
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
26+
restore-keys: |
27+
pre-commit-${{ runner.os }}-
28+
29+
- name: Install pre-commit
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install pre-commit
33+
34+
- name: Run pre-commit on all files
35+
run: |
36+
pre-commit run --all-files --show-diff-on-failure --color=always
37+
continue-on-error: true
38+
39+
- name: Comment PR on failure
40+
if: failure() && github.event_name == 'pull_request'
41+
uses: actions/github-script@v7
42+
with:
43+
script: |
44+
github.rest.issues.createComment({
45+
issue_number: context.issue.number,
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
body: '❌ Pre-commit checks failed. Please run `pre-commit run --all-files` locally and commit the changes.'
49+
})

0 commit comments

Comments
 (0)