stfc / pre-commit-hooks

Custom pre-commit hooks for use within our projects
https://stfc.github.io/pre-commit-hooks/
MIT License
2 stars 0 forks source link

pylint error checking throws exeption due to deprecation warning #14

Open RobFirth opened 1 year ago

RobFirth commented 1 year ago

Description

Running the check-pylint-import-errors hook throws deprecation error.

Details

The following error:

Check for pylint import errors............................................Failed
- hook id: check-pylint-import-errors
- exit code: 1

/Users/berto/PycharmProjects/autoredact/autoredact_develop/.venv/lib/python3.9/site-packages/hooks/check_pylint_import_errors.py:59: DeprecationWarning: 'epylint' will be removed in pylint 3.0, use https://github.com/emacsorphanage/pylint instead.
  pylint_stdout, pylint_err = lint.py_run(pylint_opts, return_std=True)
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.13_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.9/3.9.13_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/berto/PycharmProjects/autoredact/autoredact_develop/.venv/lib/python3.9/site-packages/hooks/check_pylint_import_errors.py", line 95, in <module>
    sys.exit(main())
  File "/Users/berto/PycharmProjects/autoredact/autoredact_develop/.venv/lib/python3.9/site-packages/hooks/check_pylint_import_errors.py", line 91, in main
    return CheckPylintImportErrors().run()
  File "/Users/berto/PycharmProjects/autoredact/autoredact_develop/.venv/lib/python3.9/site-packages/hooks/check_pylint_import_errors.py", line 63, in run
    raise Exception(pylint_err.getvalue())
Exception: <string>:1: DeprecationWarning: 'epylint' will be removed in pylint 3.0, use https://github.com/emacsorphanage/pylint instead.

Seems to be linked to v2.16 of pylint. https://pylint.pycqa.org/en/latest/whatsnew/2/2.16/index.html, with epylint migrated to https://github.com/emacsorphanage/pylint.

Why are we using the emacs version of pylint anyway?

ah ok, so it's because we can then capture the output:

https://pylint.pycqa.org/en/v2.13.9/user_guide/run.html#:~:text=To%20silently%20run%20Pylint%20on,C0114%27%2C%20return_std%3DTrue

RobFirth commented 1 year ago

Looks like we should migrate over to the new(er) API - https://pylint.pycqa.org/en/v2.16.0/development_guide/api/pylint.html

Expect this to look something like:

from io import StringIO

from pylint.lint import Run
from pylint.reporters.text import TextReporter

pylint_output = StringIO()  # Custom open stream
reporter = TextReporter(pylint_output)

Run(args=["autoredactdevelop", "--rcfile='pyproject.toml'", "--output-format=json"], reporter=reporter, exit=False)

print(pylint_output.getvalue())  # Retrieve and print the text report
RobFirth commented 1 year ago

I've opened an issue on the pylint repo - https://github.com/PyCQA/pylint/issues/8164