Skip to content

Commit 44c8c44

Browse files
niklasmohrinmpsijm
andauthored
RagnarGrootKoerkamp#490 Move mypy config to pyproject.toml and run outside of pre-commit environment (RagnarGrootKoerkamp#493)
* Install mypy environment externally * readme.md: Add instructions to install development dependencies in venv * pyproject.toml: By default, run mypy only on the `bapctools` package --------- Co-authored-by: Maarten Sijm <[email protected]>
1 parent 6dee7ab commit 44c8c44

File tree

4 files changed

+39
-33
lines changed

4 files changed

+39
-33
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
- uses: actions/setup-python@v3
1010
with:
1111
python-version: '3.10'
12+
- run: python3 -m pip install --editable .[types]
1213
- uses: pre-commit/[email protected]
1314

1415
test:

.pre-commit-config.yaml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,12 @@ repos:
1212
- id: ruff
1313
args: [ --fix ]
1414
- id: ruff-format
15-
- repo: https://github.com/pre-commit/mirrors-mypy
16-
rev: v1.15.0
15+
- repo: local
1716
hooks:
1817
- id: mypy
19-
additional_dependencies:
20-
- argcomplete==3.4.0
21-
- matplotlib==3.9.1
22-
- ruamel.yaml==0.18.6
23-
- questionary==2.0.1
24-
- types-colorama==0.4.15.20240311
25-
- types-Pygments==2.18.0.20240506
26-
- types-python-dateutil==2.9.0.20241003
27-
- types-PyYAML==6.0.12.20240311
28-
- types-requests==2.32.0.20240712
29-
args:
30-
- --check-untyped-defs
31-
- --exclude=test
32-
- --enable-error-code=truthy-bool
33-
- --enable-error-code=truthy-iterable
34-
- --no-incremental # Fixes ruamel.yaml, see https://stackoverflow.com/a/65223004
35-
- --python-version=3.10
36-
- --scripts-are-modules
37-
- --strict
18+
name: mypy
19+
entry: mypy
20+
pass_filenames: false
21+
language: system
22+
require_serial: true # don't split filenames into multiple processes
3823
exclude: ^(bapctools/resources|bin/misc|test)/

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ requires-python = ">=3.10"
1515

1616
[project.optional-dependencies]
1717
dev = [
18+
"pre-commit~=4.5.1",
1819
"pytest~=9.0.1",
20+
"bapctools[types]",
21+
]
22+
types = [
23+
"mypy~=1.19",
24+
"types-colorama~=0.4.15",
25+
"types-Pygments~=2.18.0",
26+
"types-python-dateutil~=2.9.0",
27+
"types-PyYAML~=6.0.12",
28+
"types-requests~=2.32.0",
1929
]
2030

2131
[project.scripts]
@@ -39,3 +49,11 @@ order-by-type = false
3949
[tool.pyright]
4050
include = ["bapctools"]
4151
exclude = ["bapctools/resources"]
52+
53+
[tool.mypy]
54+
python_version = "3.10"
55+
packages = "bapctools"
56+
exclude = ["^bapctools/resources/"]
57+
check_untyped_defs = true
58+
enable_error_code="truthy-bool,truthy-iterable"
59+
strict = true

readme.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ time since I'm not aware of usage outside of BAPC yet.
2525
You can install the [bapctools-git AUR package](https://aur.archlinux.org/packages/bapctools-git/),
2626
mirrored [here](https://github.com/RagnarGrootKoerkamp/bapctools-git).
2727
You can also use the [Docker image](#Docker) or install [via Pip (experimental)](#Experimental-Pip-installation).
28+
If you're interested in developing BAPCtools itself, see the installation instructions [at the end of this file](#Developing--Contributing-to-BAPCtools).
2829

2930
Otherwise, clone this repository and install the required dependencies manually.
3031
(If you know how to make a Debian package, feel free to help out.)
@@ -227,17 +228,18 @@ and any hyphens should be replaced with an underscore (e.g., `no_bar: True` rath
227228
These personal config files also allow to set the key `local_time_multiplier` to adjust hardcoded time limits intended for different hardware.
228229
This might be useful for the CI or if your hadware is much faster or slower than the contest hardware.
229230

230-
## Contributing / Style guide
231+
## Developing / Contributing to BAPCtools
231232

232-
- The python code in the repository is formatted using [Ruff](https://github.com/astral-sh/ruff)
233-
and type-checked using [mypy](https://mypy-lang.org/).
234-
To enable the pre-commit hook, install [pre-commit](https://pre-commit.com/)
235-
with `pip` or your package manager (Arch: `python-pre-commit`) and run
236-
`pre-commit install` from the repository root.
237-
All python code will now automatically be formatted on each commit.
238-
If you want to run the hooks before creating a commit,
239-
use `pre-commit run` (only staged files) or `pre-commit run -a` (all files).
233+
The recommended way to install all development dependencies is in a virtual environment,
234+
created with `python3 -m venv venv` and activated with `. venv/bin/activate`.<br />
235+
Install the development dependencies with `pip install --editable .[dev]`.
240236

241-
- Imports are usually ordered with system libraries first, followed by a
242-
newline, followed by local includes. Both groups are sorted alphabetically,
243-
and `import` comes before `from ... import`.
237+
If you want to use your local development version of BAPCtools anywhere, you can create a symlink from any `bin` directory on your `$PATH` to the virtual environment, for example: `ln -s /path/to/BAPCtools/venv/bin/bt ~/bin/bt`
238+
239+
The Python code in the repository is formatted using [Ruff](https://github.com/astral-sh/ruff)
240+
and type-checked using [mypy](https://mypy-lang.org/).
241+
To enable the pre-commit hook,
242+
run `pre-commit install` from the repository root.
243+
All Python code will now automatically be formatted and type-checked on each commit.
244+
If you want to run the hooks before creating a commit,
245+
use `pre-commit run` (only staged files) or `pre-commit run -a` (all files).

0 commit comments

Comments
 (0)