@@ -54,27 +54,27 @@ def system(cmd, msg=""):
5454
5555
5656def known_packages ():
57- def PyYAML ():
58- install_from_pypi ("PyYAML==3.13" )
57+ def PyYAML (* args ):
58+ install_from_pypi ("PyYAML==3.13" , args )
5959
60- def six ():
61- install_from_pypi ("six==1.12.0" )
60+ def six (* args ):
61+ install_from_pypi ("six==1.12.0" , args )
6262
63- def Cython ():
64- install_from_pypi ("Cython==0.29.2" , ['--no-cython-compile' ])
63+ def Cython (* args ):
64+ install_from_pypi ("Cython==0.29.2" , ['--no-cython-compile' ] + args )
6565
66- def setuptools ():
67- install_from_pypi ("setuptools==40.6.3" )
66+ def setuptools (* args ):
67+ install_from_pypi ("setuptools==40.6.3" , args )
6868
69- def setuptools_scm ():
70- install_from_url ("https://files.pythonhosted.org/packages/70/bc/f34b06274c1260c5e4842f789fb933a09b89f23549f282b36a15bdf63614/setuptools_scm-1.15.0rc1.tar.gz" )
69+ def setuptools_scm (* args ):
70+ install_from_url ("https://files.pythonhosted.org/packages/70/bc/f34b06274c1260c5e4842f789fb933a09b89f23549f282b36a15bdf63614/setuptools_scm-1.15.0rc1.tar.gz" , extra_opts = args )
7171
72- def numpy ():
72+ def numpy (* args ):
7373 try :
7474 import setuptools as st
7575 except ImportError :
7676 print ("Installing required dependency: setuptools" )
77- setuptools ()
77+ setuptools (* args )
7878
7979 patch = """
8080diff --git a/setup.py 2018-02-28 17:03:26.000000000 +0100
@@ -308,51 +308,47 @@ def get_lapack_lite_sources(ext, build_dir):
3083082.14.1
309309
310310"""
311- install_from_url ("https://files.pythonhosted.org/packages/b0/2b/497c2bb7c660b2606d4a96e2035e92554429e139c6c71cdff67af66b58d2/numpy-1.14.3.zip" , patch = patch )
311+ install_from_url ("https://files.pythonhosted.org/packages/b0/2b/497c2bb7c660b2606d4a96e2035e92554429e139c6c71cdff67af66b58d2/numpy-1.14.3.zip" , patch = patch , extra_opts = args )
312312
313313
314- def dateutil ():
314+ def dateutil (* args ):
315315 try :
316316 import setuptools_scm as st_scm
317317 except ImportError :
318318 print ("Installing required dependency: setuptools_scm" )
319- setuptools_scm ()
320- install_from_url ("https://files.pythonhosted.org/packages/0e/01/68747933e8d12263d41ce08119620d9a7e5eb72c876a3442257f74490da0/python-dateutil-2.7.5.tar.gz" )
319+ setuptools_scm (* args )
320+ install_from_url ("https://files.pythonhosted.org/packages/0e/01/68747933e8d12263d41ce08119620d9a7e5eb72c876a3442257f74490da0/python-dateutil-2.7.5.tar.gz" , extra_opts = args )
321321
322322
323- def pytz ():
324- install_from_url ("https://files.pythonhosted.org/packages/cd/71/ae99fc3df1b1c5267d37ef2c51b7d79c44ba8a5e37b48e3ca93b4d74d98b/pytz-2018.7.tar.gz" )
323+ def pytz (* args ):
324+ install_from_url ("https://files.pythonhosted.org/packages/cd/71/ae99fc3df1b1c5267d37ef2c51b7d79c44ba8a5e37b48e3ca93b4d74d98b/pytz-2018.7.tar.gz" , extra_opts = args )
325325
326326
327- def six ():
328- install_from_url ("https://files.pythonhosted.org/packages/dd/bf/4138e7bfb757de47d1f4b6994648ec67a51efe58fa907c1e11e350cddfca/six-1.12.0.tar.gz" )
329-
330-
331- def pandas ():
327+ def pandas (* args ):
332328 try :
333329 import numpy as np
334330 except ImportError :
335331 print ("Installing required dependency: numpy" )
336- numpy ()
332+ numpy (* args )
337333
338334
339335 try :
340336 import pytz as _dummy_pytz
341337 except ImportError :
342338 print ("Installing required dependency: pytz" )
343- pytz ()
339+ pytz (* args )
344340
345341 try :
346342 import six as _dummy_six
347343 except ImportError :
348344 print ("Installing required dependency: six" )
349- six ()
345+ six (* args )
350346
351347 try :
352348 import dateutil as __dummy_dateutil
353349 except ImportError :
354350 print ("Installing required dependency: dateutil" )
355- dateutil ()
351+ dateutil (* args )
356352
357353 # download pandas-0.20.3
358354 patch = """diff --git a/pandas/_libs/src/period_helper.c b/pandas/_libs/src/period_helper.c
@@ -382,7 +378,7 @@ def pandas():
382378 dinfo->abstime = (double)(hour * 3600 + minute * 60) + second;
383379
384380"""
385- install_from_url ("https://files.pythonhosted.org/packages/ee/aa/90c06f249cf4408fa75135ad0df7d64c09cf74c9870733862491ed5f3a50/pandas-0.20.3.tar.gz" , patch = patch )
381+ install_from_url ("https://files.pythonhosted.org/packages/ee/aa/90c06f249cf4408fa75135ad0df7d64c09cf74c9870733862491ed5f3a50/pandas-0.20.3.tar.gz" , patch = patch , extra_opts = args )
386382
387383 return locals ()
388384
@@ -395,7 +391,7 @@ def xit(msg, status=-1):
395391 exit (- 1 )
396392
397393
398- def install_from_url (url , patch = None ):
394+ def install_from_url (url , patch = None , extra_opts = [] ):
399395 name = url [url .rfind ("/" )+ 1 :]
400396 tempdir = tempfile .mkdtemp ()
401397
@@ -419,8 +415,11 @@ def install_from_url(url, patch=None):
419415 with open ("%s/%s.patch" % (tempdir , bare_name ), "w" ) as f :
420416 f .write (patch )
421417 system ("patch -d %s/%s/ -p1 < %s/%s.patch" % ((tempdir , bare_name )* 2 ))
422-
423- system ("cd %s/%s; %s setup.py install --user" % (tempdir , bare_name , sys .executable ))
418+
419+ if "--prefix" in extra_opts :
420+ system ("cd %s/%s; %s setup.py install %s" % (tempdir , bare_name , sys .executable , " " .join (extra_opts )))
421+ else :
422+ system ("cd %s/%s; %s setup.py install --user %s" % (tempdir , bare_name , sys .executable , " " .join (extra_opts )))
424423
425424
426425def install_from_pypi (package , extra_opts = []):
@@ -475,14 +474,19 @@ def main(argv):
475474 help = "list locally installed packages"
476475 )
477476
478- subparsers .add_parser (
477+ install_parser = subparsers .add_parser (
479478 "install" ,
480479 help = "install a known package" ,
481480 description = "Install a known package. Known packages are " + ", " .join (KNOWN_PACKAGES .keys ())
482- ).add_argument (
481+ )
482+ install_parser .add_argument (
483483 "package" ,
484484 help = "comma-separated list"
485485 )
486+ install_parser .add_argument (
487+ "--prefix" ,
488+ help = "user-site path prefix"
489+ )
486490
487491 subparsers .add_parser (
488492 "uninstall" ,
@@ -534,7 +538,10 @@ def main(argv):
534538 if pkg not in KNOWN_PACKAGES :
535539 xit ("Unknown package: '%s'" % pkg )
536540 else :
537- KNOWN_PACKAGES [pkg ]()
541+ if "prefix" in args :
542+ KNOWN_PACKAGES [pkg ]("--prefix" , args .prefix )
543+ else :
544+ KNOWN_PACKAGES [pkg ]()
538545 elif args .command == "pypi" :
539546 for pkg in args .package .split ("," ):
540547 install_from_pypi (pkg )
0 commit comments