Skip to content

Commit

Permalink
black: Add black to project
Browse files Browse the repository at this point in the history
- Adds a new tox `check-format` command
- Locks black to the last version supporting python 2
- Configures black using pyproject.toml (unfortunately it cannot be
  configured using tox.ini, see psf/black#2172)
  • Loading branch information
evanpurkhiser committed Oct 30, 2024
1 parent 0a75315 commit 4c12a25
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ jobs:
uses: actions/setup-python@v5
with: {python-version: "${{ matrix.python-version }}", cache: pip, cache-dependency-path: 'requirements/*.txt'}
- name: install tests dependencies
run: pip install -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt
run: pip install -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt
- name: run lint
run: tox --current-env -e lint
- name: run format
if: matrix.python-version == '3.13'
# requirements/format.txt is not installed in the `install tests
# dependencies` step since in older python versions there are conflicts.
run: |
pip install -r requirements/format.txt
tox --current-env -e check-format
- name: run tests with coverage
run: tox --current-env -e cov

Expand Down
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ Develop this package
git clone https://github.com/kiorky/croniter.git
cd croniter
virtualenv --no-site-packages venv3
venv3/bin/pip install --upgrade -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt
venv3/bin/pip install --upgrade -r requirements/test.txt -r requirements/lint.txt -r requirements/format.txt -r requirements/tox.txt
venv3/bin/tox --current-env -e lint,test
venv3/bin/black src/


Testing under py2
Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.black]
line-length = 119
target-version = [
# XXX: This project does still support 2.6, but black does not have a 2.6
# target. There should be very few (if any) syntax differences between the
# two versions however.
'py27',
'py34',
'py35',
'py36',
'py37',
'py38',
'py39',
'py310',
# Because we're using an old version of black to support older python, there
# is no explicit python version target past 3.10
]
8 changes: 8 additions & 0 deletions requirements/format.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# We lock to the version just before black 22, as this is when python 2 support
# is dropped.
black==21.11b1

# Lock to an older version of click to fix
# https://github.com/psf/black/issues/2964. This was fixed in a newever version
# of black that we cannot use.
click==8.0.2
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ deps = -r{toxinidir}/requirements/lint.txt
changedir = src
commands = flake8 croniter/croniter.py

[testenv:check-format]
deps = -r{toxinidir}/requirements/format.txt
changedir = src
commands = black --check .

0 comments on commit 4c12a25

Please sign in to comment.