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

Fix #2055: Add support for PEP 518 #2290

Merged
merged 9 commits into from
Oct 5, 2022
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
12 changes: 8 additions & 4 deletions .github/workflows/codespell-private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# For general usage in your repo, see the example in codespell.yml
# https://github.com/codespell-project/codespell
name: codespell Private Actions
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
cancel-in-progress: true
Comment on lines +5 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsoner can we have a comment explaining what this is trying to achieve. It looks like the old fail-fast would have done the same thing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fail-fast cancels jobs within an action if one of them fails

this cancels jobs if another commit is pushed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, although do we want fail-fast too?

Copy link
Member

@larsoner larsoner Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that our tests are fast enough already and as we add others (different OSes etc) they can potentially show different problems. But we reenable it if you want

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably it won't start testing the next commit until the last one is done?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With cancel-in-progress: true if you push a commit it kills runs from a previous commit. But all jobs from a given commit are allowed to run to completion (because of fail-fast: false) so you can see potentially different errors for your latest commit

To me it's the most reasonable behavior, as it's how Travis behaved from the start years ago IIRC and most CI providers followed suit (or at least provided an option for it) and has seemed like a good compromise over the years

on: [push, pull_request]
jobs:
test:
Expand All @@ -10,12 +13,13 @@ jobs:
# Make sure we're using the latest aspell dictionary
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version:
- 3.6
- 3.7
- 3.8
- 3.9
- '3.7'
- '3.8'
- '3.9'
- '3.10'
name: Python ${{ matrix.python-version }} test
steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 8 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Useful links
Requirements
------------

Python 3.6 or above.
Python 3.7 or above.

Installation
------------
Expand Down Expand Up @@ -107,6 +107,13 @@ This is equivalent to running::

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

Now codespell also support ``pyproject.toml``::
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...via the --toml argument


[tool.codespell]
skip = '*.po,*.ts,./src/3rdParty,./src/Test'
count = ''
quiet-level = 3

Any options specified in the command line will *override* options from the
config file.

Expand Down
15 changes: 14 additions & 1 deletion codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ def parse_options(args):
help='print LINES of surrounding context')
parser.add_argument('--config', type=str,
help='path to config file.')

parser.add_argument('--toml', type=str,
help='path to a pyproject.toml file.')
parser.add_argument('files', nargs='*',
help='files or directories to check')

Expand All @@ -404,6 +405,18 @@ def parse_options(args):
if options.config:
cfg_files.append(options.config)
config = configparser.ConfigParser()

# Read toml before other config files.
if options.toml:
try:
import tomli
except Exception as exc:
raise ImportError(
f'tomli is required to read pyproject.toml but could not be '
f'imported, got: {exc}') from None
with open(options.toml, 'rb') as f:
data = tomli.load(f).get('tool', {})
config.read_dict(data)
Freed-Wu marked this conversation as resolved.
Show resolved Hide resolved
config.read(cfg_files)

if config.has_section('codespell'):
Expand Down
50 changes: 30 additions & 20 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,35 +791,45 @@ def test_uri_regex_def():
assert not uri_regex.findall(boilerplate % uri), uri


def test_config(tmpdir, capsys):
"""
Tests loading options from a config file.
"""
d = str(tmpdir)

# Create sample files.
with open(op.join(d, 'bad.txt'), 'w') as f:
@pytest.mark.parametrize('kind', ('toml', 'cfg'))
def test_config_toml(tmp_path, capsys, kind):
"""Test loading options from a config file or toml."""
d = tmp_path / 'files'
d.mkdir()
with open(d / 'bad.txt', 'w') as f:
f.write('abandonned donn\n')
with open(op.join(d, 'good.txt'), 'w') as f:
with open(d / 'good.txt', 'w') as f:
f.write("good")

# Create a config file.
conffile = op.join(d, 'config.cfg')
with open(conffile, 'w') as f:
f.write(
'[codespell]\n'
'skip = bad.txt\n'
'count = \n'
)

# Should fail when checking both.
code, stdout, _ = cs.main(d, count=True, std=True)
code, stdout, _ = cs.main(str(d), count=True, std=True)
# Code in this case is not exit code, but count of misspellings.
assert code == 2
assert 'bad.txt' in stdout

if kind == 'cfg':
conffile = str(tmp_path / 'config.cfg')
args = ('--config', conffile)
with open(conffile, 'w') as f:
f.write("""\
[codespell]
skip = bad.txt, whatever.txt
count =
""")
else:
assert kind == 'toml'
pytest.importorskip('tomli')
tomlfile = str(tmp_path / 'pyproject.toml')
args = ('--toml', tomlfile)
with open(tomlfile, 'w') as f:
f.write("""\
[tool.codespell]
skip = 'bad.txt,whatever.txt'
count = false
""")

# Should pass when skipping bad.txt
code, stdout, _ = cs.main('--config', conffile, d, count=True, std=True)
code, stdout, _ = cs.main(str(d), *args, count=True, std=True)
assert code == 0
assert 'bad.txt' not in stdout

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool:pytest]
addopts = --cov=codespell_lib --showlocals -rs --cov-report=
addopts = --cov=codespell_lib -rs --cov-report= --tb=short

[flake8]
exclude = build, ci-helpers
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'Operating System :: Unix',
'Operating System :: MacOS'],
platforms='any',
python_requires='>=3.6',
python_requires='>=3.7',
packages=[
'codespell_lib',
'codespell_lib.tests',
Expand All @@ -58,9 +58,12 @@
'codespell = codespell_lib:_script_main'
],
},
# TODO: toml will need to be updated when 3.11 comes out as it's a
# CPython module there
extras_require={
"dev": ["check-manifest", "flake8", "pytest", "pytest-cov",
"pytest-dependency"],
"pytest-dependency", "tomli"],
"hard-encoding-detection": ["chardet"],
"toml": ["tomli"],
}
)