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

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 

4 

5from __future__ import annotations 

6 

7import os 

8import sys 

9from collections.abc import Sequence 

10from typing import NoReturn 

11 

12from pylint.__pkginfo__ import __version__ 

13 

14# pylint: disable=import-outside-toplevel 

15 

16 

17def run_pylint(argv: Sequence[str] | None = None) -> None: 

18 """Run pylint. 

19 

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 

23 

24 try: 

25 PylintRun(argv or sys.argv[1:]) 

26 except KeyboardInterrupt: 

27 sys.exit(1) 

28 

29 

30def run_epylint(argv: Sequence[str] | None = None) -> NoReturn: 

31 """Run epylint. 

32 

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 

36 

37 EpylintRun(argv) 

38 

39 

40def run_pyreverse(argv: Sequence[str] | None = None) -> NoReturn: # type: ignore[misc] 

41 """Run pyreverse. 

42 

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 

46 

47 PyreverseRun(argv or sys.argv[1:]) 

48 

49 

50def run_symilar(argv: Sequence[str] | None = None) -> NoReturn: 

51 """Run symilar. 

52 

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 

56 

57 SimilarRun(argv or sys.argv[1:]) 

58 

59 

60def modify_sys_path() -> None: 

61 """Modify sys path for execution as Python module. 

62 

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 

68 

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) 

86 

87 

88version = __version__ 

89__all__ = ["__version__", "version", "modify_sys_path"]