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

Remove erroneous environ commands #1584

Closed
wants to merge 2 commits into from

Conversation

pganssle
Copy link
Member

In #1559, @RajdeepRao pointed out that these code blocks were in many tests here.

environ.update() mutates a list in place and returns None, so all of these blocks with os.environ.copy().update(...) are creating an ephemeral copy of the environment dictionary, updating it, and then it's deleted since nothing holds a reference to it.

Since these were no-ops anyway, I've removed them. I believe the env fixture defined in this file should be used instead.

Pull Request Checklist

  • News fragment added in changelog.d. See documentation for details

environ = os.environ.copy().update(
HOME=env.paths['home'],
)

Copy link
Member

Choose a reason for hiding this comment

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

Don't you need to remove the references in calls to environment.run_setup_py(..., env=environ) too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed.

`environ.update()` mutates a list in place and returns `None`, so all of
these blocks with `os.environ.copy().update(...)` are creating an
ephemeral copy of the environment dictionary, updating it, and then it's
deleted since nothing holds a reference to it.

Since these were no-ops anyway, I've removed them.
@pganssle
Copy link
Member Author

Hm, I guess there's setuptools.tests.environment.

It's a bit confusing how the env fixture is named in this case, we may want to rename that.

Also, presumably this was intended to do a specific thing. Maybe we should be setting env['HOME'] in setuptools.tests.environment? I don't really know what problem this was originally intended to solve.

@pganssle
Copy link
Member Author

Actually, I think I can actually just easily make this work as intended, though it's disturbing that this has been broken for 4 years (and that everyone's just been cargo-culting this the whole time - almost all the instances of this are from blind copy-pasting).

Not sure how to test that the fixed version actually works, though. Probably seeing if some configuration in my home directory doesn't get picked up after it's fixed?

@pganssle
Copy link
Member Author

pganssle commented Nov 10, 2018

Interestingly, the tests actually fail if env is set up "correctly".

@jaraco Looks like this commit causes the problems because it changes everything over to assuming that the egg-info files are created in the cwd.

I think I can fix it by looking for all the egg-info files relative to env.paths['egg-base'], but did you want them to be in the local directory deliberately, even when HOME is set to be somewhere else?

@jaraco
Copy link
Member

jaraco commented Nov 11, 2018

I think I can fix it by looking for all the egg-info files relative to env.paths['egg-base'], but did you want them to be in the local directory deliberately, even when HOME is set to be somewhere else?

I did not have any particular expectations about the tests. I do agree that it's perhaps surprising and undesirable to be generating files in the cwd unless that directory was explicitly set to some temporary directory for the duration of the test. Since the egg_info command does normally generate files in the current directory, I would sort-of expect for tests to use that pattern (except for tests that specifically override where egg-info is generated).

I don't understand the meaning/purpose of HOME. I would expect HOME only to affect the reading of ~/.pydistutils.cfg... and not the location of a generated egg-info.

I think I can fix it by looking for all the egg-info files relative to env.paths['egg-base'].

Perhaps that's the right thing to do, but it feels like a workaround for earlier bad behavior. I'm not seeing the problem clearly, though. Feel free to do whatever you think is right.

@pganssle
Copy link
Member Author

I do agree that it's perhaps surprising and undesirable to be generating files in the cwd unless that directory was explicitly set to some temporary directory for the duration of the test.

This is indeed already happening. The pytest fixture tmpdir_cwd does this. I think maybe the env fixture came about before this. Hard for me to tell.

I don't understand the meaning/purpose of HOME. I would expect HOME only to affect the reading of ~/.pydistutils.cfg... and not the location of a generated egg-info.

I also don't understand why this is happening, I assumed it was deliberate because you created an egg-base folder. If that's not deliberate, it may be an undetected bug. I think we should probably have HOME set to something other than the user's HOME, but probably we should figure out why it's moving the eggs before we enshrine it in the tests.

Perhaps that's the right thing to do, but it feels like a workaround for earlier bad behavior. I'm not seeing the problem clearly, though. Feel free to do whatever you think is right.

I am just trying to do some software archaeology. I was surprised by the current behavior and wanted to check with you to see if you had any better information about you removed _find_egg_info_files, or why egg-base was one of the paths on env. If you don't, I'll try and track down why the HOME variable is changing where eggs get installed and see if it's a bug or a feature.

@jaraco
Copy link
Member

jaraco commented Jan 27, 2019

I don't have any better information, sorry (and sorry for the delayed response).

@pganssle pganssle closed this Feb 7, 2019
@pganssle pganssle deleted the environ_update branch February 7, 2019 14:38
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.

3 participants