Coverage for C:\Repos\ekr-pylint\pylint\__init__.py: 42%
31 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
1# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
5from __future__ import annotations
7import os
8import sys
9from collections.abc import Sequence
10from typing import NoReturn
12from pylint.__pkginfo__ import __version__
14# pylint: disable=import-outside-toplevel
17def run_pylint(argv: Sequence[str] | None = None) -> None:
18 """Run pylint.
20 argv can be a sequence of strings normally supplied as arguments on the command line
21 """
22 from pylint.lint import Run as PylintRun
24 try:
25 PylintRun(argv or sys.argv[1:])
26 except KeyboardInterrupt:
27 sys.exit(1)
30def run_epylint(argv: Sequence[str] | None = None) -> NoReturn:
31 """Run epylint.
33 argv can be a list of strings normally supplied as arguments on the command line
34 """
35 from pylint.epylint import Run as EpylintRun
37 EpylintRun(argv)
40def run_pyreverse(argv: Sequence[str] | None = None) -> NoReturn: # type: ignore[misc]
41 """Run pyreverse.
43 argv can be a sequence of strings normally supplied as arguments on the command line
44 """
45 from pylint.pyreverse.main import Run as PyreverseRun
47 PyreverseRun(argv or sys.argv[1:])
50def run_symilar(argv: Sequence[str] | None = None) -> NoReturn:
51 """Run symilar.
53 argv can be a sequence of strings normally supplied as arguments on the command line
54 """
55 from pylint.checkers.similar import Run as SimilarRun
57 SimilarRun(argv or sys.argv[1:])
60def modify_sys_path() -> None:
61 """Modify sys path for execution as Python module.
63 Strip out the current working directory from sys.path.
64 Having the working directory in `sys.path` means that `pylint` might
65 inadvertently import user code from modules having the same name as
66 stdlib or pylint's own modules.
67 CPython issue: https://bugs.python.org/issue33053
69 - Remove the first entry. This will always be either "" or the working directory
70 - Remove the working directory from the second and third entries
71 if PYTHONPATH includes a ":" at the beginning or the end.
72 https://github.com/PyCQA/pylint/issues/3636
73 Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
74 only be added once.
75 - Don't remove the working directory from the rest. It will be included
76 if pylint is installed in an editable configuration (as the last item).
77 https://github.com/PyCQA/pylint/issues/4161
78 """
79 sys.path.pop(0)
80 env_pythonpath = os.environ.get("PYTHONPATH", "")
81 cwd = os.getcwd()
82 if env_pythonpath.startswith(":") and env_pythonpath not in (f":{cwd}", ":."):
83 sys.path.pop(0)
84 elif env_pythonpath.endswith(":") and env_pythonpath not in (f"{cwd}:", ".:"):
85 sys.path.pop(1)
88version = __version__
89__all__ = ["__version__", "version", "modify_sys_path"]