File: dosage.spec

package info (click to toggle)
dosage 3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,400 kB
  • sloc: python: 12,703; sh: 55; makefile: 6
file content (52 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: © 2017 Tobias Gruetzmacher

import re
from importlib import metadata

# Idea from
# https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Setuptools-Entry-Point,
# but with importlib
def entrypoint(group, name, **kwargs):
    # get the entry point
    eps = metadata.entry_points()
    if 'select' in dir(eps):
        # modern
        ep = eps.select(group=group)[name]
    else:
        # legacy (pre-3.10)
        ep = next(ep for ep in eps[group] if ep.name == name)
    module, attr = re.split(r'\s*:\s*', ep.value, maxsplit=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, mode='w', encoding='utf-8') as fh:
        print("import sys", file=fh)
        print("import", module, file=fh)
        print(f"sys.exit({module}.{attr}())", file=fh)

    return Analysis(
        [script_path] + kwargs.get('scripts', []),
        **kwargs
    )


a = entrypoint('console_scripts', 'dosage')

a.binaries = [x for x in a.binaries if not x[1].lower().startswith(r'c:\windows')]

pyz = PYZ(a.pure, a.zipped_data)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='dosage',
          debug=False,
          strip=False,
          upx=False,
          runtime_tmpdir=None,
          console=True)

# vim: set ft=python: