Method: pylint.modify_sys_path
Calls: 14, Exceptions: 0, Paths: 4Back
Path 1: 10 calls (0.71)
1def modify_sys_path() -> None:
2 """Modify sys path for execution as Python module.
3
4 Strip out the current working directory from sys.path.
5 Having the working directory in `sys.path` means that `pylint` might
6 inadvertently import user code from modules having the same name as
7 stdlib or pylint's own modules.
8 CPython issue: https://bugs.python.org/issue33053
9
10 - Remove the first entry. This will always be either "" or the working directory
11 - Remove the working directory from the second and third entries
12 if PYTHONPATH includes a ":" at the beginning or the end.
13 https://github.com/PyCQA/pylint/issues/3636
14 Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
15 only be added once.
16 - Don't remove the working directory from the rest. It will be included
17 if pylint is installed in an editable configuration (as the last item).
18 https://github.com/PyCQA/pylint/issues/4161
19 """
20 cwd = os.getcwd()
21 if sys.path[0] in ("", ".", cwd):
22 sys.path.pop(0)
23 env_pythonpath = os.environ.get("PYTHONPATH", "")
24 if env_pythonpath.startswith(":") and env_pythonpath not in (f":{cwd}", ":."):
25 sys.path.pop(0)
26 elif env_pythonpath.endswith(":") and env_pythonpath not in (f"{cwd}:", ".:"):
27 sys.path.pop(1)
Path 2: 2 calls (0.14)
1def modify_sys_path() -> None:
2 """Modify sys path for execution as Python module.
3
4 Strip out the current working directory from sys.path.
5 Having the working directory in `sys.path` means that `pylint` might
6 inadvertently import user code from modules having the same name as
7 stdlib or pylint's own modules.
8 CPython issue: https://bugs.python.org/issue33053
9
10 - Remove the first entry. This will always be either "" or the working directory
11 - Remove the working directory from the second and third entries
12 if PYTHONPATH includes a ":" at the beginning or the end.
13 https://github.com/PyCQA/pylint/issues/3636
14 Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
15 only be added once.
16 - Don't remove the working directory from the rest. It will be included
17 if pylint is installed in an editable configuration (as the last item).
18 https://github.com/PyCQA/pylint/issues/4161
19 """
20 cwd = os.getcwd()
21 if sys.path[0] in ("", ".", cwd):
22 sys.path.pop(0)
23 env_pythonpath = os.environ.get("PYTHONPATH", "")
24 if env_pythonpath.startswith(":") and env_pythonpath not in (f":{cwd}", ":."):
25 sys.path.pop(0)
26 elif env_pythonpath.endswith(":") and env_pythonpath not in (f"{cwd}:", ".:"):
27 sys.path.pop(1)
Path 3: 1 calls (0.07)
1def modify_sys_path() -> None:
2 """Modify sys path for execution as Python module.
3
4 Strip out the current working directory from sys.path.
5 Having the working directory in `sys.path` means that `pylint` might
6 inadvertently import user code from modules having the same name as
7 stdlib or pylint's own modules.
8 CPython issue: https://bugs.python.org/issue33053
9
10 - Remove the first entry. This will always be either "" or the working directory
11 - Remove the working directory from the second and third entries
12 if PYTHONPATH includes a ":" at the beginning or the end.
13 https://github.com/PyCQA/pylint/issues/3636
14 Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
15 only be added once.
16 - Don't remove the working directory from the rest. It will be included
17 if pylint is installed in an editable configuration (as the last item).
18 https://github.com/PyCQA/pylint/issues/4161
19 """
20 cwd = os.getcwd()
21 if sys.path[0] in ("", ".", cwd):
22 sys.path.pop(0)
23 env_pythonpath = os.environ.get("PYTHONPATH", "")
24 if env_pythonpath.startswith(":") and env_pythonpath not in (f":{cwd}", ":."):
25 sys.path.pop(0)
26 elif env_pythonpath.endswith(":") and env_pythonpath not in (f"{cwd}:", ".:"):
27 sys.path.pop(1)
Path 4: 1 calls (0.07)
1def modify_sys_path() -> None:
2 """Modify sys path for execution as Python module.
3
4 Strip out the current working directory from sys.path.
5 Having the working directory in `sys.path` means that `pylint` might
6 inadvertently import user code from modules having the same name as
7 stdlib or pylint's own modules.
8 CPython issue: https://bugs.python.org/issue33053
9
10 - Remove the first entry. This will always be either "" or the working directory
11 - Remove the working directory from the second and third entries
12 if PYTHONPATH includes a ":" at the beginning or the end.
13 https://github.com/PyCQA/pylint/issues/3636
14 Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
15 only be added once.
16 - Don't remove the working directory from the rest. It will be included
17 if pylint is installed in an editable configuration (as the last item).
18 https://github.com/PyCQA/pylint/issues/4161
19 """
20 cwd = os.getcwd()
21 if sys.path[0] in ("", ".", cwd):
22 sys.path.pop(0)
23 env_pythonpath = os.environ.get("PYTHONPATH", "")
24 if env_pythonpath.startswith(":") and env_pythonpath not in (f":{cwd}", ":."):
25 sys.path.pop(0)
26 elif env_pythonpath.endswith(":") and env_pythonpath not in (f"{cwd}:", ".:"):
27 sys.path.pop(1)