Skip to content

Commit 7e861a6

Browse files
committed
black: Add black to project
- Adds a new tox `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)
1 parent d7507bf commit 7e861a6

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

.github/workflows/cicd.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ jobs:
4949
uses: actions/setup-python@v5
5050
with: {python-version: "${{ matrix.python-version }}", cache: pip, cache-dependency-path: 'requirements/*.txt'}
5151
- name: install tests dependencies
52-
run: pip install -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt
52+
run: pip install -r requirements/test.txt -r requirements/lint.txt -r requirements/format.txt -r requirements/tox.txt
5353
- name: run lint
5454
run: tox --current-env -e lint
55+
- name: run format
56+
# Only run the formatting check on the latest python version.
57+
if: ${{ matrix.python-version == "3.13" }}
58+
run: tox --current-env -e format
5559
- name: run tests with coverage
5660
run: tox --current-env -e cov
5761

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ Develop this package
340340
git clone https://github.com/kiorky/croniter.git
341341
cd croniter
342342
virtualenv --no-site-packages venv3
343-
venv3/bin/pip install --upgrade -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt
344-
venv3/bin/tox --current-env -e lint,test
343+
venv3/bin/pip install --upgrade -r requirements/test.txt -r requirements/lint.txt -r requirements/format.txt -r requirements/tox.txt
344+
venv3/bin/tox --current-env -e lint,format,test
345345

346346

347347
Testing under py2

pyproject.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tool.black]
2+
line-lenghth = 100
3+
target-version = [
4+
# XXX: This project does still support 2.6, but black does not have a 2.6
5+
# target. There should be very few (if any) syntax differences between the
6+
# two versions however.
7+
'py27',
8+
'py34',
9+
'py35',
10+
'py36',
11+
'py37',
12+
'py38',
13+
'py39',
14+
'py310',
15+
# Because we're using an old version of black to support older python, there
16+
# is no explicit python version target past 3.10
17+
]

requirements/format.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# We lock to the version just before black 22, as this is when python 2 support
2+
# is dropped.
3+
black==21.11b1
4+
5+
# Lock to an older version of click to fix
6+
# https://github.com/psf/black/issues/2964. This was fixed in a newever version
7+
# of black that we cannot use.
8+
click==8.0.2

tox.ini

+4
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ deps = -r{toxinidir}/requirements/lint.txt
1717
changedir = src
1818
commands = flake8 croniter/croniter.py
1919

20+
[testenv:format]
21+
deps = -r{toxinidir}/requirements/format.txt
22+
changedir = src
23+
commands = black src

0 commit comments

Comments
 (0)