Skip to content

Commit 2a0ee4b

Browse files
Freed-Wularsoner
andauthored
Fix #2055: Add support for PEP 518 (#2290)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 214255a commit 2a0ee4b

6 files changed

Lines changed: 66 additions & 29 deletions

File tree

.github/workflows/codespell-private.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# For general usage in your repo, see the example in codespell.yml
33
# https://github.com/codespell-project/codespell
44
name: codespell Private Actions
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
7+
cancel-in-progress: true
58
on: [push, pull_request]
69
jobs:
710
test:
@@ -10,12 +13,13 @@ jobs:
1013
# Make sure we're using the latest aspell dictionary
1114
runs-on: ubuntu-20.04
1215
strategy:
16+
fail-fast: false
1317
matrix:
1418
python-version:
15-
- 3.6
16-
- 3.7
17-
- 3.8
18-
- 3.9
19+
- '3.7'
20+
- '3.8'
21+
- '3.9'
22+
- '3.10'
1923
name: Python ${{ matrix.python-version }} test
2024
steps:
2125
- uses: actions/checkout@v3

README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Useful links
2323
Requirements
2424
------------
2525

26-
Python 3.6 or above.
26+
Python 3.7 or above.
2727

2828
Installation
2929
------------
@@ -107,6 +107,13 @@ This is equivalent to running::
107107

108108
codespell --quiet-level 3 --count --skip "*.po,*.ts,./src/3rdParty,./src/Test"
109109

110+
Now codespell also support ``pyproject.toml``::
111+
112+
[tool.codespell]
113+
skip = '*.po,*.ts,./src/3rdParty,./src/Test'
114+
count = ''
115+
quiet-level = 3
116+
110117
Any options specified in the command line will *override* options from the
111118
config file.
112119

codespell_lib/_codespell.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ def parse_options(args):
392392
help='print LINES of surrounding context')
393393
parser.add_argument('--config', type=str,
394394
help='path to config file.')
395-
395+
parser.add_argument('--toml', type=str,
396+
help='path to a pyproject.toml file.')
396397
parser.add_argument('files', nargs='*',
397398
help='files or directories to check')
398399

@@ -404,6 +405,18 @@ def parse_options(args):
404405
if options.config:
405406
cfg_files.append(options.config)
406407
config = configparser.ConfigParser()
408+
409+
# Read toml before other config files.
410+
if options.toml:
411+
try:
412+
import tomli
413+
except Exception as exc:
414+
raise ImportError(
415+
f'tomli is required to read pyproject.toml but could not be '
416+
f'imported, got: {exc}') from None
417+
with open(options.toml, 'rb') as f:
418+
data = tomli.load(f).get('tool', {})
419+
config.read_dict(data)
407420
config.read(cfg_files)
408421

409422
if config.has_section('codespell'):

codespell_lib/tests/test_basic.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -791,35 +791,45 @@ def test_uri_regex_def():
791791
assert not uri_regex.findall(boilerplate % uri), uri
792792

793793

794-
def test_config(tmpdir, capsys):
795-
"""
796-
Tests loading options from a config file.
797-
"""
798-
d = str(tmpdir)
799-
800-
# Create sample files.
801-
with open(op.join(d, 'bad.txt'), 'w') as f:
794+
@pytest.mark.parametrize('kind', ('toml', 'cfg'))
795+
def test_config_toml(tmp_path, capsys, kind):
796+
"""Test loading options from a config file or toml."""
797+
d = tmp_path / 'files'
798+
d.mkdir()
799+
with open(d / 'bad.txt', 'w') as f:
802800
f.write('abandonned donn\n')
803-
with open(op.join(d, 'good.txt'), 'w') as f:
801+
with open(d / 'good.txt', 'w') as f:
804802
f.write("good")
805803

806-
# Create a config file.
807-
conffile = op.join(d, 'config.cfg')
808-
with open(conffile, 'w') as f:
809-
f.write(
810-
'[codespell]\n'
811-
'skip = bad.txt\n'
812-
'count = \n'
813-
)
814-
815804
# Should fail when checking both.
816-
code, stdout, _ = cs.main(d, count=True, std=True)
805+
code, stdout, _ = cs.main(str(d), count=True, std=True)
817806
# Code in this case is not exit code, but count of misspellings.
818807
assert code == 2
819808
assert 'bad.txt' in stdout
820809

810+
if kind == 'cfg':
811+
conffile = str(tmp_path / 'config.cfg')
812+
args = ('--config', conffile)
813+
with open(conffile, 'w') as f:
814+
f.write("""\
815+
[codespell]
816+
skip = bad.txt, whatever.txt
817+
count =
818+
""")
819+
else:
820+
assert kind == 'toml'
821+
pytest.importorskip('tomli')
822+
tomlfile = str(tmp_path / 'pyproject.toml')
823+
args = ('--toml', tomlfile)
824+
with open(tomlfile, 'w') as f:
825+
f.write("""\
826+
[tool.codespell]
827+
skip = 'bad.txt,whatever.txt'
828+
count = false
829+
""")
830+
821831
# Should pass when skipping bad.txt
822-
code, stdout, _ = cs.main('--config', conffile, d, count=True, std=True)
832+
code, stdout, _ = cs.main(str(d), *args, count=True, std=True)
823833
assert code == 0
824834
assert 'bad.txt' not in stdout
825835

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool:pytest]
2-
addopts = --cov=codespell_lib --showlocals -rs --cov-report=
2+
addopts = --cov=codespell_lib -rs --cov-report= --tb=short
33

44
[flake8]
55
exclude = build, ci-helpers

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
'Operating System :: Unix',
4444
'Operating System :: MacOS'],
4545
platforms='any',
46-
python_requires='>=3.6',
46+
python_requires='>=3.7',
4747
packages=[
4848
'codespell_lib',
4949
'codespell_lib.tests',
@@ -58,9 +58,12 @@
5858
'codespell = codespell_lib:_script_main'
5959
],
6060
},
61+
# TODO: toml will need to be updated when 3.11 comes out as it's a
62+
# CPython module there
6163
extras_require={
6264
"dev": ["check-manifest", "flake8", "pytest", "pytest-cov",
63-
"pytest-dependency"],
65+
"pytest-dependency", "tomli"],
6466
"hard-encoding-detection": ["chardet"],
67+
"toml": ["tomli"],
6568
}
6669
)

0 commit comments

Comments
 (0)