Skip to content

Fix spawn fallback#89

Merged
jaraco merged 1 commit intopypa:mainfrom
isuruf:spawn
Dec 24, 2021
Merged

Fix spawn fallback#89
jaraco merged 1 commit intopypa:mainfrom
isuruf:spawn

Conversation

@isuruf
Copy link
Contributor

@isuruf isuruf commented Dec 23, 2021

Note that using unittest.mock doesn't fix the env in the subprocess.

For eg:

import unittest.mock
import os
import subprocess
with unittest.mock.patch('os.environ', {"FOO": "bar"}):
     print(os.environ["FOO"])
     subprocess.check_call("echo FOO=$FOO", shell=True)

outputs

bar
FOO=

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

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

What is the issue this change is attempting to fix? Has this code ever worked?

@isuruf
Copy link
Contributor Author

isuruf commented Dec 23, 2021

What is the issue this change is attempting to fix?

env variable has changes to PATH that is ignored because of the way mock.patch worked. This made code depending on numpy fail. See the linked issue above.

Has this code ever worked?

This code worked before 360aadc, but when the fallback was introduced in 6e92cda, this stopped working.

@jaraco
Copy link
Member

jaraco commented Dec 24, 2021

Reading through the issue reported in Numpy, the fix for #15 was incomplete (did not have the intended effect), but no one noticed because SETUPTOOLS_USE_DISTUTILS=stdlib became the default again... until earlier this week when the local copy of distutils was reintroduced by default.

@isuruf
Copy link
Contributor Author

isuruf commented Dec 24, 2021

Yep. Another reason is that for this issue to appear you need to have an environment without Visual Studio tools activated which is something done in most CI scripts and the lack of a PATH update doesn't matter.

@jaraco
Copy link
Member

jaraco commented Dec 24, 2021

Using the example, it seems that patch.dict works as expected:

import unittest.mock
import os
import subprocess
with unittest.mock.patch.dict(os.environ, {"FOO": "bar"}):
    print(os.environ["FOO"])
    subprocess.check_call("echo FOO=$FOO", shell=True)

outputs

bar
FOO=bar

@jaraco jaraco merged commit a5af364 into pypa:main Dec 24, 2021
@isuruf
Copy link
Contributor Author

isuruf commented Dec 24, 2021

Thanks

@isuruf isuruf deleted the spawn branch December 24, 2021 00:35
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.

2 participants