2016-06-01 15:11:29 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2021-07-01 10:47:58 +00:00
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
|
2022-03-01 15:04:49 +00:00
|
|
|
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
|
2016-06-01 15:11:29 +00:00
|
|
|
|
2021-03-01 11:49:45 +00:00
|
|
|
import os
|
2012-09-14 11:25:22 +00:00
|
|
|
import sys
|
2021-12-31 09:46:31 +00:00
|
|
|
from typing import Optional, Sequence
|
2012-09-14 11:25:22 +00:00
|
|
|
|
2021-04-04 12:37:19 +00:00
|
|
|
from pylint.__pkginfo__ import __version__
|
2020-02-11 12:08:01 +00:00
|
|
|
|
|
|
|
# pylint: disable=import-outside-toplevel
|
2014-10-21 16:49:29 +00:00
|
|
|
|
2018-01-03 13:58:07 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
def run_pylint(argv: Optional[Sequence[str]] = None):
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Run pylint.
|
2021-12-30 21:11:30 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
argv can be a sequence of strings normally supplied as arguments on the command line
|
2021-12-30 21:11:30 +00:00
|
|
|
"""
|
2020-02-11 12:08:01 +00:00
|
|
|
from pylint.lint import Run as PylintRun
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2018-01-03 13:58:07 +00:00
|
|
|
try:
|
2021-12-31 09:46:31 +00:00
|
|
|
PylintRun(argv or sys.argv[1:])
|
2018-01-03 13:58:07 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(1)
|
2012-09-14 11:25:22 +00:00
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2021-12-31 12:51:30 +00:00
|
|
|
def run_epylint(argv: Optional[Sequence[str]] = None):
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Run epylint.
|
2021-12-31 12:51:30 +00:00
|
|
|
|
|
|
|
argv can be a list of strings normally supplied as arguments on the command line
|
|
|
|
"""
|
2020-02-11 12:08:01 +00:00
|
|
|
from pylint.epylint import Run as EpylintRun
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2021-12-31 12:51:30 +00:00
|
|
|
EpylintRun(argv)
|
2012-09-14 11:25:22 +00:00
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
def run_pyreverse(argv: Optional[Sequence[str]] = None):
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Run pyreverse.
|
2021-12-30 21:11:30 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
argv can be a sequence of strings normally supplied as arguments on the command line
|
2021-12-30 21:11:30 +00:00
|
|
|
"""
|
2020-02-11 12:08:01 +00:00
|
|
|
from pylint.pyreverse.main import Run as PyreverseRun
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
PyreverseRun(argv or sys.argv[1:])
|
2021-12-30 21:11:30 +00:00
|
|
|
|
2006-04-26 10:48:09 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
def run_symilar(argv: Optional[Sequence[str]] = None):
|
2022-02-10 18:30:15 +00:00
|
|
|
"""Run symilar.
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
argv can be a sequence of strings normally supplied as arguments on the command line
|
2021-12-30 21:11:30 +00:00
|
|
|
"""
|
2020-02-11 12:08:01 +00:00
|
|
|
from pylint.checkers.similar import Run as SimilarRun
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2021-12-31 09:46:31 +00:00
|
|
|
SimilarRun(argv or sys.argv[1:])
|
2020-09-15 10:43:01 +00:00
|
|
|
|
|
|
|
|
2021-03-01 11:49:45 +00:00
|
|
|
def modify_sys_path() -> None:
|
|
|
|
"""Modify sys path for execution as Python module.
|
|
|
|
|
|
|
|
Strip out the current working directory from sys.path.
|
|
|
|
Having the working directory in `sys.path` means that `pylint` might
|
|
|
|
inadvertently import user code from modules having the same name as
|
|
|
|
stdlib or pylint's own modules.
|
|
|
|
CPython issue: https://bugs.python.org/issue33053
|
|
|
|
|
|
|
|
- Remove the first entry. This will always be either "" or the working directory
|
2021-03-28 18:40:52 +00:00
|
|
|
- Remove the working directory from the second and third entries
|
|
|
|
if PYTHONPATH includes a ":" at the beginning or the end.
|
2021-03-01 11:49:45 +00:00
|
|
|
https://github.com/PyCQA/pylint/issues/3636
|
2021-03-28 18:40:52 +00:00
|
|
|
Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
|
|
|
|
only be added once.
|
2021-03-01 11:49:45 +00:00
|
|
|
- Don't remove the working directory from the rest. It will be included
|
|
|
|
if pylint is installed in an editable configuration (as the last item).
|
|
|
|
https://github.com/PyCQA/pylint/issues/4161
|
|
|
|
"""
|
2021-03-28 18:40:52 +00:00
|
|
|
sys.path.pop(0)
|
|
|
|
env_pythonpath = os.environ.get("PYTHONPATH", "")
|
|
|
|
cwd = os.getcwd()
|
|
|
|
if env_pythonpath.startswith(":") and env_pythonpath not in (f":{cwd}", ":."):
|
|
|
|
sys.path.pop(0)
|
|
|
|
elif env_pythonpath.endswith(":") and env_pythonpath not in (f"{cwd}:", ".:"):
|
|
|
|
sys.path.pop(1)
|
2021-03-01 11:49:45 +00:00
|
|
|
|
|
|
|
|
2021-04-25 07:52:45 +00:00
|
|
|
version = __version__
|
2021-06-30 21:20:08 +00:00
|
|
|
__all__ = ["__version__", "version", "modify_sys_path"]
|