Skip to content

Commit

Permalink
bindepend: update PR pyinstaller#3735 to reflect discussion on github
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Corbelli committed Sep 25, 2019
1 parent 0752181 commit 6e9796a
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions PyInstaller/depend/bindepend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ctypes.util
import collections
import functools
import itertools
import multiprocessing
import os
import platform
Expand Down Expand Up @@ -47,9 +48,6 @@
import pefile
# Do not load all the directories information from the PE file
pefile.fast_load = True
is_win_10 = (platform.win32_ver()[0] == '10')
else:
is_win_10 = False


def getfullnameof(mod, xtrapath=None):
Expand Down Expand Up @@ -231,44 +229,43 @@ def Dependencies(lTOC, xtrapath=None, manifest=None, redirects=None):

if is_win:
# Search for required assemblies and add them to the TOC
paths = [path for name, path, typ in lTOC]
paths = set(os.path.normpath(os.path.normcase(path)) for name, path, typ in lTOC)
assemblies = pool.map(
functools.partial(getAssemblyFiles, manifest=manifest, redirects=redirects),
paths
)
paths)
# getAssemblyFiles returns a list of tuples, so assemblies is a
# list of list of tuples
for assembly in assemblies:
for ftocnm, fn in assembly:
lTOC.append((ftocnm, fn, 'BINARY'))
for ftocnm, fn in itertools.chain(assemblies):
lTOC.append((ftocnm, fn, 'BINARY'))

dataset = collections.deque([(name, path, typ) for (name, path, typ) in lTOC])
dataset = collections.deque((name, path, typ) for (name, path, typ) in lTOC)
while True:
# Breakdown the dataset in chunks as big as the chosen number of processes
# instead of just feeding the whole dataset into process pool
# so that we can keep the "seen" cache in main process only
chunk = []
while (len(chunk) < processes) and len(dataset):
(name, path, typ) = dataset.pop()
if name.upper() in seen:
continue
chunk.append(path)
while len(chunk) < processes and len(dataset):
name, path, typ = dataset.pop()
name = name.upper()
if name not in seen:
chunk.append(path)
seen.add(name)

if not chunk:
break # From while True, no more data

imports = pool.map(
functools.partial(selectImports, xtrapath=xtrapath),
chunk
)
chunk)
# selectImports returns a list of pairs, so 'imports' is
# a list of lists of pairs
for item_dependencies in imports:
for (lib, npth) in item_dependencies:
if lib.upper() in seen or npth.upper() in seen:
continue
seen.add(npth.upper())
lTOC.append((lib, npth, 'BINARY'))
for lib, npth in itertools.chain(imports):
npth = os.path.normpath(os.path.normcase(npth))
if lib in seen or npth in seen:
continue
seen.add(lib)
seen.add(npth)
lTOC.append((lib, npth, 'BINARY'))

return lTOC

Expand Down Expand Up @@ -435,6 +432,7 @@ def getAssemblyFiles(pth, manifest=None, redirects=None):
Return a list of pairs (name, fullpath)
"""
logger.debug("Analyzing %s for assembly dependencies", pth)
rv = []
if manifest:
_depNames = set(dep.name for dep in manifest.dependentAssemblies)
Expand Down Expand Up @@ -529,6 +527,7 @@ def selectImports(pth, xtrapath=None):
Return a list of pairs (name, fullpath)
"""
logger.debug("Analyzing %s for binary dependencies", pth)
rv = []
if xtrapath is None:
xtrapath = [os.path.dirname(pth)]
Expand Down

0 comments on commit 6e9796a

Please sign in to comment.