/
__init__.py
58 lines (48 loc) · 1.92 KB
/
__init__.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
52
53
54
55
56
57
58
import logging
import os
import stat
import subprocess
import zc.buildout
from zc.recipe.egg.egg import Eggs
class Recipe(object):
def __init__(self, buildout, name, options):
self.buildout = buildout
self.name = name
self.options = options
self.logger = logging.getLogger(self.name)
self.make_target_dir = False
self.pip_exe = 'pip'
if self.options.get('pip', None):
self.pip_exe = self.options['pip']
def install(self):
reqs = self.options['requirements'].split()
eggs = self.options.get('eggs', '').split()
cwd = self.buildout["buildout"]["directory"]
eggs_dir = self.buildout["buildout"]["eggs-directory"]
location = os.path.join(
self.buildout["buildout"]["parts-directory"],
self.name
)
if not os.path.exists(location):
os.mkdir(location)
filename = os.path.join(location, 'requirements.txt')
req_file = open(filename, 'w')
req_file.write("\n".join(reqs))
if len(eggs) > 0:
req_file.write("\n")
req_file.write("\n".join(eggs))
req_file.flush()
arguments = [self.pip_exe, 'install', '--egg',]
arguments += ['--install-option', '--install-purelib=%s' % eggs_dir]
arguments += ['-r', 'parts/%s/requirements.txt' % self.name]
env = {'PYTHONPATH': eggs_dir, 'PATH': os.environ['PATH']}
if self.buildout['buildout']['offline'] != 'true':
subprocess.check_call(arguments, env=env)
disable_pth = self.options.get('disable-pth', 'false')
if disable_pth in ('true', '1'):
for filename in os.listdir(eggs_dir):
if filename in ('site.py', 'site.pyc', 'easy-install.pth'):
os.remove(os.path.join(eggs_dir, filename))
return self.options.created()
def update(self):
self.install()