-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup.py
51 lines (36 loc) · 1.5 KB
/
setup.py
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
# mimic presence of 'setupy.py' - by reading config from pyproject.toml
# we are using ppsetuptools to read values and pass them to setup()
# however we also have to deal with idiosyncracies of ppsetuptools
# and of flint (which doesn't want to allow any entry inside
# [project.entry-points.console_scripts])
import inspect
import os
# important to import before importing ppsetuptools
import setuptools
import toml
orig_setup = setuptools.setup
def monkey(*args, **kwargs):
del kwargs["license_files"]
del kwargs["keywords"]
try:
caller_directory = os.path.abspath(os.path.dirname(inspect.stack()[1].filename))
if not os.path.exists(os.path.join(caller_directory, "pyproject.toml")):
raise
except: # noqa: E722
caller_directory = "."
with open(os.path.join(caller_directory, "pyproject.toml"), "r") as pptoml:
pyproject_toml = pptoml.read()
if isinstance(pyproject_toml, bytes):
pyproject_toml = pyproject_toml.decode("utf-8")
data = toml.loads(pyproject_toml)
if "xsetup" in data:
for key, value in data["xsetup"].items():
if key not in kwargs or not kwargs[key]:
kwargs[key] = value
print("monkey patched setuptools, going to call setup() with those kwargs:")
print("\n".join([str(x) for x in sorted(kwargs.items())]))
orig_setup(*args, **kwargs)
# raise ("To see values; for testing purposes")
setuptools.setup = monkey
import ppsetuptools # noqa: E402
ppsetuptools.setup()