-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix regression with sys.path filter #4258
Conversation
cc: @stanislavlevin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable. I don't see where the launching of the plugin is tested, could we even test that ? Maybe an integration test patching sys.argv
?
Tests don't pass for me with FROM python:3.9
RUN git clone --depth 1 https://github.com/PyCQA/pylint
WORKDIR pylint
RUN git fetch origin pull/4258/head:syspath && git checkout syspath
RUN pip install astroid isort pytest mccabe pytest-benchmark
RUN bash -c "PYTHONPATH=:$(pwd) pytest -vv"
|
@Pierre-Sassoulas I'm currently working on it 😅 |
Oups, sorry ! Do you mind if I create an integration test (I think I can create a new file that should not conflict) ? |
Go for it, but I think I already have one. @staticmethod
def test_import_plugin_from_local_directory_if_pythonpath_cwd(tmpdir):
p_plugin = tmpdir / "plugin.py"
p_plugin.write("# Some plugin content")
with tmpdir.as_cwd():
orig_pythonpath = os.environ.get("PYTHONPATH")
os.environ["PYTHONPATH"] = "."
process = subprocess.run(
[
sys.executable,
"-m",
"pylint",
"--load-plugins",
"plugin",
],
cwd=str(tmpdir),
stderr=subprocess.PIPE,
)
assert "AttributeError: module 'plugin' has no attribute 'register'" \
in process.stderr.decode()
if orig_pythonpath:
os.environ["PYTHONPATH"] = orig_pythonpath
else:
del os.environ["PYTHONPATH"] Added in |
Ho, my bad I did not notice ! |
I haven't pushed it yet. So you couldn't have known. |
I called mine |
@Pierre-Sassoulas If thats ok with you, I would like to push my changes instead of yours (I would take care of that). That way I could also address the |
As far as I can tell it works now. @sbraz You need to add |
@sbraz If that doesn't work for you, we would have to take another look. We just merged it now, since we are planning a new release soon (later today / tomorrow) and it should (hopefully) be a working state already. |
Yeah that won't work for me because in the Gentoo ebuild, we need to load stuff from |
Do you have an idea on how we could fix this for you @sbraz ? We have a lot of chores to do before being able to release, if there is a simple solution we can wait. |
I have one last idea. I wanted to use os.environ["PYTHONPATH"] = f"{(orig_pythonpath or '').strip(':')}:." originally, but that caused the windows tests to fail. orig_pythonpath = os.environ.get("PYTHONPATH")
if sys.platform == 'win32':
os.environ["PYTHONPATH"] = "."
else:
os.environ["PYTHONPATH"] = f"{(orig_pythonpath or '').strip(':')}:." Not pretty, but it might just work. |
I don't think it's worth the hassle to be honest. Thanks a lot for your help. |
It's just a test, so if it would help maybe someone else uses it too. |
* Fix regression with sys.path filter
Steps
doc/whatsnew/<current release.rst>
.Description
This MR fixes the regression with
sys.path
filter by checkingPYTHONPATH
before removing any additional entries.This should fix the new issue (#4252) without undoing the previous one.
This should ideally be included in
2.7.3
Type of Changes
Related Issue
Closes #4252
Followup to
#4153
#4164
--
CC: @sbraz, @Pierre-Sassoulas