2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2008, 2012 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
|
2020-04-27 09:04:14 +00:00
|
|
|
# Copyright (c) 2014, 2016-2020 Claudiu Popa <pcmanticore@gmail.com>
|
2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2014 Arun Persaud <arun@nubati.net>
|
|
|
|
# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2018 Nick Drozd <nicholasdrozd@gmail.com>
|
2021-04-24 19:26:46 +00:00
|
|
|
# Copyright (c) 2020-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
|
2021-03-29 18:59:59 +00:00
|
|
|
# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
|
2016-07-22 21:22:28 +00:00
|
|
|
|
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
|
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-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
|
|
|
|
2012-09-14 11:25:22 +00:00
|
|
|
def run_pylint():
|
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:
|
2019-10-09 07:43:38 +00:00
|
|
|
PylintRun(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
|
|
|
|
2012-09-14 11:25:22 +00:00
|
|
|
def run_epylint():
|
2020-02-11 12:08:01 +00:00
|
|
|
from pylint.epylint import Run as EpylintRun
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2019-10-09 07:43:38 +00:00
|
|
|
EpylintRun()
|
2012-09-14 11:25:22 +00:00
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2012-09-14 11:25:22 +00:00
|
|
|
def run_pyreverse():
|
|
|
|
"""run pyreverse"""
|
2020-02-11 12:08:01 +00:00
|
|
|
from pylint.pyreverse.main import Run as PyreverseRun
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2019-10-09 07:43:38 +00:00
|
|
|
PyreverseRun(sys.argv[1:])
|
2006-04-26 10:48:09 +00:00
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2012-09-14 11:25:22 +00:00
|
|
|
def run_symilar():
|
|
|
|
"""run symilar"""
|
2020-02-11 12:08:01 +00:00
|
|
|
from pylint.checkers.similar import Run as SimilarRun
|
2018-09-16 15:33:50 +00:00
|
|
|
|
2019-10-09 07:43:38 +00:00
|
|
|
SimilarRun(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"]
|