Skip to content

Commit c6c2d27

Browse files
committed
Revert "_sigh_, removing this code is easiest, not crucial enough to warrant a rewrite"
This reverts commit 78cb203.
1 parent 7cdd43a commit c6c2d27

File tree

4 files changed

+112
-23
lines changed

4 files changed

+112
-23
lines changed

src/rez/rex.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def apply_environ(self):
606606
"interpreter before using it.")
607607

608608
self.target_environ.update(self.manager.environ)
609-
self._adjust_env_for_platform(self.target_environ)
609+
self.adjust_env_for_platform(self.target_environ)
610610

611611
def get_output(self, style=OutputStyle.file):
612612
self.apply_environ()
@@ -649,8 +649,7 @@ def error(self, value):
649649
def subprocess(self, args, **subproc_kwargs):
650650
if self.manager:
651651
self.target_environ.update(self.manager.environ)
652-
653-
self._adjust_env_for_platform(self.target_environ)
652+
self.adjust_env_for_platform(self.target_environ)
654653

655654
shell_mode = isinstance(args, basestring)
656655
return Popen(args,
@@ -702,26 +701,53 @@ def get_key_token(self, key):
702701
# here because the API requires it.
703702
return "${%s}" % key
704703

705-
@classmethod
706-
def _adjust_env_for_platform(cls, env):
707-
""" Make adjustments to env specific to a platform
704+
def adjust_env_for_platform(self, env):
705+
""" Make required platform-specific adjustments to env.
708706
"""
709-
if platform_.name != "windows":
710-
return
707+
if platform_.name == "windows":
708+
self._add_systemroot_to_env_win32(env)
711709

712-
"""
713-
Set SYSTEMROOT if not already present in env.
710+
def _add_systemroot_to_env_win32(self, env):
711+
r""" Sets ``%SYSTEMROOT%`` environment variable, if not present
712+
in :py:attr:`target_environ` .
713+
714+
Args:
715+
env (dict): desired environment variables
716+
717+
Notes:
718+
on windows, python-3.6 startup fails within an environment
719+
where it ``%PATH%`` includes python3, but ``%SYSTEMROOT%`` is not
720+
present.
721+
722+
for example.
723+
724+
.. code-block:: python
725+
726+
from subprocess import Popen
727+
cmds = ['python', '--version']
728+
729+
# successful
730+
Popen(cmds)
731+
Popen(cmds, env={'PATH': 'C:\\Python-3.6.5',
732+
'SYSTEMROOT': 'C:\Windows'})
733+
734+
# failure
735+
Popen(cmds, env={'PATH': 'C:\\Python-3.6.5'})
736+
737+
#> Fatal Python Error: failed to get random numbers to initialize Python
714738
715-
On windows, python-3.6 startup fails within an environment
716-
when PATH includes python3, but SYSTEMROOT is not present.
717739
"""
718-
if "SYSTEMROOT" in env:
740+
# 'SYSTEMROOT' unecessary unless 'PATH' is set.
741+
if env is None:
742+
return
743+
# leave SYSTEMROOT alone if set by user
744+
if 'SYSTEMROOT' in env:
745+
return
746+
# not enough info to set SYSTEMROOT
747+
if 'SYSTEMROOT' not in os.environ:
719748
return
720749

721-
if "SYSTEMROOT" not in os.environ:
722-
return # not enough info to set SYSTEMROOT
723-
724-
env["SYSTEMROOT"] = os.environ["SYSTEMROOT"]
750+
env['SYSTEMROOT'] = os.environ['SYSTEMROOT']
725751

726752

727753
#===============================================================================

src/rez/tests/test_utils.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
unit tests for 'utils.filesystem' module
3+
"""
4+
import os
5+
from rez.tests.util import TestBase
6+
from rez.utils import filesystem
7+
from rez.utils.platform_ import Platform, platform_
8+
9+
10+
class TestCanonicalPath(TestBase):
11+
class CaseSensitivePlatform(Platform):
12+
@property
13+
def has_case_sensitive_filesystem(self):
14+
return True
15+
16+
class CaseInsensitivePlatform(Platform):
17+
@property
18+
def has_case_sensitive_filesystem(self):
19+
return False
20+
21+
def test_win32_case_insensitive(self):
22+
if platform_.name != 'windows':
23+
self.skipTest('on linux/macos, `os.path.realpath()` treats windows '
24+
'abspaths as relpaths, and prepends `os.getcwd()`')
25+
platform = self.CaseInsensitivePlatform()
26+
path = filesystem.canonical_path('C:\\dir\\File.txt', platform)
27+
expects = 'c:\\dir\\file.txt'.replace('\\', os.sep)
28+
self.assertEqual(path, expects)
29+
30+
def test_unix_case_sensistive_platform(self):
31+
if platform_.name == 'windows':
32+
self.skipTest('on windows, `os.path.realpath()` treats unix abspaths '
33+
'as relpaths, and prepends `os.getcwd()`')
34+
platform = self.CaseSensitivePlatform()
35+
path = filesystem.canonical_path('/a/b/File.txt', platform)
36+
expects = '/a/b/File.txt'.replace('\\', os.sep)
37+
self.assertEqual(path, expects)
38+
39+
def test_unix_case_insensistive_platform(self):
40+
if platform_.name == 'windows':
41+
self.skipTest('on windows, `os.path.realpath()` treats unix abspaths '
42+
'as relpaths, and prepends `os.getcwd()`')
43+
platform = self.CaseInsensitivePlatform()
44+
path = filesystem.canonical_path('/a/b/File.txt', platform)
45+
expects = '/a/b/file.txt'.replace('\\', os.sep)
46+
self.assertEqual(path, expects)
47+
48+
49+
# Copyright 2013-2016 Allan Johns.
50+
#
51+
# This library is free software: you can redistribute it and/or
52+
# modify it under the terms of the GNU Lesser General Public
53+
# License as published by the Free Software Foundation, either
54+
# version 3 of the License, or (at your option) any later version.
55+
#
56+
# This library is distributed in the hope that it will be useful,
57+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
58+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
59+
# Lesser General Public License for more details.
60+
#
61+
# You should have received a copy of the GNU Lesser General Public
62+
# License along with this library. If not, see <http://www.gnu.org/licenses/>.

src/rez/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def __init__(self, label, max):
2828
def __del__(self):
2929
if self.close_file:
3030
self.file.close()
31+
if hasattr(Bar, '__del__'):
32+
Bar.__del__(self)
3133

3234

3335
def dedup(seq):

src/rezplugins/package_repository/filesystem.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,12 @@ def __init__(self, location, resource_pool, disable_memcache=None,
490490
disable_memcache (bool): Don't use memcache memcache if True
491491
disable_pkg_ignore (bool): If True, .ignore* files have no effect
492492
"""
493-
super(FileSystemPackageRepository, self).__init__(
494-
# ensure that differing case doesn't get interpreted as different repos
495-
# on case-insensitive platforms (eg windows)
496-
location=canonical_path(location, platform_),
497493

498-
resource_pool=resource_pool
499-
)
494+
# ensure that differing case doesn't get interpreted as different repos
495+
# on case-insensitive platforms (eg windows)
496+
location = canonical_path(location, platform_)
497+
498+
super(FileSystemPackageRepository, self).__init__(location, resource_pool)
500499

501500
# load settings optionally defined in a settings.yaml
502501
local_settings = {}

0 commit comments

Comments
 (0)