@@ -114,7 +114,7 @@ def Werkzeug(*args):
114
114
# install_from_pypi("Keras-Applications==1.0.6", args)
115
115
116
116
def setuptools_scm (* args ):
117
- install_from_url ( "https://files.pythonhosted.org/packages/70/bc/f34b06274c1260c5e4842f789fb933a09b89f23549f282b36a15bdf63614/ setuptools_scm- 1.15.0rc1.tar.gz " , extra_opts = args )
117
+ install_from_pypi ( " setuptools_scm== 1.15.0rc1" , extra_opts = args )
118
118
119
119
def numpy (* args ):
120
120
try :
@@ -369,7 +369,7 @@ def get_lapack_lite_sources(ext, build_dir):
369
369
2.14.1
370
370
371
371
"""
372
- install_from_url ( "https://files.pythonhosted.org/packages/b0/2b/497c2bb7c660b2606d4a96e2035e92554429e139c6c71cdff67af66b58d2/ numpy- 1.14.3.zip " , patch = patch , extra_opts = args )
372
+ install_from_pypi ( " numpy== 1.14.3" , patch = patch , extra_opts = args )
373
373
374
374
375
375
def dateutil (* args ):
@@ -378,11 +378,11 @@ def dateutil(*args):
378
378
except ImportError :
379
379
print ("Installing required dependency: setuptools_scm" )
380
380
setuptools_scm (* args )
381
- install_from_url ( "https://files.pythonhosted.org/packages/0e/01/68747933e8d12263d41ce08119620d9a7e5eb72c876a3442257f74490da0/ python-dateutil- 2.7.5.tar.gz " , extra_opts = args )
381
+ install_from_pypi ( " python-dateutil== 2.7.5" , extra_opts = args )
382
382
383
383
384
384
def pytz (* args ):
385
- install_from_url ( "https://files.pythonhosted.org/packages/cd/71/ae99fc3df1b1c5267d37ef2c51b7d79c44ba8a5e37b48e3ca93b4d74d98b/ pytz- 2018.7.tar.gz " , extra_opts = args )
385
+ install_from_pypi ( " pytz== 2018.7" , extra_opts = args )
386
386
387
387
388
388
def pandas (* args ):
@@ -473,7 +473,7 @@ def pandas(*args):
473
473
474
474
"""
475
475
cflags = "-allowcpp" if sys .implementation .name == "graalpython" else ""
476
- install_from_url ( "https://files.pythonhosted.org/packages/ee/aa/90c06f249cf4408fa75135ad0df7d64c09cf74c9870733862491ed5f3a50/ pandas- 0.20.3.tar.gz " , patch = patch , extra_opts = args , add_cflags = cflags )
476
+ install_from_pypi ( " pandas== 0.20.3" , patch = patch , extra_opts = args , add_cflags = cflags )
477
477
478
478
return locals ()
479
479
@@ -486,7 +486,7 @@ def xit(msg, status=-1):
486
486
exit (- 1 )
487
487
488
488
489
- def install_from_url (url , patch = None , extra_opts = [], add_cflags = "" ):
489
+ def _install_from_url (url , patch = None , extra_opts = [], add_cflags = "" ):
490
490
name = url [url .rfind ("/" )+ 1 :]
491
491
tempdir = tempfile .mkdtemp ()
492
492
@@ -502,13 +502,18 @@ def install_from_url(url, patch=None, extra_opts=[], add_cflags=""):
502
502
cppflags = os .environ .get ("CPPFLAGS" , "" )
503
503
cflags = "-v " + os .environ .get ("CFLAGS" , "" ) + ((" " + add_cflags ) if add_cflags else "" )
504
504
505
- system ("curl %s -o %s/%s %s" % (" " .join (curl_opts ), tempdir , name , url ))
505
+ system ("curl %s -o %s/%s %s" % (" " .join (curl_opts ), tempdir , name , url ), msg = "Download error" )
506
506
if name .endswith (".tar.gz" ):
507
- system ("tar xzf %s/%s -C %s" % (tempdir , name , tempdir ))
507
+ system ("tar xzf %s/%s -C %s" % (tempdir , name , tempdir ), msg = "Error extracting tar.gz" )
508
508
bare_name = name [:- len (".tar.gz" )]
509
+ elif name .endswith (".tar.bz2" ):
510
+ system ("tar xjf %s/%s -C %s" % (tempdir , name , tempdir ), msg = "Error extracting tar.bz2" )
511
+ bare_name = name [:- len (".tar.bz2" )]
509
512
elif name .endswith (".zip" ):
510
- system ("unzip -u %s/%s -d %s" % (tempdir , name , tempdir ))
513
+ system ("unzip -u %s/%s -d %s" % (tempdir , name , tempdir ), msg = "Error extracting zip" )
511
514
bare_name = name [:- len (".zip" )]
515
+ else :
516
+ xit ("Unknown file type: %s" % filename )
512
517
513
518
if patch :
514
519
with open ("%s/%s.patch" % (tempdir , bare_name ), "w" ) as f :
@@ -519,51 +524,37 @@ def install_from_url(url, patch=None, extra_opts=[], add_cflags=""):
519
524
user_arg = "--user"
520
525
else :
521
526
user_arg = ""
522
- system ("cd %s/%s; %s %s %s setup.py install %s %s" % (tempdir , bare_name , 'CFLAGS="%s"' % cflags if cflags else "" , 'CPPFLAGS="%s"' % cppflags if cppflags else "" , sys .executable , user_arg , " " .join (extra_opts )))
527
+ status = system ("cd %s/%s; %s %s %s setup.py install %s %s" % (tempdir , bare_name , 'CFLAGS="%s"' % cflags if cflags else "" , 'CPPFLAGS="%s"' % cppflags if cppflags else "" , sys .executable , user_arg , " " .join (extra_opts )))
528
+ if status != 0 :
529
+ xit ("An error occurred trying to run `setup.py install %s %s'" % (user_arg , " " .join (extra_opts )))
530
+
523
531
532
+ def install_from_pypi (package , patch = None , extra_opts = [], add_cflags = "" ):
533
+ package_pattern = os .environ .get ("GINSTALL_PACKAGE_PATTERN" , "https://pypi.org/pypi/%s/json" )
534
+ package_version_pattern = os .environ .get ("GINSTALL_PACKAGE_VERSION_PATTERN" , "https://pypi.org/pypi/%s/%s/json" )
524
535
525
- def install_from_pypi (package , extra_opts = []):
526
536
if "==" in package :
527
537
package , _ , version = package .rpartition ("==" )
528
- url = "https://pypi.org/pypi/%s/%s/json" % (package , version )
538
+ url = package_version_pattern % (package , version )
529
539
else :
530
- url = "https://pypi.org/pypi/%s/json" % package
540
+ url = package_pattern % package
531
541
532
- r = subprocess .check_output ("curl %s" % url , shell = True ).decode ("utf8" )
533
- try :
534
- urls = json .loads (r )["urls" ]
535
- except :
536
- pass
542
+ if any (url .endswith (ending ) for ending in [".zip" , ".tar.bz2" , ".tar.gz" ]):
543
+ # this is already the url to the actual package
537
544
else :
538
- for url_info in urls :
539
- if url_info ["python_version" ] == "source" :
540
- url = url_info ["url" ]
541
- break
542
-
543
- if url :
544
- tempdir = tempfile .mkdtemp ()
545
- filename = url .rpartition ("/" )[2 ]
546
- system ("curl -L -o %s/%s %s" % (tempdir , filename , url ), msg = "Download error" )
547
- dirname = None
548
- if filename .endswith (".zip" ):
549
- system ("unzip -u %s/%s -d %s" % (tempdir , filename , tempdir ))
550
- dirname = filename [:- 4 ]
551
- elif filename .endswith (".tar.gz" ):
552
- system ("tar -C %s -xzf %s/%s" % (tempdir , tempdir , filename ), msg = "Error during extraction" )
553
- dirname = filename [:- 7 ]
554
- elif filename .endswith (".tar.bz2" ):
555
- system ("tar -C %s -xjf %s/%s" % (tempdir , tempdir , filename ), msg = "Error during extraction" )
556
- dirname = filename [:- 7 ]
545
+ r = subprocess .check_output ("curl %s" % url , shell = True ).decode ("utf8" )
546
+ try :
547
+ urls = json .loads (r )["urls" ]
548
+ except :
549
+ pass
557
550
else :
558
- xit ("Unknown file type: %s" % filename )
551
+ for url_info in urls :
552
+ if url_info ["python_version" ] == "source" :
553
+ url = url_info ["url" ]
554
+ break
559
555
560
- if "--prefix" not in extra_opts and site .ENABLE_USER_SITE :
561
- user_arg = "--user"
562
- else :
563
- user_arg = ""
564
- status = os .system ("cd %s/%s; %s setup.py install %s %s" % (tempdir , dirname , sys .executable , user_arg , " " .join (extra_opts )))
565
- if status != 0 :
566
- xit ("An error occurred trying to run `setup.py install %s %s'" % (user_arg , " " .join (extra_opts )))
556
+ if url :
557
+ _install_from_url (url , patch = patch , extra_opts = extra_opts , add_cflags = add_cflags )
567
558
else :
568
559
xit ("Package not found: '%s'" % package )
569
560
0 commit comments