-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_module_versions.py
37 lines (35 loc) · 1.65 KB
/
update_module_versions.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
import os
import fileinput
def get_module_versions():
# gets the required module versions from `min_requirements.txt` file
curdir = os.path.dirname(os.path.abspath(__file__))
for submodule in [['light_python_wrapper', '+light_python_wrapper'],
['euphonic_sqw_models', 'min_requirements.txt']]:
if not os.path.isfile(os.path.join(curdir, *submodule)):
from update_dependencies import update_submodules
update_submodules(submodule[0])
req_file = os.path.join(curdir, 'euphonic_sqw_models', 'min_requirements.txt')
with open(req_file, 'r') as minreq:
reqstrs = minreq.read().splitlines()
reqmods = []
for req in reqstrs:
reqspl = req.split('>=')
if len(reqspl) == 1 and 'euphonic' in req:
# Euphonic is a special case, can define 'euphonic>ver'
# which means Euphonic is between versions
reqspl = req.split('>')
if len(reqspl) == 1:
raise ValueError(
f'Unexpected module version {req} in {req_file}')
reqmods += [req.strip() for req in reqspl]
return reqmods
def update_module_versions():
curdir = os.path.dirname(os.path.abspath(__file__))
verstrs = [f"'{verstr}'" for verstr in get_module_versions()]
vercell = f"{{{', '.join(verstrs)}}}"
with fileinput.FileInput(curdir+'/+euphonic/private/required_modules.m',
inplace=True) as reqmod:
for line in reqmod:
# FileInput redirect stdout to the file, for inplace replacement;
# end='' means don't add extra newlines
print(line.replace('{}', vercell), end='')