|
| 1 | +# -*- mode: python -*- |
| 2 | + |
| 3 | +import platform |
| 4 | + |
| 5 | +block_cipher = None |
| 6 | + |
| 7 | + |
| 8 | +def Entrypoint(dist, group, name, **kwargs): |
| 9 | + import pkg_resources |
| 10 | + |
| 11 | + # get toplevel packages of distribution from metadata |
| 12 | + def get_toplevel(dist): |
| 13 | + distribution = pkg_resources.get_distribution(dist) |
| 14 | + if distribution.has_metadata('top_level.txt'): |
| 15 | + return list(distribution.get_metadata('top_level.txt').split()) |
| 16 | + else: |
| 17 | + return [] |
| 18 | + |
| 19 | + kwargs.setdefault('hiddenimports', []) |
| 20 | + packages = [] |
| 21 | + for distribution in kwargs['hiddenimports']: |
| 22 | + packages += get_toplevel(distribution) |
| 23 | + |
| 24 | + kwargs.setdefault('pathex', []) |
| 25 | + # get the entry point |
| 26 | + ep = pkg_resources.get_entry_info(dist, group, name) |
| 27 | + # insert path of the egg at the verify front of the search path |
| 28 | + kwargs['pathex'] = [ep.dist.location] + kwargs['pathex'] |
| 29 | + # script name must not be a valid module name to avoid name clashes on import |
| 30 | + script_path = os.path.join(workpath, name + '-script.py') |
| 31 | + print("creating script for entry point", dist, group, name) |
| 32 | + with open(script_path, 'w') as fh: |
| 33 | + print("import", ep.module_name, file=fh) |
| 34 | + print("%s.%s()" % (ep.module_name, '.'.join(ep.attrs)), file=fh) |
| 35 | + for package in packages: |
| 36 | + print("import", package, file=fh) |
| 37 | + |
| 38 | + return Analysis( |
| 39 | + [script_path] + kwargs.get('scripts', []), |
| 40 | + **kwargs |
| 41 | + ) |
| 42 | + |
| 43 | + |
| 44 | +a = Entrypoint('iotedgehubdev', 'console_scripts', 'iotedgehubdev') |
| 45 | + |
| 46 | +pyz = PYZ(a.pure, a.zipped_data, |
| 47 | + cipher=block_cipher) |
| 48 | + |
| 49 | +# exe = EXE(pyz, |
| 50 | +# a.scripts, |
| 51 | +# [], |
| 52 | +# exclude_binaries=True, |
| 53 | +# name='setup', |
| 54 | +# debug=False, |
| 55 | +# bootloader_ignore_signals=False, |
| 56 | +# strip=False, |
| 57 | +# upx=True, |
| 58 | +# console=True ) |
| 59 | +# coll = COLLECT(exe, |
| 60 | +# a.binaries, |
| 61 | +# a.zipfiles, |
| 62 | +# a.datas, |
| 63 | +# strip=False, |
| 64 | +# upx=True, |
| 65 | +# name='setup') |
| 66 | + |
| 67 | +exe = EXE(pyz, |
| 68 | + a.scripts, |
| 69 | + a.binaries, |
| 70 | + a.zipfiles, |
| 71 | + a.datas, |
| 72 | + name='iotedgehubdev-{0}-X86_64'.format(platform.system()), |
| 73 | + debug=False, |
| 74 | + strip=False, |
| 75 | + upx=True, |
| 76 | + runtime_tmpdir=None, |
| 77 | + console=True) |
0 commit comments