From 6088ebfffd90e9285f5a5e9e2d8a6c84bac6d896 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:00:59 +0100 Subject: [PATCH 1/4] Follow-up of d639621 Make sure tests are not part of the wheel. This requires moving `tests` outside the source directory `codespell_lib`, flit is strict about this and does not seem to provide an option to skip files within the source directory.. Besides, that's the standard for small Python projects. --- .coveragerc | 1 - .github/workflows/codespell.yml | 2 +- .github/workflows/tests.yml | 6 +++--- AGENTS.md | 15 +++++++-------- Makefile | 6 +++--- pyproject-codespell.precommit-toml | 4 ++-- pyproject.toml | 8 ++++---- {codespell_lib/tests => tests}/__init__.py | 0 .../data/en_GB-additional.wordlist | 0 .../data/en_US-additional.wordlist | 0 {codespell_lib/tests => tests}/test_basic.py | 0 {codespell_lib/tests => tests}/test_dictionary.py | 6 +++--- 12 files changed, 23 insertions(+), 25 deletions(-) rename {codespell_lib/tests => tests}/__init__.py (100%) rename {codespell_lib/tests => tests}/data/en_GB-additional.wordlist (100%) rename {codespell_lib/tests => tests}/data/en_US-additional.wordlist (100%) rename {codespell_lib/tests => tests}/test_basic.py (100%) rename {codespell_lib/tests => tests}/test_dictionary.py (98%) diff --git a/.coveragerc b/.coveragerc index 09fee0e09a..93593072a9 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,6 @@ [run] branch = True source = codespell_lib -omit = */codespell_lib/tests/* # Some tests run the codespell entry point in a subprocess; without this their # coverage is invisible (pytest-cov 7 dropped its own subprocess support). patch = subprocess diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index c50416f6d0..289004d6fd 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -16,4 +16,4 @@ jobs: with: check_filenames: true # When using this Action in other repos, the --skip option below can be removed - skip: "./.git,./codespell_lib/data,./example/code.c,test_basic.py,./codespell_lib/tests/data,*.pyc,README.rst,pyproject-codespell.precommit-toml" + skip: "./.git,./codespell_lib/data,./example/code.c,test_basic.py,./tests/data,*.pyc,README.rst,pyproject-codespell.precommit-toml" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 90daf602fc..e943cadacc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -67,7 +67,7 @@ jobs: - run: codespell --version - run: make check if: startsWith(matrix.os, 'ubuntu') - - run: pytest codespell_lib + - run: pytest if: startsWith(matrix.os, 'windows') - uses: codecov/codecov-action@v7 with: @@ -75,9 +75,9 @@ jobs: # tomli should not be required for the next two steps (and make sure it's not) - run: pip uninstall -yq tomli if: ${{ matrix.kind == 'no-toml' }} - - run: codespell --check-filenames --skip="./.*,./build/*,./codespell_lib/data/*,./codespell_lib/tests/test_basic.py,./example/code.c,./junit-results.xml,*.egg-info/*,*.pyc,*.sig,pyproject-codespell.precommit-toml,README.rst," + - run: codespell --check-filenames --skip="./.*,./build/*,./codespell_lib/data/*,./tests/test_basic.py,./example/code.c,./junit-results.xml,*.egg-info/*,*.pyc,*.sig,pyproject-codespell.precommit-toml,README.rst," # this file has an error - - run: "! codespell codespell_lib/tests/test_basic.py" + - run: "! codespell tests/test_basic.py" shell: bash -e {0} make-check-dictionaries: diff --git a/AGENTS.md b/AGENTS.md index ef2d8e60c0..295160d0e5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -41,9 +41,9 @@ when something actually needs it. near-duplicate. - **Do not add dependencies** without asking first. - **Add to an existing test before writing a new one.** Extend a test in - `codespell_lib/tests/test_basic.py` that already sets up what you need, - then add a new test function there, and only then consider a new file. A - few compact assertions beat a long test that re-creates setup. + `tests/test_basic.py` that already sets up what you need, then add a new + test function there, and only then consider a new file. A few compact + assertions beat a long test that re-creates setup. - **For a bug fix, confirm the test fails without the fix and passes with it.** A regression test that passes without the fix guards nothing. @@ -52,7 +52,7 @@ when something actually needs it. ```bash pip install -e . --group dev # editable install with test/lint deps pre-commit install --install-hooks # ruff, mypy, codespell, file sorting, ... -pytest codespell_lib/tests/test_basic.py -k write_changes # CLI tests +pytest tests/test_basic.py -k write_changes # CLI tests make check-dictionaries # sort + validate dictionaries (test_dictionary.py) pre-commit run --all-files # all linters, auto-fixing where possible make check # everything CI checks: dictionaries, build, pytest, ruff @@ -66,10 +66,9 @@ Pure Python (>= 3.9), no runtime dependencies. file checking/fixing. - `codespell_lib/data/dictionary*.txt`: the misspelling dictionaries, one per `--builtin` set. -- `codespell_lib/tests/test_basic.py`: CLI behavior tests, mostly calling - `cs.main(...)` on files in `tmp_path`. -- `codespell_lib/tests/test_dictionary.py`: dictionary format and - consistency checks. +- `tests/test_basic.py`: CLI behavior tests, mostly calling `cs.main(...)` + on files in `tmp_path`. +- `tests/test_dictionary.py`: dictionary format and consistency checks. Dictionary entries are `typo->fix`; with more than one fix, end the line with a comma so none is applied automatically: diff --git a/Makefile b/Makefile index c7560182b3..1bd098c41d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DICTIONARIES = codespell_lib/data/dictionary*.txt codespell_lib/tests/data/*.wordlist +DICTIONARIES = codespell_lib/data/dictionary*.txt tests/data/*.wordlist PHONY := all check check-dictionaries sort-dictionaries trim-dictionaries check-dist pytest pypi ruff clean @@ -23,7 +23,7 @@ check-dictionaries: sort-dictionaries fi; \ done @if command -v pytest > /dev/null; then \ - pytest codespell_lib/tests/test_dictionary.py; \ + pytest tests/test_dictionary.py; \ else \ echo "Test dependencies not present, install using 'pip install -e . --group dev'"; \ exit 1; \ @@ -47,7 +47,7 @@ ruff: pytest: sort-dictionaries @if command -v pytest > /dev/null; then \ - pytest codespell_lib; \ + pytest; \ else \ echo "Test dependencies not present, install using 'pip install -e . --group dev'"; \ exit 1; \ diff --git a/pyproject-codespell.precommit-toml b/pyproject-codespell.precommit-toml index e27bdc52de..ea9335d495 100644 --- a/pyproject-codespell.precommit-toml +++ b/pyproject-codespell.precommit-toml @@ -3,5 +3,5 @@ builtin = "clear,rare,informal,usage,code,names" #ignore-words-list = ["uint"] ignore-words-list = "adn,master,uint,wrod" -#skip=[ "./.*","codespell_lib/data/*","codespell_lib/tests/*"] -skip="./.*,codespell_lib/data/*,codespell_lib/tests/*" +#skip=[ "./.*","codespell_lib/data/*","tests/*"] +skip="./.*,codespell_lib/data/*,tests/*" diff --git a/pyproject.toml b/pyproject.toml index ae3a03edbc..4e3b74b833 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ name = "codespell_lib" #[tool.codespell] #builtin = ["clear","rare","informal","usage","code","names"] #ignore-words-list = ["uint"] -#skip=[ "./.*","codespell_lib/data/*","codespell_lib/tests/*"] +#skip=[ "./.*","codespell_lib/data/*","tests/*"] [tool.mypy] pretty = true @@ -83,7 +83,7 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [tool.pytest.ini_options] minversion = "6" -testpaths = ["codespell_lib/tests"] +testpaths = ["tests"] log_cli_level = "INFO" xfail_strict = true addopts = ["--cov=codespell_lib", "-rs", "--strict-config", "--strict-markers", "--cov-report=", "--tb=short", "--junit-xml=junit-results.xml"] @@ -150,8 +150,8 @@ max-complexity = 45 [tool.ruff.lint.per-file-ignores] "codespell_lib/_codespell.py" = ["A003"] -"codespell_lib/tests/test_*" = ["S101"] -"codespell_lib/tests/test_basic.py" = ["ANN401", "N802"] +"tests/test_*" = ["S101"] +"tests/test_basic.py" = ["ANN401", "N802"] [tool.ruff.lint.pylint] allow-magic-value-types = ["bytes", "int", "str",] diff --git a/codespell_lib/tests/__init__.py b/tests/__init__.py similarity index 100% rename from codespell_lib/tests/__init__.py rename to tests/__init__.py diff --git a/codespell_lib/tests/data/en_GB-additional.wordlist b/tests/data/en_GB-additional.wordlist similarity index 100% rename from codespell_lib/tests/data/en_GB-additional.wordlist rename to tests/data/en_GB-additional.wordlist diff --git a/codespell_lib/tests/data/en_US-additional.wordlist b/tests/data/en_US-additional.wordlist similarity index 100% rename from codespell_lib/tests/data/en_US-additional.wordlist rename to tests/data/en_US-additional.wordlist diff --git a/codespell_lib/tests/test_basic.py b/tests/test_basic.py similarity index 100% rename from codespell_lib/tests/test_basic.py rename to tests/test_basic.py diff --git a/codespell_lib/tests/test_dictionary.py b/tests/test_dictionary.py similarity index 98% rename from codespell_lib/tests/test_dictionary.py rename to tests/test_dictionary.py index 4411c49225..e105507d51 100644 --- a/codespell_lib/tests/test_dictionary.py +++ b/tests/test_dictionary.py @@ -42,7 +42,7 @@ global_pairs: set[tuple[str, str]] = set() # Filename, should be seen as errors in aspell or not -_data_dir = op.join(op.dirname(__file__), "..", "data") +_data_dir = op.join(op.dirname(__file__), "..", "codespell_lib", "data") _fnames_in_aspell = [ (op.join(_data_dir, f"dictionary{d[2]}.txt"), d[3:5], d[5:7]) for d in _builtin_dictionaries @@ -84,8 +84,8 @@ def test_dictionary_formatting( @pytest.mark.parametrize( "filename", [ - *(root / "data").rglob("dictionary*.txt"), - *(root / "tests/data").rglob("*.wordlist"), + *(root / "codespell_lib" / "data").rglob("dictionary*.txt"), + *(root / "tests" / "data").rglob("*.wordlist"), ], ) def test_dictionary_sorting(filename: pathlib.Path) -> None: From e3075fd853580a3849f7b9d2bfe8e82acc0ac5c8 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:11:57 +0100 Subject: [PATCH 2/4] Either tox runs all pre-commit checks, or none I chose to run none of them since pre-commit is run by CI anyway. This way, a consistent version of MyPy shall be used. --- tox.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tox.ini b/tox.ini index b93be53014..c350e39d58 100644 --- a/tox.ini +++ b/tox.ini @@ -12,8 +12,3 @@ commands = make check-dictionaries description = run unit tests dependency_groups = dev commands = pytest --cov=codespell_lib {posargs} codespell_lib - -[testenv:type] -description = run type checks -dependency_groups = types -commands = mypy codespell_lib From 1da3cc16b024dd90800499f9444ce36a98ae68de Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:07:47 +0100 Subject: [PATCH 3/4] Follow-up of d639621 Make sure files useful for development and testing are part of the sdist. Also, get rid of the now obsolete `MANIFEST.in` file. --- MANIFEST.in | 11 ----------- pyproject.toml | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 90c44a95a9..0000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,11 +0,0 @@ -exclude *.yml -exclude .coveragerc -exclude .git-blame-ignore-revs -prune example -prune snap -prune .devcontainer -prune .github -exclude .gitignore -exclude .mailmap -exclude codespell.1.include -exclude pyproject-codespell.precommit-toml diff --git a/pyproject.toml b/pyproject.toml index 4e3b74b833..51921e5f58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,14 +60,24 @@ codespell = "codespell_lib:_script_main" homepage = "https://github.com/codespell-project/codespell" repository = "https://github.com/codespell-project/codespell" +[tool.flit.module] +name = "codespell_lib" + +[tool.flit.sdist] +include = [ + "tests/", + "Makefile", + ".pre-commit-config.yaml", + ".pre-commit-hooks.yaml", + "tools/gen_OX.sh", + "tox.ini", +] + # flit_scm uses setuptools_scm under the hood to write the version file at # build time, so that flit can stamp the version into the package metadata. [tool.setuptools_scm] write_to = "codespell_lib/_version.py" -[tool.flit.module] -name = "codespell_lib" - # TODO: reintegrate codespell configuration after updating test cases #[tool.codespell] #builtin = ["clear","rare","informal","usage","code","names"] From fdd0b34cf644dfa6f23eddc965cf4ed4592ca8c0 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 28 Nov 2026 20:41:29 +0100 Subject: [PATCH 4/4] Fix warning in CI while building sdist WARNING "/home/runner/work/codespell/codespell" is shallow and may cause errors --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 51921e5f58..55e7681de2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,6 +77,7 @@ include = [ # build time, so that flit can stamp the version into the package metadata. [tool.setuptools_scm] write_to = "codespell_lib/_version.py" +scm.git.pre_parse = "fetch_on_shallow" # TODO: reintegrate codespell configuration after updating test cases #[tool.codespell]