diff options
Diffstat (limited to 'pylint/lint/utils.py')
-rw-r--r-- | pylint/lint/utils.py | 102 |
1 files changed, 53 insertions, 49 deletions
diff --git a/pylint/lint/utils.py b/pylint/lint/utils.py index 98fb8087a..a7fbfd0bc 100644 --- a/pylint/lint/utils.py +++ b/pylint/lint/utils.py @@ -1,19 +1,18 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations import contextlib +import platform import sys import traceback -import warnings from collections.abc import Iterator, Sequence from datetime import datetime from pathlib import Path -from pylint.config import PYLINT_HOME -from pylint.lint.expand_modules import discover_package_path +from pylint.constants import PYLINT_HOME, full_version def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) -> Path: @@ -26,18 +25,20 @@ def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) -> if not issue_template_path.exists(): template = """\ First, please verify that the bug is not already filled: -https://github.com/PyCQA/pylint/issues/ +https://github.com/pylint-dev/pylint/issues/ -Then create a new crash issue: -https://github.com/PyCQA/pylint/issues/new?assignees=&labels=crash%2Cneeds+triage&template=BUG-REPORT.yml +Then create a new issue: +https://github.com/pylint-dev/pylint/issues/new?labels=Crash 💥%2CNeeds triage 📥 -""" - template += f"""\ +""" + template += f""" Issue title: Crash ``{ex}`` (if possible, be more specific about what made pylint crash) -Content: -When parsing the following file: + +### Bug description + +When parsing the following ``a.py``: <!-- If sharing the code is not an option, please state so, @@ -48,11 +49,49 @@ When parsing the following file: {file_content} ``` -pylint crashed with a ``{ex.__class__.__name__}`` and with the following stacktrace: +### Command used + +```shell +pylint a.py ``` + +### Pylint output + +<details open> + <summary> + pylint crashed with a ``{ex.__class__.__name__}`` and with the following stacktrace: + </summary> + +```python """ template += traceback.format_exc() - template += "```\n" + template += f""" +``` + + +</details> + +### Expected behavior + +No crash. + +### Pylint version + +```shell +{full_version} +``` + +### OS / Environment + +{sys.platform} ({platform.system()}) + +### Additional dependencies + +<!-- +Please remove this part if you're not using any of +your dependencies in the example. + --> +""" try: with open(issue_template_path, "a", encoding="utf8") as f: f.write(template) @@ -73,19 +112,6 @@ def get_fatal_error_message(filepath: str, issue_template_path: Path) -> str: ) -def _patch_sys_path(args: Sequence[str]) -> list[str]: - # TODO: Remove deprecated function - warnings.warn( - "_patch_sys_path has been deprecated because it relies on auto-magic package path " - "discovery which is implemented by get_python_path that is deprecated. " - "Use _augment_sys_path and pass additional sys.path entries as an argument obtained from " - "discover_package_path.", - DeprecationWarning, - stacklevel=2, - ) - return _augment_sys_path([discover_package_path(arg, []) for arg in args]) - - def _augment_sys_path(additional_paths: Sequence[str]) -> list[str]: original = list(sys.path) changes = [] @@ -100,28 +126,6 @@ def _augment_sys_path(additional_paths: Sequence[str]) -> list[str]: @contextlib.contextmanager -def fix_import_path(args: Sequence[str]) -> Iterator[None]: - """Prepare 'sys.path' for running the linter checks. - - Within this context, each of the given arguments is importable. - Paths are added to 'sys.path' in corresponding order to the arguments. - We avoid adding duplicate directories to sys.path. - `sys.path` is reset to its original value upon exiting this context. - """ - # TODO: Remove deprecated function - warnings.warn( - "fix_import_path has been deprecated because it relies on auto-magic package path " - "discovery which is implemented by get_python_path that is deprecated. " - "Use augmented_sys_path and pass additional sys.path entries as an argument obtained from " - "discover_package_path.", - DeprecationWarning, - stacklevel=2, - ) - with augmented_sys_path([discover_package_path(arg, []) for arg in args]): - yield - - -@contextlib.contextmanager def augmented_sys_path(additional_paths: Sequence[str]) -> Iterator[None]: """Augment 'sys.path' by adding non-existent entries from additional_paths.""" original = _augment_sys_path(additional_paths) |