-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
49 lines (36 loc) · 1.29 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
import configparser
import subprocess
import sys
import importlib
from contextlib import contextmanager
from setuptools import setup
@contextmanager
def substituted_config():
with open('setup.cfg', 'r') as cfg:
template_cfg = cfg.read()
try:
from envsubst import envsubst
substituted_config_text = envsubst(template_cfg)
with open('setup.cfg', 'w') as cfg:
cfg.write(substituted_config_text)
yield template_cfg, substituted_config_text
finally:
with open('setup.cfg', 'w') as cfg:
cfg.write(template_cfg)
def install(*packages: str):
subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', *packages])
for p in packages:
p = p.rstrip('=<>0123456789.~^*')
globals()[p] = importlib.import_module(p)
if __name__ == '__main__':
install('toml')
import toml
with open('pyproject.toml') as project_toml:
toml_requirements = toml.load(project_toml)
install(*toml_requirements['build-system']['requires'])
with substituted_config() as (template, substituted):
configs = configparser.ConfigParser()
configs.read_string(substituted)
requirements = configs['options']['install_requires'].split('\n')[1:]
install(*requirements)
setup()