Skip to content

Commit

Permalink
copy dependent files relative to source module file (#494)
Browse files Browse the repository at this point in the history
* copy dependent files relative to source module file

* relative source only over absolute path

* this patch is only for linux
  • Loading branch information
marcelotduarte authored and anthony-tuininga committed Dec 7, 2019
1 parent b8c01af commit bc376ce
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cx_Freeze/freezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _AddVersionResource(self, exe):
stamp(fileName, versionInfo)

def _CopyFile(self, source, target, copyDependentFiles,
includeMode = False):
includeMode = False, relativeSource = False):
normalizedSource = os.path.normcase(os.path.normpath(source))
normalizedTarget = os.path.normcase(os.path.normpath(target))
if normalizedTarget in self.filesCopied:
Expand All @@ -166,9 +166,16 @@ def _CopyFile(self, source, target, copyDependentFiles,
# to allow to set relative reference
if sys.platform == 'darwin':
targetDir = self.targetDir
sourceDir = os.path.dirname(source)
for source in self._GetDependentFiles(source):
target = os.path.join(targetDir, os.path.basename(source))
self._CopyFile(source, target, copyDependentFiles)
if relativeSource and os.path.isabs(source) and\
os.path.commonpath((source, sourceDir)) == sourceDir:
relative = os.path.relpath(source, sourceDir)
target = os.path.join(targetDir, relative)
else:
target = os.path.join(targetDir, os.path.basename(source))
self._CopyFile(source, target, copyDependentFiles,
relativeSource=relativeSource)

def _CreateDirectory(self, path):
if not os.path.isdir(path):
Expand Down Expand Up @@ -616,7 +623,8 @@ def _WriteModules(self, fileName, finder):
if module.parent is not None:
path = os.pathsep.join([origPath] + module.parent.path)
os.environ["PATH"] = path
self._CopyFile(module.file, target, copyDependentFiles = True)
self._CopyFile(module.file, target, copyDependentFiles=True,
relativeSource=(sys.platform == "linux"))
finally:
os.environ["PATH"] = origPath

Expand Down

0 comments on commit bc376ce

Please sign in to comment.