-
Notifications
You must be signed in to change notification settings - Fork 339
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
Fixes some failing tests on windows #775
Changes from 5 commits
1a90a60
5ed01f8
64e6207
a407270
119d801
ddab4c7
6e9b385
5fe1ab4
e39cf7e
f8f6666
6cdf914
cab6b8d
3c020f5
7022990
fa24878
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,6 +591,7 @@ def apply_environ(self): | |
"interpreter before using it.") | ||
|
||
self.target_environ.update(self.manager.environ) | ||
self.target_environ = self.adjust_env_for_platform(self.target_environ) | ||
|
||
def get_output(self, style=OutputStyle.file): | ||
self.apply_environ() | ||
|
@@ -633,6 +634,7 @@ def error(self, value): | |
def subprocess(self, args, **subproc_kwargs): | ||
if self.manager: | ||
self.target_environ.update(self.manager.environ) | ||
self.target_environ = self.adjust_env_for_platform(self.target_environ) | ||
|
||
shell_mode = isinstance(args, basestring) | ||
return Popen(args, | ||
|
@@ -684,6 +686,59 @@ def get_key_token(self, key): | |
# here because the API requires it. | ||
return "${%s}" % key | ||
|
||
def adjust_env_for_platform(self, env): | ||
""" Make required platform-specific adjustments to env. | ||
""" | ||
if sys.platform.startswith('win'): | ||
env = self._add_systemroot_to_env_win32(env) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, in-place rather than copy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! |
||
return env.copy() | ||
|
||
def _add_systemroot_to_env_win32(self, env): | ||
""" Sets ``%SYSTEMROOT%`` environment variable, if not present. | ||
|
||
Args: | ||
env (dict): desired environment variables | ||
|
||
Notes: | ||
on windows, python-3.6 startup fails within an environment | ||
where it ``%PATH%`` includes python3, but ``%SYSTEMROOT%`` is not | ||
present. | ||
|
||
for example. | ||
|
||
.. code-block:: python | ||
|
||
from subprocess import Popen | ||
cmds = ['python', '--version'] | ||
|
||
# successful | ||
Popen(cmds) | ||
Popen(cmds, env={'PATH': 'C:\\Python-3.6.5', | ||
'SYSTEMROOT': 'C:\Windows'}) | ||
|
||
# failure | ||
Popen(cmds, env={'PATH': 'C:\\Python-3.6.5'}) | ||
|
||
#> Fatal Python Error: failed to get random numbers to initialize Python | ||
|
||
""" | ||
# 'SYSTEMROOT' only relevant on windows | ||
if not sys.platform.startswith('win'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this check is already done, and this is a non-public func, so this can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! thank you, I'm never sure how much I should worry about accidents. this seems like a good rule of thumb. |
||
return env | ||
# 'SYSTEMROOT' unecessary unless 'PATH' is set. | ||
if env is None: | ||
return env | ||
# leave SYSTEMROOT alone if set by user | ||
if 'SYSTEMROOT' in env: | ||
return env | ||
# not enough info to set SYSTEMROOT | ||
if 'SYSTEMROOT' not in os.environ: | ||
return env | ||
|
||
new_env = env.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above, in-place rather than copy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! |
||
new_env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] | ||
return new_env | ||
|
||
|
||
#=============================================================================== | ||
# String manipulation | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
""" | ||
from rez.packages_ import iter_package_families, iter_packages, get_package, \ | ||
create_package, get_developer_package | ||
from rez.package_resources_ import package_release_keys | ||
from rez.package_repository import create_memory_package_repository | ||
from rez.package_py_utils import expand_requirement | ||
from rez.package_repository import create_memory_package_repository | ||
from rez.package_resources_ import package_release_keys | ||
from rez.tests.util import TestBase, TempdirMixin | ||
from rez.utils.formatting import PackageRequest | ||
from rez.utils.platform_ import platform_ | ||
from rez.utils.sourcecode import SourceCode | ||
import unittest | ||
from rez.vendor.version.version import Version | ||
|
@@ -119,21 +120,27 @@ def test_2(self): | |
|
||
def test_3(self): | ||
"""check package contents.""" | ||
def _format_platformpath(path): | ||
""" `FileSystemPackageRepository` lower-cases paths for case-insensitive filesystems. | ||
""" | ||
if platform_.has_case_sensitive_filesystem: | ||
return path | ||
return path.lower() | ||
|
||
# a py-based package | ||
package = get_package("versioned", "3.0") | ||
expected_data = dict( | ||
name="versioned", | ||
version=Version("3.0"), | ||
base=os.path.join(self.py_packages_path, "versioned", "3.0"), | ||
base=_format_platformpath(os.path.join(self.py_packages_path, "versioned", "3.0")), | ||
commands=SourceCode('env.PATH.append("{root}/bin")')) | ||
data = package.validated_data() | ||
self.assertDictEqual(data, expected_data) | ||
|
||
# a yaml-based package | ||
package = get_package("versioned", "2.0") | ||
expected_uri = os.path.join(self.yaml_packages_path, | ||
"versioned", "2.0", "package.yaml") | ||
expected_uri = _format_platformpath(os.path.join(self.yaml_packages_path, | ||
"versioned", "2.0", "package.yaml")) | ||
self.assertEqual(package.uri, expected_uri) | ||
|
||
# a py-based package with late binding attribute functions | ||
|
@@ -142,7 +149,7 @@ def test_3(self): | |
|
||
# a 'combined' type package | ||
package = get_package("multi", "1.0") | ||
expected_uri = os.path.join(self.yaml_packages_path, "multi.yaml<1.0>") | ||
expected_uri = _format_platformpath(os.path.join(self.yaml_packages_path, "multi.yaml<1.0>")) | ||
self.assertEqual(package.uri, expected_uri) | ||
expected_data = dict( | ||
name="multi", | ||
|
@@ -153,7 +160,7 @@ def test_3(self): | |
|
||
# a 'combined' type package, with version overrides | ||
package = get_package("multi", "1.1") | ||
expected_uri = os.path.join(self.yaml_packages_path, "multi.yaml<1.1>") | ||
expected_uri = _format_platformpath(os.path.join(self.yaml_packages_path, "multi.yaml<1.1>")) | ||
self.assertEqual(package.uri, expected_uri) | ||
expected_data = dict( | ||
name="multi", | ||
|
@@ -164,7 +171,7 @@ def test_3(self): | |
|
||
# check that visibility of 'combined' packages is correct | ||
package = get_package("multi", "2.0") | ||
expected_uri = os.path.join(self.py_packages_path, "multi.py<2.0>") | ||
expected_uri = _format_platformpath(os.path.join(self.py_packages_path, "multi.py<2.0>")) | ||
self.assertEqual(package.uri, expected_uri) | ||
|
||
def test_4(self): | ||
|
@@ -309,11 +316,17 @@ def preprocess(this, data): | |
|
||
def test_6(self): | ||
"""test variant iteration.""" | ||
# ensure that differing case doesn't get interpreted as different repos | ||
# on case-insensitive platforms (eg windows) | ||
base = os.path.join(self.py_packages_path, "variants_py", "2.0") | ||
if not platform_.has_case_sensitive_filesystem: | ||
base = base.lower() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this sort of code already exists in another place, see https://github.com/nerdvegas/rez/blob/master/src/rezplugins/package_repository/filesystem.py#L473. It would be good to add a utility function to rez.utils.filesystem, something like so:
I think this may also fix a potential bug currently, where two package repositories could be the same, but if one uses symlinks to the same path on disk, rez will think they are two different repos. To give some context: The lower() is there to fix a previous bug that was caused by differing cases of the same path, on windows (non-case-sensitive), which then led rez to believe that there were two different packages that were in fact the same package ('foo' vs 'Foo' for eg). At least if there's just the one utility function, this can be documented in one place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, I agree with this idea. The I wrote There are some frustrating pain points here for testing however. # python-3.6.5, windows-10
ntpath.realpath('/a/b/c') #>> 'C:\\a\\b\\c'
posixpath.realpath('C:/a/b/c') #>> 'C:\\Users\\willjp/C:/a/b/c'
# python-3.7.4, windows-10
ntpath.realpath('/a/b/c') #>> 'C:\\a\\b\\c'
posixpath.realpath('C:/a/b/c') #>> 'C:\\Users\willjp/C:/a/b/c' # python-3.7.4, linux
ntpath.realpath('/a/b/c') #>> '\\a\\b\\c'
posixpath.realpath('/a/b/c') #>> '/a/b/c' This change in python is not represented in the docs, so I am uncertain when they were introduced: https://docs.python.org/3/library/os.path.html?highlight=realpath#os.path.realpath |
||
|
||
expected_data = dict( | ||
name="variants_py", | ||
version=Version("2.0"), | ||
description="package with variants", | ||
base=os.path.join(self.py_packages_path, "variants_py", "2.0"), | ||
base=base, | ||
requires=[PackageRequest("python-2.7")], | ||
commands=SourceCode('env.PATH.append("{root}/bin")')) | ||
|
||
|
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.
I would drop the return value, and avoid the unnecessary dict copy.
adjust_env_for_platform
should just alter self.target_environ in-place, asthe previous code already doesThere 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.
fixed!