codespell-project / codespell

check code for common misspellings
GNU General Public License v2.0
1.88k stars 468 forks source link

method to get absolute path to dictionary.txt file #1540

Open muvarov opened 4 years ago

muvarov commented 4 years ago

dictionary.txt is used for linux kernel code checker checkpatch.pl. With the latest changed dictionary was moved from /usr/share/codespell/dictionary.txt to /usr/lib/python3/dist-packages/codespell_lib/data/dictionary.txt. With some custom installations paths might be different. I think it's better to add some method to codespell to printout default location of the dictionary. What do you think?

larsoner commented 4 years ago

With the latest changed dictionary was moved from /usr/share/codespell/dictionary.txt to /usr/lib/python3/dist-packages/codespell_lib/data/dictionary.txt. With some custom installations paths might be different. I think it's better to add some method to codespell to printout default location of the dictionary. What do you think?

In theory the location should (from now on at least) always be relative to where codespell itself is installed, i.e.:

python -c "import os.path as op; import codespell_lib; print(op.join(op.dirname(codespell_lib.__file__), 'data', 'dictionary.txt'))"

Would this work rather than adding something to codespell?

If not, I guess we could make a codespell --list or something that just spit out the absolute paths of the builtin dictionaries.

muvarov commented 4 years ago

I think 'codespell --list' is more clean way to do this.

peternewman commented 4 years ago

The other thing to note @muvarov if you're using the file independently rather than via Codespell, is that there are now multiple dictionary files ( https://github.com/codespell-project/codespell/tree/master/codespell_lib/data ), but only some are enabled by default: https://github.com/codespell-project/codespell/blob/f107ddb54b766c40f57d406c50858b1efe9a84b3/codespell_lib/_codespell.py#L50

Perhaps a --list option should report that status too?

larsoner commented 4 years ago

--help should tell them which are enabled by default somewhere, so I wouldn't put it in --list