__init__.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright (c) 2008, 2012 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2014, 2016-2020 Claudiu Popa <pcmanticore@gmail.com>
  3. # Copyright (c) 2014 Arun Persaud <arun@nubati.net>
  4. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  5. # Copyright (c) 2018 Nick Drozd <nicholasdrozd@gmail.com>
  6. # Copyright (c) 2020-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
  7. # Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
  8. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  9. # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
  10. import os
  11. import sys
  12. from pylint.__pkginfo__ import __version__
  13. # pylint: disable=import-outside-toplevel
  14. def run_pylint():
  15. from pylint.lint import Run as PylintRun
  16. try:
  17. PylintRun(sys.argv[1:])
  18. except KeyboardInterrupt:
  19. sys.exit(1)
  20. def run_epylint():
  21. from pylint.epylint import Run as EpylintRun
  22. EpylintRun()
  23. def run_pyreverse():
  24. """run pyreverse"""
  25. from pylint.pyreverse.main import Run as PyreverseRun
  26. PyreverseRun(sys.argv[1:])
  27. def run_symilar():
  28. """run symilar"""
  29. from pylint.checkers.similar import Run as SimilarRun
  30. SimilarRun(sys.argv[1:])
  31. def modify_sys_path() -> None:
  32. """Modify sys path for execution as Python module.
  33. Strip out the current working directory from sys.path.
  34. Having the working directory in `sys.path` means that `pylint` might
  35. inadvertently import user code from modules having the same name as
  36. stdlib or pylint's own modules.
  37. CPython issue: https://bugs.python.org/issue33053
  38. - Remove the first entry. This will always be either "" or the working directory
  39. - Remove the working directory from the second and third entries
  40. if PYTHONPATH includes a ":" at the beginning or the end.
  41. https://github.com/PyCQA/pylint/issues/3636
  42. Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
  43. only be added once.
  44. - Don't remove the working directory from the rest. It will be included
  45. if pylint is installed in an editable configuration (as the last item).
  46. https://github.com/PyCQA/pylint/issues/4161
  47. """
  48. sys.path.pop(0)
  49. env_pythonpath = os.environ.get("PYTHONPATH", "")
  50. cwd = os.getcwd()
  51. if env_pythonpath.startswith(":") and env_pythonpath not in (f":{cwd}", ":."):
  52. sys.path.pop(0)
  53. elif env_pythonpath.endswith(":") and env_pythonpath not in (f"{cwd}:", ".:"):
  54. sys.path.pop(1)
  55. version = __version__
  56. __all__ = ["__version__", "version", "modify_sys_path"]