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

Docs request: how to put check-filenames and ignore-words-list into pyproject.toml #2839

Closed
jamesbraza opened this issue Apr 26, 2023 · 13 comments · Fixed by #3046
Closed

Docs request: how to put check-filenames and ignore-words-list into pyproject.toml #2839

jamesbraza opened this issue Apr 26, 2023 · 13 comments · Fixed by #3046

Comments

@jamesbraza
Copy link
Contributor

How can I put check-filenames, check-hidden, and ignore-words-list into pyproject.toml?

In the tests there doesn't seem to be a case for this: https://github.com/codespell-project/codespell/blob/v2.2.4/codespell_lib/tests/test_basic.py#L1028

From a GitHub Search, there's no results either: tool.codespell filename:pyproject.toml

And none of the below keys are working for me:

[tool.codespell]

check-filenames = true
check-hidden = true
ignore-words-list = ["acn"]
> codespell .
usage: codespell [-h] [--version] [-d] [-c] [-w] [-D DICTIONARY] [--builtin BUILTIN-LIST] [--ignore-regex IGNORE_REGEX] [-I FILE] [-L WORDS] [--uri-ignore-words-list WORDS] [-r REGEX] [--uri-regex URI_REGEX] [-s] [--count] [-S SKIP]
                 [-x FILE] [-i INTERACTIVE] [-q QUIET_LEVEL] [-e] [-f] [-H] [-A LINES] [-B LINES] [-C LINES] [--config CONFIG] [--toml TOML]
                 [files ...]
codespell: error: unrecognized arguments: True

From https://stackoverflow.com/questions/75377334/toml-how-to-have-key-without-value it seems keys without values aren't possible in .toml.


Related: #2718

Here is my old .codespellrc:

[codespell]
check-filenames =
check-hidden =
ignore-words-list = acn
@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Apr 26, 2023

ignore-words-list expects a “comma separated list of words”. Try:

ignore-words-list = "acn"

@jamesbraza
Copy link
Contributor Author

jamesbraza commented Apr 26, 2023

[tool.codespell]

ignore-words-list = "acn"

Works for me when invoking codespell from the command line or with this pre-commit config:

- repo: https://github.com/codespell-project/codespell
  rev: v2.2.4
  hooks:
  - id: codespell
    additional_dependencies:
      - tomli

Yaay, thank you!


How about check-filenames and check-hidden?

@rly
Copy link

rly commented Aug 25, 2023

How about check-filenames and check-hidden?

Following the convention in https://github.com/codespell-project/codespell#using-a-config-file where --count in the command line corresponds to count = in the .codespellrc file and count = '' in the pyproject.toml file, I tried this:

[tool.codespell]
ignore-words-list = "acn"
check-filenames = ""
check-hidden = ""

And it looks like it works as intended.

@DimitriPapadopoulos
Copy link
Collaborator

Shouldn't these work as well?

check-filenames = true
check-hidden = true

I wonder whether this should be considered a bug.

@jamesbraza
Copy link
Contributor Author

@DimitriPapadopoulos thanks for the PR, appreciated! What is the correct TOML usage now, is it true/false for check-filenames/hidden?

@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Sep 1, 2023

Not sure "correct" applies here, but yes, true/false should work now, but only in TOML files.

Ideally I would like true/false and 1/0 to work in INI files, but that would require wider changes.

@Borda
Copy link

Borda commented Sep 22, 2023

ignore-words-list expects a “comma separated list of words”.

Would it be possible to allow also a list? The main advantage is that you can then write notes/comments for future you

ignore-words-list = [
	"MAPE", # metrics name
	"fo", # fall-out variable
]

@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Sep 22, 2023

It could be implemented in TOML files, but the concept does not seem compatible with INI config files.

The difficulty is that our options processing model is based on command line options and INI config files. I have tried to add some flexibility to our parsing of TOML files, but adding too many TOML-related patches might end up in too complex code. The main difficulty difficulty might be that we need to remain compatible with argparse.ArgumentParser - or rewrite the entire options parsing code.

Perhaps I can have a go at it when finalising #2767.

@Borda
Copy link

Borda commented Sep 22, 2023

The main difficulty difficulty might be that we need to remain compatible with argparse.ArgumentParser

yes I think just switching this options to accept one or more values with nargs would be fully compatible and if only one is passed you try to split with comma

or rewrite the entire options parsing code.

I would try Fire which has zero additional dependencies; and eventually I can help

about the ignore-words-list it is confusing as you can't pass a list but one string, so shall be just ignore-words

@Borda
Copy link

Borda commented Sep 22, 2023

@DimitriPapadopoulos seems does not work for me...

docs/source/text/rouge_score.rst:2: ROUGE ==> ROGUE
docs/source/text/rouge_score.rst:9: ROUGE ==> ROGUE
docs/source/text/rouge_score.rst:15: rouge ==> rogue
docs/source/text/rouge_score.rst:21: rouge ==> rogue
...

with my pyproject.toml config

[tool.codespell]
# comma separated list of words
ignore-words-list = "ROUGE"
quiet-level = 3

and using precommit:

  - repo: https://github.com/codespell-project/codespell
    rev: v2.2.5
    hooks:
      - id: codespell
        additional_dependencies: [tomli]

@DimitriPapadopoulos
Copy link
Collaborator

I find ignore-words-list confusing too. Unfortunately, ignore-words is already taken:

  -I FILE, --ignore-words FILE
                        file that contains words that will be ignored by
                        codespell. File must contain 1 word per line. Words
                        are case sensitive based on how they are written in
                        the dictionary file
  -L WORDS, --ignore-words-list WORDS
                        comma separated list of words to be ignored by
                        codespell. Words are case sensitive based on how they
                        are written in the dictionary file

It would probably be less confusing if we could switch ignore-words and ignore-words-list – but it's too late for that.

@DimitriPapadopoulos
Copy link
Collaborator

seems does not work for me...

See Ignoring Words. Change:

ignore-words-list = "ROUGE"

to:

ignore-words-list = "rouge"

@Borda
Copy link

Borda commented Sep 22, 2023

Ahh, all need to be lower-case? Even I have "ROUGE" in the text and write identical ROUGE (including case-sensitive) to the ignore list...

It would probably be less confusing if we could switch ignore-words and ignore-words-list – but it's too late for that

Do you mean for backward compatibility? I think that allowing words as a list truly would help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants