Skip to content

Commit

Permalink
Merge branch 'davidlatwe-issue_934-update-include-module'
Browse files Browse the repository at this point in the history
  • Loading branch information
ajohns committed Aug 24, 2020
2 parents f81c721 + 068cf51 commit 2897a42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
34 changes: 22 additions & 12 deletions src/rez/utils/sourcecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def __init__(self):
self.modules = {}

def load_module(self, name, package):
from hashlib import sha1
from rez.config import config # avoiding circular import
from rez.developer_package import DeveloperPackage

Expand All @@ -303,8 +304,6 @@ def load_module(self, name, package):
# copied into package payload) location.
#
if isinstance(package, DeveloperPackage):
from hashlib import sha1

# load sourcefile from original location
path = config.package_definition_python_path
filepath = os.path.join(path, "%s.py" % name)
Expand All @@ -313,20 +312,31 @@ def load_module(self, name, package):
return None

with open(filepath, "rb") as f:
txt = f.read().strip()
hash_str = sha1(f.read().strip()).hexdigest()

hash_str = sha1(txt).hexdigest()
else:
# load sourcefile that's been copied into package install payload
path = os.path.join(package.base, self.include_modules_subpath)
pathname = os.path.join(path, "%s-*.py" % name)

pathnames = glob(pathname)
if not pathnames:
return None

filepath = pathnames[0]
hash_str = filepath.rsplit('-', 1)[-1].split('.', 1)[0]
pathname = os.path.join(path, "%s.py" % name)
hashname = os.path.join(path, "%s.sha1" % name)

if os.path.isfile(pathname) and os.path.isfile(hashname):
with open(hashname, "r") as f:
hash_str = f.readline()
filepath = pathname

else:
# Fallback for backward compat
pathname = os.path.join(path, "%s-*.py" % name)
hashnames = glob(pathname)
if not hashnames:
return None

filepath = hashnames[0]
hash_str = filepath.rsplit('-', 1)[-1].split('.', 1)[0]
# End, for details of backward compat,
# see https://github.com/nerdvegas/rez/issues/934
# and https://github.com/nerdvegas/rez/pull/935

module = self.modules.get(hash_str)
if module is not None:
Expand Down
10 changes: 6 additions & 4 deletions src/rezplugins/build_process/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,14 @@ def _install_include_modules(self, install_path):

with open(filepath, "rb") as f:
txt = f.read().strip()

uuid = sha1(txt).hexdigest()
dest_filepath = os.path.join(path, "%s-%s.py" % (name, uuid))

if not os.path.exists(dest_filepath):
shutil.copy(filepath, dest_filepath)
dest_filepath = os.path.join(path, "%s.py" % name)
shutil.copy(filepath, dest_filepath) # overwrite if exists

sha1_filepath = os.path.join(path, "%s.sha1" % name)
with open(sha1_filepath, "w") as f: # overwrite if exists
f.write(uuid)

def _rmtree(self, path):
try:
Expand Down

0 comments on commit 2897a42

Please sign in to comment.