BUG: Fix bug with toml triage (#2774)
diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml
index 9a14d55..1318451 100644
--- a/.github/workflows/codespell-private.yml
+++ b/.github/workflows/codespell-private.yml
@@ -2,7 +2,7 @@
# For general usage in your repo, see the example in codespell.yml
# https://github.com/codespell-project/codespell
# Concurrency cancels an action on a given PR once a new commit is pushed
-name: Test Codespell
+name: Pytest
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
cancel-in-progress: true
@@ -23,7 +23,12 @@
- '3.9'
- '3.10'
- '3.11'
- name: Python ${{ matrix.python-version }} test
+ no-toml:
+ - ''
+ include:
+ - python-version: '3.10'
+ no-toml: 'no-toml'
+ name: ${{ matrix.python-version }} ${{ matrix.no-toml }}
steps:
- uses: actions/checkout@v3
with:
@@ -44,10 +49,14 @@
- run: codespell --version
- run: make check
- uses: codecov/codecov-action@v3
- - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml"
+ # tomli should not be required for the next two steps (and make sure it's not)
+ - run: pip uninstall -yq tomli
+ if: ${{ matrix.no-toml == 'no-toml' }}
+ - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache"
# this file has an error
- run: "! codespell codespell_lib/tests/test_basic.py"
+
make-check-dictionaries:
runs-on: ubuntu-latest
steps:
diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py
index 0e4209a..3b79286 100644
--- a/codespell_lib/_codespell.py
+++ b/codespell_lib/_codespell.py
@@ -563,10 +563,12 @@
f"tomllib or tomli are required to read pyproject.toml "
f"but could not be imported, got: {e}"
) from None
- for toml_file in toml_files:
- with open(toml_file, "rb") as f:
- data = tomllib.load(f).get("tool", {})
- config.read_dict(data)
+ tomllib = None
+ if tomllib is not None:
+ for toml_file in toml_files:
+ with open(toml_file, "rb") as f:
+ data = tomllib.load(f).get("tool", {})
+ config.read_dict(data)
# Collect which config files are going to be used
used_cfg_files = []