forked from gregtap/mayan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_setup.py
executable file
·51 lines (37 loc) · 1.4 KB
/
generate_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
#!/usr/bin/env python
from __future__ import unicode_literals
import os
import django
from django.conf import settings
from django.template import Template, Context
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
REQUIREMENTS_FILE = 'requirements.txt'
SETUP_TEMPLATE = 'setup.py.tmpl'
def get_requirements(base_directory, filename):
result = []
with open(os.path.join(base_directory, filename)) as file_object:
for line in file_object:
if line.startswith('-r'):
line = line.split('\n')[0][3:]
directory, filename = os.path.split(line)
result.extend(
get_requirements(
base_directory=os.path.join(base_directory, directory), filename=filename
)
)
elif not line.startswith('\n'):
result.append(line.split('\n')[0])
return result
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mayan.settings')
django.setup()
requirements = get_requirements(
base_directory=BASE_DIR, filename=REQUIREMENTS_FILE
)
with open(SETUP_TEMPLATE) as file_object:
template = file_object.read()
result = Template(template).render(
context=Context({'requirements': requirements})
)
with open('setup.py', 'w') as file_object:
file_object.write(result)