Skip to content
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

DM-12454: Be explicit about which python pytest-xdist uses. #45

Merged
merged 1 commit into from Nov 1, 2017

Conversation

jdswinbank
Copy link
Contributor

When starting a Python interpreter, it will add its own site-packages
directory to sys.path if it's not already there.

Normally, this works fine. However, when the same interpreter can be accessed
through two different paths, it can cause both of those paths to be added to
sys.path.

For example, in our standard, newinstall.sh provided, environment, we might
refer to the Python interpreter either as:

/ssd/lsstsw/stack3_20171021/python/miniconda3-4.3.21/bin/python

or as:

/ssd/lsstsw/stack3_20171021/python/current/bin/python

If we include the former's site packages directory corresponding to the former
on our $PYTHONPATH and then run it, everything is fine. Howver, if we instead
invoke the latter, it will insert a new site-packages directory,
corresponding to that provided by Miniconda, to our sys.path. It doesn't add
it at the end of the list of paths, but rather inserts it at some (arbitrary?)
point in the middle.

This then causes confusion when there are packages installed by Miniconda
which shadow packages provided by EUPS: even if the latter are set up, they
can be overriden by this new entry on sys.path. Confusion ensues.

Here, we explicitly normalize the path used by pytest-xdist to invoke Python
so that we avoid this problem.

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems annoyingly unclear but I guess we have to live with it. Is this only caused by the soft link? Is the real problem that pytest-xdist is installed in the miniconda tree as well? Is this a bug in xdist itself?

@@ -237,7 +237,9 @@ def runPythonTests(self, pyList):
njobs = self._env.GetOption("num_jobs")
print("Running pytest with {} process{}".format(njobs, "" if njobs == 1 else "es"))
if njobs > 1:
interpreter = interpreter + " --max-slave-restart=0 -n {}".format(njobs)
executable = os.path.realpath(sys.executable)
interpreter = (interpreter +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this deserves a comment.

@jdswinbank
Copy link
Contributor Author

jdswinbank commented Nov 1, 2017

Is this only caused by the soft link?

It's certainly most directly caused by the soft link — I think any time you are invoking multiple copies of the same Python interpreter which you'd like to have the same environment but which you're calling by different names, you're asking for trouble.

Is the real problem that pytest-xdist is installed in the miniconda tree as well?

That's the immediate issue that brought this to our attention. However, it's a general problem: any package that gets installed into the Conda environment might leak through and override the EUPS-provided equivalent.

Is this a bug in xdist itself?

I don't think that correct behaviour is adequately well specified to say. I don't have spare cycles to spend thinking about it further.

When starting a Python interpreter, it will add its own site-packages
directory to sys.path if it's not already there.

Normally, this works fine. However, when the same interpreter can be accessed
through two different paths, it can cause both of those paths to be added to
sys.path.

For example, in our standard, newinstall.sh provided, environment, we might
refer to the Python interpreter either as:

  /ssd/lsstsw/stack3_20171021/python/miniconda3-4.3.21/bin/python

or as:

  /ssd/lsstsw/stack3_20171021/python/current/bin/python

If we include the former's site packages directory corresponding to the former
on our $PYTHONPATH and then run it, everything is fine. Howver, if we instead
invoke the latter, it will insert a new site-packages directory,
corresponding to that provided by Miniconda, to our sys.path. It doesn't add
it at the end of the list of paths, but rather inserts it at some (arbitrary?)
point in the middle.

This then causes confusion when there are packages installed by Miniconda
which shadow packages provided by EUPS: even if the latter are set up, they
can be overriden by this new entry on sys.path. Confusion ensues.

Here, we explicitly normalize the path used by pytest-xdist to invoke Python
so that we avoid this problem.
@jdswinbank jdswinbank merged commit 03b688b into master Nov 1, 2017
@ktlim ktlim deleted the tickets/DM-12454 branch August 25, 2018 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants