Skip to content

Commit 3ea9498

Browse files
authored
Merge pull request #2515 from larsoner/comment
DOC: Better docs
2 parents 4bcbf34 + f58c60b commit 3ea9498

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

.github/workflows/codespell-private.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# GitHub Action to check our dictionary, this should only be used by the codespell project itself
22
# For general usage in your repo, see the example in codespell.yml
33
# https://github.com/codespell-project/codespell
4+
# Concurrency cancels an action on a given PR once a new commit is pushed
45
name: codespell Private Actions
56
concurrency:
67
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}

README.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,24 @@ be specified in this file (without the preceding dashes), for example::
103103
count =
104104
quiet-level = 3
105105

106-
This is equivalent to running::
107-
108-
codespell --quiet-level 3 --count --skip "*.po,*.ts,./src/3rdParty,./src/Test"
109-
110-
Now codespell also support ``pyproject.toml``::
106+
Codespell will also check in the current directory for a ``pyproject.toml``
107+
(or a path can be specified via ``--toml <filename>``) file, and the
108+
``[tool.codespell]`` entry will be used as long as the tomli_ package
109+
is installed, for example::
111110

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

116+
These are both equivalent to running::
117+
118+
codespell --quiet-level 3 --count --skip "*.po,*.ts,./src/3rdParty,./src/Test"
119+
117120
Any options specified in the command line will *override* options from the
118-
config file.
121+
config files.
122+
123+
.. _tomli: https://pypi.org/project/tomli/
119124

120125
Dictionary format
121126
-----------------

codespell_lib/_codespell.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,22 @@ def parse_options(args):
407407
config = configparser.ConfigParser()
408408

409409
# Read toml before other config files.
410+
toml_files_errors = list()
411+
if os.path.isfile('pyproject.toml'):
412+
toml_files_errors.append(('pyproject.toml', False))
410413
if options.toml:
414+
toml_files_errors.append((options.toml, True))
415+
for toml_file, raise_error in toml_files_errors:
411416
try:
412417
import tomli
413418
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:
419+
if raise_error:
420+
raise ImportError(
421+
f'tomli is required to read pyproject.toml but could not '
422+
f'be imported, got: {exc}') from None
423+
else:
424+
continue
425+
with open(toml_file, 'rb') as f:
418426
data = tomli.load(f).get('tool', {})
419427
config.read_dict(data)
420428
config.read(cfg_files)

codespell_lib/tests/test_basic.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ def test_config_toml(tmp_path, capsys, kind):
808808
assert 'bad.txt' in stdout
809809

810810
if kind == 'cfg':
811-
conffile = str(tmp_path / 'config.cfg')
811+
conffile = str(tmp_path / 'setup.cfg')
812812
args = ('--config', conffile)
813813
with open(conffile, 'w') as f:
814814
f.write("""\
@@ -833,6 +833,16 @@ def test_config_toml(tmp_path, capsys, kind):
833833
assert code == 0
834834
assert 'bad.txt' not in stdout
835835

836+
# And both should automatically work if they're in cwd
837+
cwd = os.getcwd()
838+
try:
839+
os.chdir(tmp_path)
840+
code, stdout, _ = cs.main(str(d), count=True, std=True)
841+
finally:
842+
os.chdir(cwd)
843+
assert code == 0
844+
assert 'bad.txt' not in stdout
845+
836846

837847
@contextlib.contextmanager
838848
def FakeStdin(text):

0 commit comments

Comments
 (0)