Generate start script for PyInstaller from entry point
This commit is contained in:
parent
d93fed567c
commit
020b8497c0
1 changed files with 33 additions and 16 deletions
|
@ -1,25 +1,40 @@
|
||||||
# -*- mode: python ; coding: utf-8 -*-
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (C) 2017-2020 Tobias Gruetzmacher
|
||||||
|
|
||||||
block_cipher = None
|
# Idea from
|
||||||
|
# https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Setuptools-Entry-Point,
|
||||||
|
# but with importlib
|
||||||
|
def Entrypoint(group, name, **kwargs):
|
||||||
|
import re
|
||||||
|
try:
|
||||||
|
from importlib.metadata import entry_points
|
||||||
|
except ImportError:
|
||||||
|
from importlib_metadata import entry_points
|
||||||
|
|
||||||
|
# get the entry point
|
||||||
|
eps = entry_points()[group]
|
||||||
|
ep = next(ep for ep in eps if ep.name == name)
|
||||||
|
module, attr = re.split(r'\s*:\s*', ep.value, 1)
|
||||||
|
|
||||||
|
# script name must not be a valid module name to avoid name clashes on import
|
||||||
|
script_path = os.path.join(workpath, name + '-script.py')
|
||||||
|
print("creating script for entry point", group, name)
|
||||||
|
with open(script_path, 'w') as fh:
|
||||||
|
print("import sys", file=fh)
|
||||||
|
print("import", module, file=fh)
|
||||||
|
print("sys.exit(%s.%s())" % (module, attr), file=fh)
|
||||||
|
|
||||||
|
return Analysis(
|
||||||
|
[script_path] + kwargs.get('scripts', []),
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
a = Analysis(['../dosage'],
|
a = Entrypoint('console_scripts', 'dosage')
|
||||||
pathex=['.'],
|
|
||||||
binaries=[],
|
|
||||||
datas=[],
|
|
||||||
hiddenimports=[],
|
|
||||||
hookspath=['.'],
|
|
||||||
runtime_hooks=[],
|
|
||||||
excludes=[],
|
|
||||||
win_no_prefer_redirects=False,
|
|
||||||
win_private_assemblies=False,
|
|
||||||
cipher=block_cipher,
|
|
||||||
noarchive=False)
|
|
||||||
|
|
||||||
a.binaries = [x for x in a.binaries if not x[1].lower().startswith(r'c:\windows')]
|
a.binaries = [x for x in a.binaries if not x[1].lower().startswith(r'c:\windows')]
|
||||||
|
|
||||||
pyz = PYZ(a.pure, a.zipped_data,
|
pyz = PYZ(a.pure, a.zipped_data)
|
||||||
cipher=block_cipher)
|
|
||||||
exe = EXE(pyz,
|
exe = EXE(pyz,
|
||||||
a.scripts,
|
a.scripts,
|
||||||
a.binaries,
|
a.binaries,
|
||||||
|
@ -31,3 +46,5 @@ exe = EXE(pyz,
|
||||||
upx=False,
|
upx=False,
|
||||||
runtime_tmpdir=None,
|
runtime_tmpdir=None,
|
||||||
console=True)
|
console=True)
|
||||||
|
|
||||||
|
# vim: set ft=python:
|
||||||
|
|
Loading…
Reference in a new issue