Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default setup for linting and reformatting Darker itself #552

Merged
merged 7 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/darker-black-isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: darker-black-isort

on: push # yamllint disable-line rule:truthy

jobs:
reformat-modified:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Reformat code using own GitHub action straight from the repository
uses: ./
with:
options: --check --diff --color --isort
src: action release_tools setup.py src/darker
revision: origin/master...
version: "@${{ github.ref_name }}"
4 changes: 2 additions & 2 deletions .github/workflows/darker-flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
- name: Run Darker's own GitHub action straight from the repository
uses: ./
with:
options: --check --diff --color --isort --config pyproject.toml
src: src/darker
options: --check --diff --color
src: action release_tools setup.py src/darker
revision: origin/master...
lint: flake8
version: "@${{ github.ref_name }}"
14 changes: 3 additions & 11 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ jobs:
--run '
python -m venv venv
source venv/bin/activate
cert_file=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
export NIX_SSL_CERT_FILE=$cert_file
pip install "${{needs.build-wheel.outputs.wheel-path}}[test]"
# Run tests in installed package to avoid plugin import issue:
pytest $(python -c "
Expand Down Expand Up @@ -127,17 +129,7 @@ jobs:
if: matrix.constraints == '--constraint constraints-oldest.txt'
run: |
sed -i 's/py311/py39/' pyproject.toml
- name: Run Pytest with the Darker plugin on recent Black versions
if: matrix.constraints != '--constraint constraints-oldest.txt'
run: |
pytest --darker
- name: Run Pytest without the Darker plugin on oldest Black version
# The reformatting rules used to be a bit different. We don't need to
# test reformatting Darker's own code base with old Black versions.
# Interoperability is ensured by unit tests.
if: matrix.constraints == '--constraint constraints-oldest.txt'
run: |
pytest
- run: pytest

build-sdist-validate-dists:
runs-on: ubuntu-latest
Expand Down
96 changes: 59 additions & 37 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,40 @@ These features will be included in the next release:

Added
-----
- The command ``darker --config=check-darker.toml`` now runs Flake8_, Mypy_,
pydocstyle_, Pylint_ and Ruff_ on modified lines in Python files. Those tools are
included in the ``[test]`` extra.
- The minimum Ruff_ version is now 0.0.292. Its configuration in ``pyproject.toml`` has
been updated accordingly.
- The contribution guide now gives better instructions for reformatting and linting.
- Separate GitHub workflow for checking code formatting and import sorting.
- Also check the action, release tools and ``setup.py`` in the build workflows.

Removed
-------
- Don't run pytest-darker_ in the CI build. It's lagging quite a bit behind.

Fixed
-----
- Black 24.2.0 compatibility by using the new `darkgraylib.files.find_project_root`
- `Black 24.2.0`_ compatibility by using the new `darkgraylib.files.find_project_root`
instead of the implementation in Black.
- Black 24.2.1 compatibility by detecting the new `black.parsing.ASTSafetyError` instead
- `Black 24.2.1`_ compatibility by detecting the new `black.parsing.ASTSafetyError` instead
of `AssertionError` when Black>=24.2.1 is in use.
- Make sure NixOS_ builds have good SSL certificates installed.


1.7.3_ - 2024-02-27
===================

Added
-----
- Limit Black to versions before 24.2 until the incompatibility is resolved.
- Limit Black_ to versions before 24.2 until the incompatibility is resolved.
- Stop testing on Python 3.7. Note: dropping support to be done in a separate PR.

Fixed
-----
- Typos in README.
- Usage of the Black ``gen_python_files(gitignore_dict=...)`` parameter.
- Usage of the Black_ ``gen_python_files(gitignore_dict=...)`` parameter.
- ``show_capture`` option in Pytest configuration.
- Ignore some linter messages by recent versions of linters used in CI builds.
- Fix compatibility with Pygments 2.4.0 and 2.17.2 in unit tests.
Expand All @@ -39,8 +52,8 @@ Added
-----
- Add a ``News`` link on the PyPI page.
- Allow ``-`` as the single source filename when using the ``--stdin-filename`` option.
This makes the option compatible with Black.
- Upgrade NixOS tests to use Python 3.11 on both Linux and macOS.
This makes the option compatible with Black_.
- Upgrade NixOS_ tests to use Python 3.11 on both Linux and macOS.
- Move ``git_repo`` fixture to ``darkgraylib``.
- In CI builds, show a diff of changed ``--help`` output if ``README.rst`` is outdated.

Expand All @@ -51,10 +64,10 @@ Fixed
- Python 3.12 compatibility in multi-line string scanning.
- Python 3.12 compatibility for the GitHub Action.
- Use the original repository working directory name as the name of the temporary
directory for getting the linter baseline. This avoids issues with Mypy when there's
directory for getting the linter baseline. This avoids issues with Mypy_ when there's
an ``__init__.py`` in the repository root.
- Upgrade ``install-nix-action`` to version 22 in CI to fix an issue with macOS.
- Allow ``--target-version=py312`` since newest Black supports it.
- Allow ``--target-version=py312`` since newest Black_ supports it.
- Allow a comment in milestone titles in the ``bump_version`` script.


Expand All @@ -74,8 +87,8 @@ Fixed
- In CI builds, run the ``commit-range`` action from the current checkout instead of
pointing to a release tag. This fixes workflows when in a release branch.
- Linting fixes: Use ``stacklevel=2`` in ``warnings.warn()`` calls as suggested by
Flake8; skip Bandit check for virtualenv creation in the GitHub Action;
use ``ignore[method-assign]`` as suggested by Mypy.
Flake8_; skip Bandit check for virtualenv creation in the GitHub Action;
use ``ignore[method-assign]`` as suggested by Mypy_.
- Configuration options spelled with hyphens in ``pyproject.toml``
(e.g. ``line-length = 88``) are now supported.
- In debug log output mode, configuration options are now always spelled with hyphens
Expand All @@ -92,7 +105,7 @@ Added
- Make unit tests compatible with ``pytest --log-cli-level==DEBUG``.
Doctests are still incompatible due to
`pytest#5908 <https://github.com/pytest-dev/pytest/issues/5908>`_.
- Black's ``target-version =`` configuration file option and ``-t`` /
- Black_'s ``target-version =`` configuration file option and ``-t`` /
``--target-version`` command line option
- In ``README.rst``, link to GitHub searches which find public repositories that
use Darker.
Expand All @@ -109,7 +122,7 @@ Added
Fixed
-----
- Compatibility of highlighting unit tests with Pygments 2.14.0.
- In the CI test workflow, don't use environment variables to add a Black version
- In the CI test workflow, don't use environment variables to add a Black_ version
constraint to the ``pip`` command. This fixes the Windows builds.
- Pass Git errors to stderr correctly both in raw and encoded subprocess output mode.
- Add a work-around for cleaning up temporary directories. Needed for Python 3.7 on
Expand All @@ -119,7 +132,7 @@ Fixed
- Configure ``coverage`` to use relative paths in the Darker repository. This enables
use of ``cov_to_lint.py``
- Satisfy Pylint's ``use-dict-literal`` check in Darker's code base.
- Use ``!r`` to quote values in format strings as suggested by recent Flake8 versions.
- Use ``!r`` to quote values in format strings as suggested by recent Flake8_ versions.


1.6.1_ - 2022-12-28
Expand All @@ -135,7 +148,7 @@ Added

Fixed
-----
- Pin Black to version 22.12.0 in the CI build to ensure consistent formatting of
- Pin Black_ to version 22.12.0 in the CI build to ensure consistent formatting of
Darker's own code base.
- Fix compatibility with ``black-22.10.1.dev19+gffaaf48`` and later – an argument was
replaced in ``black.files.gen_python_files()``.
Expand Down Expand Up @@ -176,7 +189,7 @@ Added
- Only run linters, security checks and package builds once in the CI build.
- Small simplification: It doesn't matter whether ``isort`` was run or not, only
whether changes were made.
- Refactor Black and ``isort`` file exclusions into one data structure.
- Refactor Black_ and ``isort`` file exclusions into one data structure.

Fixed
-----
Expand Down Expand Up @@ -213,7 +226,7 @@ Fixed
- Handle files encoded with an encoding other than UTF-8 without an exception.
- The GitHub Action now handles missing ``revision:`` correctly.
- Update ``cachix/install-nix-action`` to ``v17`` to fix macOS build error.
- Downgrade Python from 3.10 to 3.9 in the macOS NixOS build on GitHub due to a build
- Downgrade Python from 3.10 to 3.9 in the macOS NixOS_ build on GitHub due to a build
error with Python 3.10.
- Darker now reads its own configuration from the file specified using
``-c``/``--config``, or in case a directory is specified, from ``pyproject.toml``
Expand All @@ -235,12 +248,12 @@ Added

Fixed
-----
- Fix NixOS builds when ``pytest-darker`` calls ``pylint``. Needed to activate
- Fix NixOS_ builds when ``pytest-darker`` calls ``pylint``. Needed to activate
the virtualenv.
- Allow more time to pass when checking file modification times in a unit test.
Windows tests on GitHub are sometimes really slow.
- Multiline strings are now always reformatted completely even if just a part
was modified by the user and reformatted by Black. This prevents the
was modified by the user and reformatted by Black_. This prevents the
"back-and-forth indent" symptom.


Expand All @@ -249,14 +262,14 @@ Fixed

Added
-----
- Run tests on CI against Black ``main`` branch to get an early warning of
- Run tests on CI against Black_ ``main`` branch to get an early warning of
incompatible changes which would break Darker.
- Determine the commit range to check automatically in the GitHub Action.
- Improve GitHub Action documentation.
- Add Nix CI builds on Linux and macOS.
- Add a YAML linting workflow to the Darker repository.
- Updated Mypy to version 0.931.
- Guard against breaking changes in Black by testing against its ``main`` branch
- Updated Mypy_ to version 0.931.
- Guard against breaking changes in Black_ by testing against its ``main`` branch
in the ``test-future`` GitHub Workflow.

Fixed
Expand All @@ -279,9 +292,9 @@ Added
Fixed
-----
- ``regex`` module now always available for unit tests
- Compatibility with NixOS. Keep ``$PATH`` intact so Git can be called.
- Compatibility with NixOS_. Keep ``$PATH`` intact so Git can be called.
- Updated tests to pass on new Pygments versions
- Compatibility with Black 22.1
- Compatibility with `Black 22.1`_
- Removed additional newline at the end of the file with the ``--stdout`` flag
compared to without.
- Handle isort file skip comment ``#isort:file_skip`` without an exception.
Expand All @@ -307,13 +320,13 @@ Fixed
-----
- ``.py.<hash>.tmp`` files from VSCode are now correctly compared to corresponding
``.py`` files in earlier revisions of the Git reposiotry
- Honor exclusion patterns from Black configuration when choosing files to reformat.
- Honor exclusion patterns from Black_ configuration when choosing files to reformat.
This only applies when recursing directories specified on the command line, and only
affects Black reformatting, not ``isort`` or linters.
affects Black_ reformatting, not ``isort`` or linters.
- ``--revision rev1...rev2`` now actually applies reformatting and filters linter output
to only lines modified compared to the common ancestor of ``rev1`` and ``rev2``
- Relative paths are now resolved correctly when using the ``--stdout`` option
- Downgrade to Flake8 version 3.x for Pytest compatibility.
- Downgrade to Flake8_ version 3.x for Pytest compatibility.
See `tholo/pytest-flake8#81`__

__ https://github.com/tholo/pytest-flake8/issues/81
Expand All @@ -327,7 +340,7 @@ Added
- Empty and all-whitespace files are now reformatted properly
- Darker now allows itself to modify files when called with ``pre-commit -o HEAD``, but
also emits a warning about this being an experimental feature
- Mention Black's possible new line range formatting support in README
- Mention Black_'s possible new line range formatting support in README
- Darker can now be used in a plain directory tree in addition to Git repositories

Fixed
Expand All @@ -343,16 +356,16 @@ Fixed

Added
-----
- Support for Black's ``--skip-magic-trailing-comma`` option
- Support for Black_'s ``--skip-magic-trailing-comma`` option
- ``darker --diff`` output is now identical to that of ``black --diff``
- The ``-d`` / ``--stdout`` option outputs the reformatted contents of the single Python
file provided on the command line.
- Terminate with an error if non-existing files or directories are passed on the command
line. This also improves the error from misquoted parameters like ``"--lint pylint"``.
- Allow Git test case to run slower when checking file timestamps. CI can be slow.
- Fix compatibility with Black >= 21.7b1.dev9
- Fix compatibility with Black_ >= 21.7b1.dev9
- Show a simple one-line error instead of full traceback on some unexpected failures
- Skip reformatting files set to be excluded by Black in configuration files
- Skip reformatting files set to be excluded by Black_ in configuration files

Fixed
-----
Expand All @@ -369,7 +382,7 @@ Fixed

Added
-----
- Upgrade to and satisfy MyPy 0.910 by adding ``types-toml`` as a test dependency, and
- Upgrade to and satisfy Mypy_ 0.910 by adding ``types-toml`` as a test dependency, and
``types-dataclasses`` as well if running on Python 3.6.
- Installation instructions in a Conda environment.

Expand All @@ -380,8 +393,8 @@ Fixed
- AST verification no longer erroneously fails when using ``--isort``
- Historical comparisons like ``darker --diff --revision=v1.0..v1.1`` now actually
compare the second revision and not the working tree files on disk.
- Ensure identical Black formatting on Unix and Windows by always passing Unix newlines
to Black
- Ensure identical Black_ formatting on Unix and Windows by always passing Unix newlines
to Black_


1.2.3_ - 2021-05-02
Expand All @@ -399,7 +412,7 @@ Added

Fixed
-----
- Compatibility with MyPy 0.812
- Compatibility with Mypy_ 0.812
- Keep newline character sequence and text encoding intact when modifying files
- Installation now works on Windows
- Improve compatibility with pre-commit. Fallback to compare against HEAD if
Expand Down Expand Up @@ -453,7 +466,7 @@ Added
requests. In a way, Darker is now eating its own dogfood.
- Support commit ranges for ``-r``/``--revision``. Useful for comparing to the best
common ancestor, e.g. ``master...``.
- Configure Flake8 verification for Darker's own source code
- Configure Flake8_ verification for Darker's own source code


1.1.0_ - 2020-08-15
Expand Down Expand Up @@ -484,7 +497,7 @@ Fixed

Added
-----
- Support for black config
- Support for Black_ config
- Support for ``-l``/``--line-length`` and ``-S``/``--skip-string-normalization``
- ``--diff`` outputs a diff for each file on standard output
- Require ``isort`` >= 5.0.1 and be compatible with it
Expand All @@ -501,7 +514,7 @@ Added

Fixed
-----
- Run `isort` first, and only then do the detailed ``git diff`` for Black
- Run `isort` first, and only then do the detailed ``git diff`` for Black_


0.1.1_ - 2020-02-17
Expand Down Expand Up @@ -550,5 +563,14 @@ Added
.. _pytest-darker: https://pypi.org/project/pytest-darker/
.. _Black 19.10: https://github.com/psf/black/blob/master/CHANGES.md#1910b0
.. _Black 20.8: https://github.com/psf/black/blob/master/CHANGES.md#208b0
.. _Black 22.1: https://github.com/psf/black/blob/main/CHANGES.md#2210
.. _Black 24.2.0: https://github.com/psf/black/blob/master/CHANGES.md#2420
.. _Black 24.2.1: https://github.com/psf/black/blob/master/CHANGES.md#2421
.. _Pylint: https://pypi.org/project/pylint
.. _pygments: https://pypi.org/project/Pygments/
.. _Flake8: https://flake8.pycqa.org/
.. _Mypy: https://www.mypy-lang.org/
.. _pydocstyle: http://www.pydocstyle.org/
.. _Ruff: https://astral.sh/ruff
.. _Black: https://black.readthedocs.io/
.. _NixOS: https://nixos.org/
Loading
Loading