| author | ymh <ymh.work@gmail.com> |
| Sat, 05 Apr 2014 03:49:56 +0200 | |
| changeset 165 | 64aae3fee9d5 |
| parent 113 | c05567404888 |
| child 170 | 3c73250693b9 |
| permissions | -rw-r--r-- |
| 0 | 1 |
import sys |
2 |
import os |
|
3 |
import os.path |
|
4 |
import shutil |
|
5 |
import tarfile |
|
6 |
import zipfile |
|
7 |
import urllib |
|
8 |
import platform |
|
9 |
import patch |
|
10 |
import struct |
|
11 |
import glob |
|
12 |
import re |
|
13 |
||
14 |
join = os.path.join |
|
15 |
system_str = platform.system() |
|
16 |
||
17 |
URLS = { |
|
18 |
#'': {'setup': '', 'url':'', 'local':''}, |
|
19 |
'DISTRIBUTE': {'setup': 'distribute', 'url':'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.34.tar.gz', 'local':"distribute-0.6.34.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
| 165 | 20 |
'DJANGO': {'setup': 'django', 'url': 'https://github.com/django/django/archive/1.6.2.tar.gz', 'local':"django-1.6.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
21 |
'SIX' : {'setup':'six', 'url':'https://pypi.python.org/packages/source/s/six/six-1.6.1.tar.gz', 'local': 'six-1.6.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
22 |
'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/archive/1.3.3.tar.gz', 'local':"django-extensions-1.3.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
23 |
'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-0.8.4.tar.gz', 'local':"south-0.8.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
24 |
'RDFLIB' : {'setup':'rdflib', 'url':'https://github.com/RDFLib/rdflib/archive/4.1.1.tar.gz', 'local': 'rdflib-4.1.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
25 |
'REQUESTS': {'setup': 'requests', 'url':'https://github.com/kennethreitz/requests/archive/v2.2.1.tar.gz', 'local':'requests-2.2.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
26 |
'SIMPLEJSON': {'setup': 'simplejson','url':'https://github.com/simplejson/simplejson/archive/v3.4.0.tar.gz', 'local': 'simplejson-3.4.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
27 |
'ISODATE': {'setup': 'isodate','url':'https://pypi.python.org/packages/source/i/isodate/isodate-0.5.0.tar.gz', 'local': 'isodate-0.5.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
28 |
'PYPARSING': {'setup': 'pyparsing','url':'https://pypi.python.org/packages/source/p/pyparsing/pyparsing-2.0.1.tar.gz', 'local': 'pyparsing-2.0.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
| 0 | 29 |
'SPARQLWRAPPER': {'setup': 'sparqlwrapper','url':'http://downloads.sourceforge.net/project/sparql-wrapper/sparql-wrapper-python/1.5.2/SPARQLWrapper-1.5.2.tar.gz', 'local': 'SPARQLWrapper-1.5.2.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
| 165 | 30 |
'HTML5LIB': {'setup': 'html5lib','url':'https://github.com/html5lib/html5lib-python/archive/0.999.tar.gz', 'local': 'html5lib-0.999.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
31 |
'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.2.tar.gz', 'local':"psycopg2-2.5.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
|
2
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
32 |
'DEFUSEDXML': {'setup': 'defusedxml','url': 'https://pypi.python.org/packages/source/d/defusedxml/defusedxml-0.4.1.tar.gz', 'local':"defusedxml-0.4.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
| 165 | 33 |
'DJANGO-CORS-HEADERS': {'setup': 'django-cors-headers','url': 'https://pypi.python.org/packages/source/d/django-cors-headers/django-cors-headers-0.12.tar.gz', 'local':"django-cors-headers-0.12.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
2
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
34 |
'DJANGO-FILTER': {'setup': 'django-filter','url': 'https://github.com/alex/django-filter/archive/v0.7.tar.gz', 'local':"django-filter-0.7.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
| 165 | 35 |
'DJANGO-REST-FRAMEWORK': {'setup': 'djangorestframework','url': 'https://pypi.python.org/packages/source/d/djangorestframework/djangorestframework-2.3.13.tar.gz', 'local':"djangorestframework-2.3.13.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
36 |
'MARKDOWN': {'setup': 'markdown','url': 'http://pypi.python.org/packages/source/M/Markdown/Markdown-2.4.tar.gz', 'local':"Markdown-2.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
|
2
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
37 |
'WSGIREF': {'setup': 'wsgiref','url': 'https://pypi.python.org/packages/source/w/wsgiref/wsgiref-0.1.2.zip', 'local':"wsgiref-0.1.2.zip", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
89
diff
changeset
|
38 |
'HAYSTACK': {'setup': 'django-haystack','url': 'https://github.com/toastdriven/django-haystack/archive/v2.1.0.tar.gz', 'local':"django-haystack-2.1.0.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
| 165 | 39 |
'PYELASTICSEARCH': {'setup': 'pyelasticsearch','url': 'https://pypi.python.org/packages/source/p/pyelasticsearch/pyelasticsearch-0.6.1.tar.gz', 'local':"pyelasticsearch-0.6.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
40 |
'WHOOSH': {'setup': 'whoosh','url': 'https://pypi.python.org/packages/source/W/Whoosh/Whoosh-2.5.7.tar.gz', 'local':"Whoosh-2.5.7.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
| 0 | 41 |
} |
42 |
||
43 |
class ResourcesEnv(object): |
|
44 |
||
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
45 |
def __init__(self, src_base, run_base, urls, normal_installs): |
| 0 | 46 |
self.src_base = src_base |
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
47 |
self.run_base = run_base |
| 0 | 48 |
self.URLS = {} |
49 |
self.__init_url(urls) |
|
50 |
self.NORMAL_INSTALL = normal_installs |
|
51 |
||
52 |
def get_src_base_path(self, fpath): |
|
53 |
return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/") |
|
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
54 |
|
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
55 |
def get_run_res_base_path(self, fpath): |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
56 |
return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/") |
| 0 | 57 |
|
58 |
def __add_package_def(self, key, dict): |
|
59 |
self.URLS[key] = dict |
|
60 |
||
61 |
def __init_url(self, urls): |
|
62 |
for key, url_dict in urls.items(): |
|
63 |
url_dict_copy = url_dict.copy() |
|
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
64 |
if url_dict.get('install', {}).get('method','pip') == 'pip-req': |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
65 |
get_base_path = self.get_run_res_base_path |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
66 |
else: |
| 165 | 67 |
get_base_path = self.get_src_base_path |
| 0 | 68 |
if not url_dict['url'].startswith("http://"): |
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
69 |
url_dict_copy['url'] = get_base_path(url_dict['url']) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
70 |
url_dict_copy['local'] = get_base_path(url_dict['local']) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
71 |
|
| 0 | 72 |
self.__add_package_def(key, url_dict_copy ) |
73 |
||
74 |
def ensure_dir(dir, logger): |
|
75 |
logger.notify('Check directory %s' % dir) |
|
76 |
if not os.path.exists(dir): |
|
77 |
logger.notify('Creating directory %s' % dir) |
|
78 |
os.makedirs(dir) |
|
79 |
||
80 |
def extend_parser(parser): |
|
81 |
parser.add_option( |
|
82 |
'--index-url', |
|
83 |
metavar='INDEX_URL', |
|
84 |
dest='index_url', |
|
85 |
default='http://pypi.python.org/simple/', |
|
86 |
help='base URL of Python Package Index') |
|
87 |
parser.add_option( |
|
88 |
'--type-install', |
|
89 |
metavar='type_install', |
|
90 |
dest='type_install', |
|
91 |
help='type install : local, url, setup - default : local') |
|
92 |
parser.add_option( |
|
93 |
'--ignore-packages', |
|
94 |
metavar='ignore_packages', |
|
95 |
dest='ignore_packages', |
|
96 |
default=None, |
|
97 |
help='list of comma separated keys for package to ignore') |
|
98 |
||
99 |
def install_psycopg2(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
100 |
psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
101 |
shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
102 |
#extract psycopg2 |
|
103 |
zf = zipfile.ZipFile(psycopg2_src) |
|
104 |
psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
105 |
zf.extractall(psycopg2_base_path) |
|
106 |
zf.close() |
|
107 |
||
108 |
psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
109 |
shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2'))) |
|
110 |
shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.4.5-py2.7.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'site-packages'))) |
|
111 |
||
112 |
||
113 |
def install_mysql(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
114 |
||
115 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]] |
|
116 |
if option_str : |
|
117 |
args.insert(4,option_str) |
|
118 |
call_subprocess(args, |
|
119 |
cwd=os.path.abspath(tmp_dir), |
|
120 |
filter_stdout=filter_python_develop, |
|
121 |
show_stdout=True, |
|
122 |
extra_env=extra_env) |
|
123 |
||
124 |
mysqlconfig_output = [] |
|
125 |
||
126 |
call_subprocess(['mysql_config', '--libmysqld-libs'], |
|
127 |
cwd=os.path.abspath(tmp_dir), |
|
128 |
filter_stdout=lambda line: mysqlconfig_output.append(line), |
|
129 |
show_stdout=True) |
|
130 |
||
131 |
mysqlconfig_output = "".join(mysqlconfig_output) |
|
132 |
m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output) |
|
133 |
if m: |
|
134 |
repdylibpath = m.group(1) |
|
135 |
else: |
|
136 |
repdylibpath = '/usr/local/mysql/lib' |
|
137 |
||
138 |
dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib") |
|
139 |
def key_func(s): |
|
140 |
m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s) |
|
141 |
if m: |
|
142 |
return int(m.group(1)) |
|
143 |
else: |
|
144 |
return sys.maxint |
|
145 |
dyliblist.sort(key=key_func) |
|
146 |
||
147 |
if dyliblist: |
|
148 |
dylibpath = dyliblist[0] |
|
149 |
else: |
|
150 |
dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib' |
|
151 |
||
152 |
dylibname = os.path.basename(dylibpath) |
|
153 |
sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so') |
|
154 |
||
155 |
call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath], |
|
156 |
cwd=os.path.abspath(tmp_dir), |
|
157 |
filter_stdout=filter_python_develop, |
|
158 |
show_stdout=True) |
|
159 |
||
160 |
||
161 |
def gen_install_comp_lib(lib_name, lib_key, configure_options=[]): |
|
162 |
||
163 |
def install_lib(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
164 |
lib_src = os.path.join(src_dir,lib_name+".tar.gz") |
|
165 |
logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src)) |
|
166 |
shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src) |
|
167 |
tf = tarfile.open(lib_src,'r:gz') |
|
168 |
lib_base_path = os.path.join(src_dir, lib_name) |
|
169 |
logger.notify("Extract %s to %s " % (lib_name,lib_base_path)) |
|
170 |
tf.extractall(lib_base_path) |
|
171 |
tf.close() |
|
172 |
||
173 |
lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0]) |
|
174 |
||
175 |
logger.notify(lib_name + " configure in " + lib_src_path) |
|
176 |
call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options, |
|
177 |
cwd=os.path.abspath(lib_src_path), |
|
178 |
filter_stdout=filter_python_develop, |
|
179 |
show_stdout=True) |
|
180 |
||
181 |
logger.notify(lib_name + " make in " + lib_src_path) |
|
182 |
call_subprocess(['make'], |
|
183 |
cwd=os.path.abspath(lib_src_path), |
|
184 |
filter_stdout=filter_python_develop, |
|
185 |
show_stdout=True) |
|
186 |
||
187 |
logger.notify(lib_name + "make install in " + lib_src_path) |
|
188 |
call_subprocess(['make', 'install'], |
|
189 |
cwd=os.path.abspath(lib_src_path), |
|
190 |
filter_stdout=filter_python_develop, |
|
191 |
show_stdout=True) |
|
192 |
return install_lib |
|
193 |
||
194 |
install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared']) |
|
195 |
install_zlib = gen_install_comp_lib("zlib", "ZLIB", []) |
|
| 165 | 196 |
|
197 |
osx_extra_env = {'ARCHFLAGS': '-Wno-error=unused-command-line-argument-hard-error-in-future', 'CFLAGS': '-Qunused-arguments', 'CPPFLAGS': '-Qunused-arguments'} |
|
198 |
||
| 0 | 199 |
|
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
200 |
def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None): |
| 0 | 201 |
|
202 |
all_urls = URLS.copy() |
|
203 |
if urls is not None: |
|
204 |
all_urls.update(urls) |
|
205 |
||
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
206 |
res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs) |
| 0 | 207 |
|
208 |
def filter_python_develop(line): |
|
209 |
if not line.strip(): |
|
210 |
return Logger.DEBUG |
|
211 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
212 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
213 |
'creating ', 'Copying ']: |
|
214 |
if line.startswith(prefix): |
|
215 |
return Logger.DEBUG |
|
216 |
return Logger.NOTIFY |
|
217 |
||
218 |
||
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
219 |
def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess): |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
220 |
logger.notify("Install %s from %s with %s" % (key,res_path,method)) |
| 0 | 221 |
if method == 'pip': |
222 |
if sys.platform == 'win32': |
|
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
223 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path] |
| 0 | 224 |
else: |
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
225 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_path] |
| 0 | 226 |
if option_str : |
|
2
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
227 |
args.append(option_str) |
|
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
228 |
if res_source_key == 'local': |
| 0 | 229 |
if extra_env is None: |
230 |
extra_env = {} |
|
|
2
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
231 |
extra_env["PIP_DOWNLOAD_CACHE"] = res_env.get_src_base_path("") |
|
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
232 |
args.insert(2, '-f') |
|
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
233 |
args.insert(3, res_env.get_src_base_path("")) |
|
aaa8629d42c9
add django rest framework and its dependencies + improve virtualenv creation
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
234 |
args.insert(4, '--no-index') |
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
235 |
logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
236 |
call_subprocess(args, |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
237 |
cwd=os.path.abspath(tmp_dir), |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
238 |
filter_stdout=filter_python_develop, |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
239 |
show_stdout=True, |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
240 |
extra_env=extra_env) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
241 |
if method == 'pip-req': |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
242 |
if sys.platform == 'win32': |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
243 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-r', res_path] |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
244 |
else: |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
245 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-r', res_path] |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
246 |
if option_str : |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
247 |
args.append(option_str) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
248 |
if res_source_key == 'local': |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
249 |
if extra_env is None: |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
250 |
extra_env = {} |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
251 |
extra_env["PIP_DOWNLOAD_CACHE"] = res_env.get_src_base_path("") |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
252 |
args.insert(2, '-f') |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
253 |
args.insert(3, res_env.get_src_base_path("")) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
254 |
args.insert(4, '--no-index') |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
255 |
logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
| 0 | 256 |
call_subprocess(args, |
257 |
cwd=os.path.abspath(tmp_dir), |
|
258 |
filter_stdout=filter_python_develop, |
|
259 |
show_stdout=True, |
|
260 |
extra_env=extra_env) |
|
261 |
else: |
|
262 |
if sys.platform == 'win32': |
|
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
263 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_path] |
| 0 | 264 |
else: |
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
265 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_path] |
| 0 | 266 |
if option_str : |
267 |
args.insert(1,option_str) |
|
268 |
call_subprocess(args, |
|
269 |
cwd=os.path.abspath(tmp_dir), |
|
270 |
filter_stdout=filter_python_develop, |
|
271 |
show_stdout=True, |
|
272 |
extra_env=extra_env) |
|
273 |
||
274 |
||
275 |
def after_install(options, home_dir): |
|
276 |
||
277 |
global logger |
|
278 |
||
279 |
verbosity = options.verbose - options.quiet |
|
280 |
logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)]) |
|
281 |
||
282 |
||
283 |
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
284 |
base_dir = os.path.dirname(home_dir) |
|
285 |
src_dir = os.path.join(home_dir, 'src') |
|
286 |
tmp_dir = os.path.join(home_dir, 'tmp') |
|
287 |
ensure_dir(src_dir, logger) |
|
288 |
ensure_dir(tmp_dir, logger) |
|
289 |
system_str = platform.system() |
|
290 |
||
291 |
res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local') |
|
292 |
if res_source_key is None: |
|
293 |
res_source_key = 'local' |
|
294 |
||
295 |
ignore_packages = [] |
|
296 |
||
297 |
if system_str == 'Windows': |
|
298 |
default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}} |
|
299 |
else: |
|
300 |
default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}} |
|
301 |
||
302 |
if options.ignore_packages : |
|
303 |
ignore_packages = options.ignore_packages.split(",") |
|
304 |
||
305 |
logger.indent += 2 |
|
306 |
try: |
|
307 |
for key in res_env.NORMAL_INSTALL: |
|
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
308 |
install_options = None |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
309 |
if isinstance(key, dict): |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
310 |
install_options = key.get('install', default_install_options) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
311 |
install_options['method'] = 'pip-req' |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
312 |
res_path = res_env.get_run_res_base_path(key['requirement']) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
313 |
else: |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
314 |
if key not in res_env.URLS: |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
315 |
logger.notify("%s not found in def : passing" % (key,)) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
316 |
install_options = res_env.URLS[key].get('install', None) |
|
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
317 |
res_path = res_env.URLS[key][res_source_key] |
| 0 | 318 |
if install_options is None: |
319 |
install_options = default_install_options |
|
320 |
method = install_options.get('method', default_install_options['method']) |
|
321 |
option_str = install_options.get('option_str', default_install_options['option_str']) |
|
322 |
extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env']) |
|
323 |
if not extra_env: |
|
324 |
extra_env = {} |
|
325 |
||
326 |
if 'TMPDIR' not in extra_env: |
|
| 165 | 327 |
extra_env['TMPDIR'] = os.path.abspath(tmp_dir) |
328 |
if system_str == 'Darwin': |
|
329 |
for flag_key, flag_value in iter(osx_extra_env.items()): |
|
330 |
flags = extra_env.get(flag_key, '') |
|
331 |
if flag_value not in flags: |
|
332 |
flags += " -Wno-error=unused-command-line-argument-hard-error-in-future" |
|
333 |
extra_env[flag_key] = flags.strip() |
|
334 |
||
| 0 | 335 |
#isinstance(lst, (list, tuple)) |
336 |
if key not in ignore_packages: |
|
337 |
logger.notify("install %s with method %s" % (key, repr(method))) |
|
338 |
if callable(method): |
|
339 |
method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
|
340 |
elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']: |
|
341 |
globals()[method](option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
|
342 |
else: |
|
|
3
63c5437a9b7d
allow usage of requirement files for virtualenv
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
343 |
normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess) |
| 0 | 344 |
|
345 |
logger.notify("Clear source dir") |
|
346 |
shutil.rmtree(src_dir) |
|
347 |
||
348 |
finally: |
|
349 |
logger.indent -= 2 |
|
350 |
script_dir = join(base_dir, bin_dir) |
|
351 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
352 |
% join(script_dir, 'easy_install')) |
|
353 |
||
354 |
def adjust_options(options, args): |
|
355 |
if not options_to_add: |
|
| 165 | 356 |
return |
| 0 | 357 |
for opt in options_to_add: |
358 |
test_opt = opt.split('=',1)[0] |
|
359 |
#if not hasattr(options,test_opt) or getattr(options, test_opt) is None: |
|
360 |
setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True) |
|
361 |
||
362 |
return adjust_options, extend_parser, after_install |
|
| 165 | 363 |