From 818493c2cfebf13b6ec4e70cf6319daaa02a67d1 Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Wed, 30 Oct 2024 14:10:08 -0400 Subject: [PATCH] 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 https://github.com/psf/black/issues/2172) --- .github/workflows/cicd.yml | 6 +++++- README.rst | 3 ++- pyproject.toml | 17 +++++++++++++++++ requirements/format.txt | 8 ++++++++ tox.ini | 4 ++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 pyproject.toml create mode 100644 requirements/format.txt diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index fcec0ad..87657f2 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -49,9 +49,13 @@ 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/format.txt -r requirements/tox.txt - name: run lint run: tox --current-env -e lint + - name: run format + # Only run the formatting check on the latest python version. + if: ${{ matrix.python-version == "3.13" }} + run: tox --current-env -e check-format - name: run tests with coverage run: tox --current-env -e cov diff --git a/README.rst b/README.rst index 6877cfd..c72bf4f 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4049fb3 --- /dev/null +++ b/pyproject.toml @@ -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 +] diff --git a/requirements/format.txt b/requirements/format.txt new file mode 100644 index 0000000..1612774 --- /dev/null +++ b/requirements/format.txt @@ -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 diff --git a/tox.ini b/tox.ini index cb9fb2f..9607e07 100644 --- a/tox.ini +++ b/tox.ini @@ -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 src