Skip to content

Commit 7c0fee0

Browse files
authored
Add ruff for lint/format (#52)
* Add ruff for lint/format * remove make * use poetry * coverage to xml
1 parent 43b37e1 commit 7c0fee0

30 files changed

+1579
-609
lines changed

.devcontainer.json

+45-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
11
{
22
"name": "pytraccar",
3-
"image": "mcr.microsoft.com/vscode/devcontainers/python:0-3.11",
4-
"postCreateCommand": "make requirements",
53
"customizations": {
64
"vscode": {
75
"settings": {
8-
"python.defaultInterpreterPath": "/usr/local/bin/python",
6+
"[python]": {
7+
"editor.codeActionsOnSave": {
8+
"source.fixAll": "always",
9+
"source.organizeImports": "always"
10+
},
11+
"editor.formatOnSave": true,
12+
"editor.defaultFormatter": "charliermarsh.ruff"
13+
},
14+
"coverage-gutters.customizable.context-menu": true,
15+
"coverage-gutters.customizable.status-bar-toggler-watchCoverageAndVisibleEditors-enabled": true,
16+
"coverage-gutters.showGutterCoverage": false,
17+
"coverage-gutters.showLineCoverage": true,
18+
"coverage-gutters.xmlname": "coverage.xml",
19+
"python.analysis.extraPaths": [
20+
"${workspaceFolder}/src"
21+
],
22+
"python.formatting.provider": "ruff format",
923
"python.linting.enabled": true,
10-
"python.linting.pylintEnabled": true,
11-
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
12-
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
13-
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
14-
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
15-
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
16-
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
17-
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
18-
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
19-
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
20-
},
21-
"extensions": [
22-
"ms-python.python",
23-
"ms-python.vscode-pylance",
24-
"GitHub.copilot"
25-
]
24+
"python.linting.mypyEnabled": true,
25+
"python.testing.cwd": "${workspaceFolder}",
26+
"python.testing.pytestArgs": [
27+
"--cov-report=xml"
28+
],
29+
"python.testing.pytestEnabled": true,
30+
"ruff.importStrategy": "fromEnvironment",
31+
"terminal.integrated.defaultProfile.linux": "zsh",
32+
"extensions": [
33+
"be5invis.toml",
34+
"GitHub.copilot",
35+
"ms-python.python",
36+
"charliermarsh.ruff",
37+
"ms-python.vscode-pylance",
38+
"ryanluker.vscode-coverage-gutters"
39+
]
40+
}
2641
}
27-
}
28-
}
42+
},
43+
"features": {
44+
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
45+
"ghcr.io/devcontainers/features/python:1": {
46+
"installTools": false,
47+
"version": "3.11"
48+
}
49+
},
50+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
51+
"updateContentCommand": "poetry install && poetry run pre-commit install"
52+
}

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=auto eol=lf
1+
* text=auto eol=lf

.github/ISSUE_TEMPLATE/feature_request.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ A clear and concise description of what you want to happen.
1414
A clear and concise description of any alternative solutions or features you've considered.
1515

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

.github/ISSUE_TEMPLATE/issue.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ A clear and concise description of what the bug is.
1010
**log**
1111
```
1212
Add your logs here.
13-
```
13+
```

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ updates:
1212
schedule:
1313
interval: daily
1414
time: "06:00"
15-
open-pull-requests-limit: 10
15+
open-pull-requests-limit: 10

.github/workflows/actions.yml

+29-26
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@ jobs:
1313
name: Lint
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: 📥 Checkout the repository
16+
- name: Checkout the repository
1717
uses: actions/[email protected]
1818

19-
- name: 🛠 Set up Python 3
19+
- name: Set up Python 3.11
2020
uses: actions/[email protected]
2121
with:
2222
python-version: "3.11"
2323

24-
- name: 📦 Install dependencies
25-
run: make requirements
24+
- name: Install poetry
25+
run: pipx install poetry
2626

27-
- name: 🖤 Lint with Black
28-
run: make black-check
27+
- name: install dependencies
28+
run: poetry install
2929

30-
- name: 🔤 Lint with isort
31-
run: make isort-check
32-
33-
- name: 🔢 Lint with mypy
34-
run: make mypy
30+
- name: Lint/test with pre-commit
31+
run: poetry run pre-commit run --all-files
3532

3633
test:
3734
name: Test with Python ${{ matrix.python-version }}
@@ -43,44 +40,50 @@ jobs:
4340
- "3.11"
4441
- "3.12"
4542
steps:
46-
- name: 📥 Checkout the repository
43+
- name: Checkout the repository
4744
uses: actions/[email protected]
4845
with:
4946
fetch-depth: 0
5047

51-
- name: 🛠️ Set up Python ${{ matrix.python-version }}
48+
- name: Set up Python ${{ matrix.python-version }}
5249
uses: actions/[email protected]
5350
with:
5451
python-version: ${{ matrix.python-version }}
5552

56-
- name: 📦 Install dependencies
57-
run: make requirements
53+
- name: Install poetry
54+
run: pipx install poetry
55+
56+
- name: install dependencies
57+
run: poetry install
5858

59-
- name: 🏃 Run tests
60-
run: make test
59+
- name: Run tests
60+
run: poetry run pytest
6161

62-
- name: 🛠 Build
63-
run: make build
62+
- name: Build
63+
run: poetry build
6464

6565
coverage:
6666
name: Coverage
6767
needs: test
6868
runs-on: ubuntu-latest
6969
steps:
70-
- name: 📥 Checkout the repository
70+
- name: Checkout the repository
7171
uses: actions/[email protected]
7272
with:
7373
fetch-depth: 0
7474

75-
- name: 🛠 Set up Python 3
75+
- name: Set up Python 3.11
7676
uses: actions/[email protected]
7777
with:
7878
python-version: "3.11"
7979

80-
- name: 📦 Install dependencies
81-
run: make requirements
80+
- name: Install poetry
81+
run: pipx install poetry
82+
83+
- name: install dependencies
84+
run: poetry install
8285

83-
- name: 📤 Upload coverage to Codecov
86+
- name: Upload coverage to Codecov
8487
run: |
85-
make coverage
86-
curl -sfSL https://codecov.io/bash | bash -
88+
poetry run pytest --cov --cov-report=xml
89+
curl -sfSL https://codecov.io/bash | bash -

.github/workflows/release.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ jobs:
1111
runs-on: ubuntu-latest
1212
name: Deploy to PyPi
1313
steps:
14-
- name: 📥 Checkout the repository
14+
- name: Checkout the repository
1515
uses: actions/[email protected]
1616

17-
- name: 🛠 Set up Python
17+
- name: Set up Python 3.11
1818
uses: actions/[email protected]
1919
with:
2020
python-version: "3.11"
2121

22-
- name: 📦 Install poetry
23-
run: make install-poetry
22+
- name: Install poetry
23+
run: pipx install poetry
2424

25-
- name: 🔢 Set version number
25+
- name: install dependencies
26+
run: poetry install
27+
28+
- name: Set version number
2629
run: poetry version "${{ github.event.release.tag_name }}"
2730

28-
- name: 🚀 Publish to PyPi
31+
- name: Publish to PyPi
2932
env:
3033
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
31-
run: poetry publish --build --no-interaction
34+
run: poetry publish --build --no-interaction

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ coverage.xml
77
example.py
88
dist
99
.mypy_cache
10-
.pytest_cache
10+
.pytest_cache
11+
.ruff_cache
12+
.venv

.pre-commit-config.yaml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
repos:
3+
- repo: local
4+
hooks:
5+
- id: ruff-check
6+
name: Ruff Linter
7+
language: system
8+
types: [python]
9+
entry: poetry run ruff check --fix
10+
require_serial: true
11+
stages: [commit, push, manual]
12+
exclude: ^tests|example\.py$
13+
- id: ruff-format
14+
name: Ruff Formatter
15+
language: system
16+
types: [python]
17+
entry: poetry run ruff format
18+
require_serial: true
19+
stages: [commit, push, manual]
20+
- id: check-ast
21+
name: Check Python AST
22+
language: system
23+
types: [python]
24+
entry: poetry run check-ast
25+
- id: check-case-conflict
26+
name: Check for case conflicts
27+
language: system
28+
entry: poetry run check-case-conflict
29+
- id: check-docstring-first
30+
name: Check docstring is first
31+
language: system
32+
types: [python]
33+
entry: poetry run check-docstring-first
34+
- id: check-json
35+
name: Check JSON files
36+
language: system
37+
types: [json]
38+
entry: poetry run check-json
39+
- id: check-toml
40+
name: Check TOML files
41+
language: system
42+
types: [toml]
43+
entry: poetry run check-toml
44+
- id: check-xml
45+
name: Check code for common misspellings
46+
language: system
47+
types: [text]
48+
exclude: ^poetry\.lock$
49+
entry: poetry run codespell
50+
- id: detect-private-key
51+
name: Detect Private Keys
52+
language: system
53+
types: [text]
54+
entry: poetry run detect-private-key
55+
- id: end-of-file-fixer
56+
name: Fix End of Files
57+
language: system
58+
types: [text]
59+
entry: poetry run end-of-file-fixer
60+
stages: [commit, push, manual]
61+
- id: mypy
62+
name: Static type checking using mypy
63+
language: system
64+
types: [python]
65+
pass_filenames: false
66+
entry: poetry run mypy pytraccar
67+
require_serial: true
68+
- id: poetry
69+
name: Check pyproject with Poetry
70+
language: system
71+
entry: poetry check
72+
pass_filenames: false
73+
always_run: true
74+
- id: pytest
75+
name: Running tests and test coverage with pytest
76+
language: system
77+
types: [python]
78+
entry: poetry run pytest --cov pytraccar tests
79+
pass_filenames: false
80+
- id: trailing-whitespace
81+
name: Trim Trailing Whitespace
82+
language: system
83+
types: [text]
84+
entry: poetry run trailing-whitespace-fixer
85+
stages: [commit, push, manual]

Makefile

-43
This file was deleted.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Look at the file `example.py` for a usage example.
2222
1. Fork the repository
2323
2. Clone the repository locally and open the devcontainer or use GitHub codespaces
2424
3. Do your changes
25-
4. Lint the files with `make lint`
26-
5. Ensure all tests passes with `make test`
27-
6. Ensure 100% coverage with `make coverage`
25+
4. Lint the files with `poetry run ruff check --fix pytraccar`
26+
5. Format the files with `poetry run ruff format`
27+
6. Ensure all tests passes and coverage is still at 100% with `poetry run pytest --cov`
2828
7. Commit your work, and push it to GitHub
2929
8. Create a PR against the `main` branch

example.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pytraccar import ApiClient
77

88

9-
109
async def test():
1110
"""Example usage of pytraccar."""
1211
async with aiohttp.ClientSession() as client_session:

0 commit comments

Comments
 (0)