Skip to content

Commit 1099668

Browse files
author
renaud gaudin
committed
Formatting and repo-management
- added import for `importlib.abc` so it's always found - fixed long string in setup.py so it doesn't need to be excluded - completed and added ranges for the list of dev requirements - added a new `check` command to invoke tasks verifying formatting and linting - fixed import order in test according to black+isort - test workflow to use invoke check instead of duplicating commands - adding coverage reporting to invoke test
1 parent 8dd1e27 commit 1099668

File tree

6 files changed

+47
-44
lines changed

6 files changed

+47
-44
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ env:
55
LIBZIM_VERSION: 2021-10-05
66
LIBZIM_INCLUDE_PATH: include/zim
77
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8-
MAX_LINE_LENGTH: 88
98
PROFILE: 1
109

1110
jobs:
@@ -20,18 +19,11 @@ jobs:
2019
python-version: 3.6
2120
architecture: x64
2221

23-
- name: Autoformat with black
22+
- name: Check formatting and linting
2423
run: |
25-
pip install black
26-
black --check .
27-
28-
- name: Lint with flake8
29-
run: |
30-
pip install flake8
31-
# one pass for show-stopper syntax errors or undefined names
32-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33-
# one pass for small stylistic things
34-
flake8 . --count --max-line-length=$MAX_LINE_LENGTH --statistics
24+
pip install -U invoke
25+
invoke install-dev
26+
invoke check
3527
3628
test:
3729
runs-on: ${{ matrix.os }}

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ pipenv run pip install -e .
3030
### Run Linters & Tests
3131

3232
```bash
33-
# Autoformat code with black
34-
black --exclude=setup.py .
35-
# Lint and check for errors with flake8
36-
flake8 --exclude=setup.py .
33+
# Check format and linting
34+
invoke check
35+
# Autoformat and import sorting
36+
invoke lint
3737
# Typecheck with mypy (optional)
3838
mypy .
3939
# Run tests
40-
pytest .
40+
invoke test
4141
```
4242

4343
### Rebuild Cython extension during development

libzim/libzim.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ cimport zim
3434
import datetime
3535
import enum
3636
import importlib
37+
import importlib.abc
3738
import os
3839
import pathlib
3940
import sys

requirements-dev.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
isort
2-
black
3-
flake8
4-
pytest
1+
isort>=5.9,<6.0
2+
black>=21.9b0,<22.0
3+
flake8>=3.9,<4.0
4+
invoke>=1.5,<2.0
5+
coverage>=5.0,<7.0
6+
pytest>=6.2,<7.0
7+
pytest-cov>=2.10,<4.0
8+
Cython>=0.29.24

setup.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
on environment variables side.
3434
"""
3535

36-
3736
import os
3837
import platform
3938
import sys
4039
from ctypes.util import find_library
4140
from pathlib import Path
42-
from textwrap import dedent
4341

4442
from Cython.Build import cythonize
4543
from Cython.Distutils.build_ext import new_build_ext as build_ext
@@ -83,30 +81,24 @@ def finalize_options(self):
8381
lib_file = base_dir / "lib" / f"libzim.{dyn_lib_ext}"
8482
if header_file.exists() and lib_file.exists():
8583
print(
86-
dedent(
87-
"""\
88-
Found lizim library and headers in local directory.
89-
We will use them to compile python-libzim.
90-
Hint : If you don't want to use them (and use "system" installed one), remove them.
91-
"""
92-
)
84+
"Found lizim library and headers in local directory. "
85+
"We will use them to compile python-libzim.\n"
86+
"Hint : If you don't want to use them "
87+
"(and use “system” installed one), remove them."
9388
)
9489
include_dirs.append("include")
9590
library_dirs = ["lib"]
9691
else:
9792
# Check for library.
9893
if not find_library("zim"):
9994
print(
100-
dedent(
101-
"""\
102-
"[!] The libzim library cannot be found.
103-
"Please verify that the library is correctly installed of and can be found.
104-
"""
105-
)
95+
"[!] The libzim library cannot be found.\n"
96+
"Please verify that the library is correctly installed and can be found."
10697
)
10798
sys.exit(1)
10899
print(
109-
"Using system installed library. We are assuming CFLAGS/LDFLAGS are correctly set."
100+
"Using system installed library. "
101+
"We are assuming CFLAGS/LDFLAGS are correctly set."
110102
)
111103

112104
wrapper_extension = Extension(

tasks.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77

88
from invoke import task
99

10+
MAX_LINE_LENGTH = 88
11+
1012

1113
@task
1214
def build_ext(c):
13-
c.run("python setup.py build_ext -i")
15+
c.run("PROFILE=1 python setup.py build_ext -i")
1416

1517

1618
@task
1719
def test(c):
18-
c.run(f"python -m pytest --color=yes --ff")
20+
c.run(
21+
"python -m pytest --color=yes --ff "
22+
"--cov=libzim --cov-config=.coveragerc "
23+
"--cov-report=term --cov-report term-missing ."
24+
)
1925

2026

2127
@task
@@ -29,17 +35,25 @@ def install_dev(c):
2935
c.run("pip install -r requirements-dev.txt")
3036

3137

38+
@task
39+
def check(c):
40+
c.run("isort --profile=black --check-only .")
41+
c.run("black --check .")
42+
c.run('echo "one pass for show-stopper syntax errors or undefined names"')
43+
c.run("flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics")
44+
c.run('echo "one pass for small stylistic things"')
45+
c.run(f"flake8 . --count --max-line-length={MAX_LINE_LENGTH} --statistics")
46+
47+
3248
@task
3349
def lint(c):
34-
c.run("isort .")
50+
c.run("isort --profile=black .")
3551
c.run("black .")
3652
c.run("flake8 .")
3753

3854

3955
if __name__ == "__main__":
4056
print(
41-
"""\
42-
This file is not intended to be directly run.
43-
Install invoke and run the `invoke` command line.
44-
"""
57+
"This file is not intended to be directly run.\n"
58+
"Install invoke and run the `invoke` command line."
4559
)

0 commit comments

Comments
 (0)