Skip to content

Commit

Permalink
Merge pull request #3 from dalthviz/add_pylint_patch
Browse files Browse the repository at this point in the history
PR: Add Pylint modified __ini__.py commenting sys.path modifications
  • Loading branch information
ccordoba12 authored Jul 21, 2021
2 parents 7b4ac94 + bb40db1 commit 4d5a5fa
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ List of resources:
* `jedi` compiled subprocess `__main__.py` patched version
* NSIS files and plugins to build the installer with a context menu entry that can be used with `pynsist`
* `tkinter` binaries and files
* `pylint` `modify_sys_path` funtion from `__init__.py` modification
80 changes: 80 additions & 0 deletions pylint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) 2008, 2012 LOGILAB S.A. (Paris, FRANCE) <[email protected]>
# Copyright (c) 2014, 2016-2020 Claudiu Popa <[email protected]>
# Copyright (c) 2014 Arun Persaud <[email protected]>
# Copyright (c) 2015 Ionel Cristian Maries <[email protected]>
# Copyright (c) 2018 Nick Drozd <[email protected]>
# Copyright (c) 2020-2021 Pierre Sassoulas <[email protected]>
# Copyright (c) 2021 Marc Mueller <[email protected]>

# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/master/LICENSE

import os
import sys

from pylint.__pkginfo__ import __version__

# pylint: disable=import-outside-toplevel


def run_pylint():
from pylint.lint import Run as PylintRun

try:
PylintRun(sys.argv[1:])
except KeyboardInterrupt:
sys.exit(1)


def run_epylint():
from pylint.epylint import Run as EpylintRun

EpylintRun()


def run_pyreverse():
"""run pyreverse"""
from pylint.pyreverse.main import Run as PyreverseRun

PyreverseRun(sys.argv[1:])


def run_symilar():
"""run symilar"""
from pylint.checkers.similar import Run as SimilarRun

SimilarRun(sys.argv[1:])


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
- Remove the working directory from the second and third entries
if PYTHONPATH includes a ":" at the beginning or the end.
https://github.com/PyCQA/pylint/issues/3636
Don't remove it if PYTHONPATH contains the cwd or '.' as the entry will
only be added once.
- 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
"""
# NOTE: Commented out line to be able to run pylint with the default interpreter
# of the Spyder installation
# 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)


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

0 comments on commit 4d5a5fa

Please sign in to comment.