Skip to content

DOC: Better docs #2515

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

Merged
merged 6 commits into from
Oct 6, 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
1 change: 1 addition & 0 deletions .github/workflows/codespell-private.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GitHub Action to check our dictionary, this should only be used by the codespell project itself
# 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: codespell Private Actions
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
Expand Down
17 changes: 11 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,24 @@ be specified in this file (without the preceding dashes), for example::
count =
quiet-level = 3

This is equivalent to running::

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

Now codespell also support ``pyproject.toml``::
Codespell will also check in the current directory for a ``pyproject.toml``
(or a path can be specified via ``--toml <filename>``) file, and the
``[tool.codespell]`` entry will be used as long as the tomli_ package
is installed, for example::

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

These are both equivalent to running::

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

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

.. _tomli: https://pypi.org/project/tomli/

Dictionary format
-----------------
Expand Down
16 changes: 12 additions & 4 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,22 @@ def parse_options(args):
config = configparser.ConfigParser()

# Read toml before other config files.
toml_files_errors = list()
if os.path.isfile('pyproject.toml'):
toml_files_errors.append(('pyproject.toml', False))
if options.toml:
toml_files_errors.append((options.toml, True))
for toml_file, raise_error in toml_files_errors:
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:
if raise_error:
raise ImportError(
f'tomli is required to read pyproject.toml but could not '
f'be imported, got: {exc}') from None
else:
continue
with open(toml_file, 'rb') as f:
data = tomli.load(f).get('tool', {})
config.read_dict(data)
config.read(cfg_files)
Expand Down
12 changes: 11 additions & 1 deletion codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def test_config_toml(tmp_path, capsys, kind):
assert 'bad.txt' in stdout

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

# And both should automatically work if they're in cwd
cwd = os.getcwd()
try:
os.chdir(tmp_path)
code, stdout, _ = cs.main(str(d), count=True, std=True)
finally:
os.chdir(cwd)
assert code == 0
assert 'bad.txt' not in stdout


@contextlib.contextmanager
def FakeStdin(text):
Expand Down