Skip to content

Commit

Permalink
Revert "_sigh_, removing this code is easiest, not crucial enough to …
Browse files Browse the repository at this point in the history
…warrant a rewrite"

This reverts commit 78cb203.
  • Loading branch information
nerdvegas committed Nov 9, 2021
1 parent 7cdd43a commit c6c2d27
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 23 deletions.
60 changes: 43 additions & 17 deletions src/rez/rex.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def apply_environ(self):
"interpreter before using it.")

self.target_environ.update(self.manager.environ)
self._adjust_env_for_platform(self.target_environ)
self.adjust_env_for_platform(self.target_environ)

def get_output(self, style=OutputStyle.file):
self.apply_environ()
Expand Down Expand Up @@ -649,8 +649,7 @@ def error(self, value):
def subprocess(self, args, **subproc_kwargs):
if self.manager:
self.target_environ.update(self.manager.environ)

self._adjust_env_for_platform(self.target_environ)
self.adjust_env_for_platform(self.target_environ)

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

@classmethod
def _adjust_env_for_platform(cls, env):
""" Make adjustments to env specific to a platform
def adjust_env_for_platform(self, env):
""" Make required platform-specific adjustments to env.
"""
if platform_.name != "windows":
return
if platform_.name == "windows":
self._add_systemroot_to_env_win32(env)

"""
Set SYSTEMROOT if not already present in env.
def _add_systemroot_to_env_win32(self, env):
r""" Sets ``%SYSTEMROOT%`` environment variable, if not present
in :py:attr:`target_environ` .
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
On windows, python-3.6 startup fails within an environment
when PATH includes python3, but SYSTEMROOT is not present.
"""
if "SYSTEMROOT" in env:
# 'SYSTEMROOT' unecessary unless 'PATH' is set.
if env is None:
return
# leave SYSTEMROOT alone if set by user
if 'SYSTEMROOT' in env:
return
# not enough info to set SYSTEMROOT
if 'SYSTEMROOT' not in os.environ:
return

if "SYSTEMROOT" not in os.environ:
return # not enough info to set SYSTEMROOT

env["SYSTEMROOT"] = os.environ["SYSTEMROOT"]
env['SYSTEMROOT'] = os.environ['SYSTEMROOT']


#===============================================================================
Expand Down
62 changes: 62 additions & 0 deletions src/rez/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
unit tests for 'utils.filesystem' module
"""
import os
from rez.tests.util import TestBase
from rez.utils import filesystem
from rez.utils.platform_ import Platform, platform_


class TestCanonicalPath(TestBase):
class CaseSensitivePlatform(Platform):
@property
def has_case_sensitive_filesystem(self):
return True

class CaseInsensitivePlatform(Platform):
@property
def has_case_sensitive_filesystem(self):
return False

def test_win32_case_insensitive(self):
if platform_.name != 'windows':
self.skipTest('on linux/macos, `os.path.realpath()` treats windows '
'abspaths as relpaths, and prepends `os.getcwd()`')
platform = self.CaseInsensitivePlatform()
path = filesystem.canonical_path('C:\\dir\\File.txt', platform)
expects = 'c:\\dir\\file.txt'.replace('\\', os.sep)
self.assertEqual(path, expects)

def test_unix_case_sensistive_platform(self):
if platform_.name == 'windows':
self.skipTest('on windows, `os.path.realpath()` treats unix abspaths '
'as relpaths, and prepends `os.getcwd()`')
platform = self.CaseSensitivePlatform()
path = filesystem.canonical_path('/a/b/File.txt', platform)
expects = '/a/b/File.txt'.replace('\\', os.sep)
self.assertEqual(path, expects)

def test_unix_case_insensistive_platform(self):
if platform_.name == 'windows':
self.skipTest('on windows, `os.path.realpath()` treats unix abspaths '
'as relpaths, and prepends `os.getcwd()`')
platform = self.CaseInsensitivePlatform()
path = filesystem.canonical_path('/a/b/File.txt', platform)
expects = '/a/b/file.txt'.replace('\\', os.sep)
self.assertEqual(path, expects)


# Copyright 2013-2016 Allan Johns.
#
# This library is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
2 changes: 2 additions & 0 deletions src/rez/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __init__(self, label, max):
def __del__(self):
if self.close_file:
self.file.close()
if hasattr(Bar, '__del__'):
Bar.__del__(self)


def dedup(seq):
Expand Down
11 changes: 5 additions & 6 deletions src/rezplugins/package_repository/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,12 @@ def __init__(self, location, resource_pool, disable_memcache=None,
disable_memcache (bool): Don't use memcache memcache if True
disable_pkg_ignore (bool): If True, .ignore* files have no effect
"""
super(FileSystemPackageRepository, self).__init__(
# ensure that differing case doesn't get interpreted as different repos
# on case-insensitive platforms (eg windows)
location=canonical_path(location, platform_),

resource_pool=resource_pool
)
# ensure that differing case doesn't get interpreted as different repos
# on case-insensitive platforms (eg windows)
location = canonical_path(location, platform_)

super(FileSystemPackageRepository, self).__init__(location, resource_pool)

# load settings optionally defined in a settings.yaml
local_settings = {}
Expand Down

0 comments on commit c6c2d27

Please sign in to comment.