pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.33k stars 1.14k forks source link

spelling-private-dict-file should be looked up relative to pylintrc file instead of current folder #8972

Open jjmortensen opened 1 year ago

jjmortensen commented 1 year ago

Bug description

With this in my pylintrc (which is at the root of my git repository):

[SPELLING]
spelling-dict=en_US
spelling-private-dict-file=doc/words.txt

pylint will only find the words.txt file if I'm launching it from the folder where the pylintrc file is.

Configuration

No response

Command used

pylint code.py

Pylint output

Traceback (most recent call last):
  File "/home/jensj/.local/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/jensj/.local/lib/python3.10/site-packages/pylint/__init__.py", line 35, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/home/jensj/.local/lib/python3.10/site-packages/pylint/lint/run.py", line 207, in __init__
    linter.check(args)
  File "/home/jensj/.local/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 693, in check
    with self._astroid_module_checker() as check_astroid_module:
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/home/jensj/.local/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 990, in _astroid_module_checker
    checker.open()
  File "/home/jensj/.local/lib/python3.10/site-packages/pylint/checkers/spelling.py", line 317, in open
    self.spelling_dict = enchant.DictWithPWL(
  File "/home/jensj/.local/lib/python3.10/site-packages/enchant/__init__.py", line 784, in __init__
    f = open(pwl, "wt")
FileNotFoundError: [Errno 2] No such file or directory: 'doc/words.txt'

Expected behavior

It should find the words.txt file also when I'm in a subfolder of the folder where the pylintrc file is.

Pylint version

Latest from PyPI

OS / Environment

No response

Additional dependencies

No response

Pierre-Sassoulas commented 1 year ago

Thank you for opening the issue :)

Pierre-Sassoulas commented 1 year ago

I'm looking into it. I've started a hack using os.path.isabs but it's too hot to use a desktop computer at the moment so might as well design properly to make all configuration options that use paths better :) This might not be easy to fix generically because the args parsing is generic and we parse cli args with the same function than conf file args. For CLI the point of ref should be the python interpreter dir for config file it's the config file directory. We have an interface for this function with no way to give the relpath afaik. Do you have an opinion on how to tweak the path parser to handle both cases @DanielNoord ?