Skip to content

Commit 19640d2

Browse files
committed
draft of downloading sources from pypi instead of pip (pypa/pip#9701)
1 parent b2fbeec commit 19640d2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cmsBuild

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ from cmsBuild_consts import *
3131
from cmsdist_config import USE_COMPILER_VERSION
3232
try: from monitor_build import run_monitor_on_command
3333
except: run_monitor_on_command=None
34+
import json
3435

3536
urlRe = re.compile(".*:.*/.*")
3637
logLevel = 10
@@ -605,6 +606,7 @@ def downloadPip(source, dest, options):
605606
pack = pack + '==' + pkg[1].strip()
606607
pip_opts = "--no-deps --no-binary=:all:"
607608
pip="pip"
609+
isSourceDownload=True
608610

609611
for opt in opts:
610612
if opt.startswith("pip="): pip=opt.split('=',1)[-1]
@@ -619,6 +621,31 @@ def downloadPip(source, dest, options):
619621
i = i + 1
620622
else:
621623
pip_opts = pip_opts + ' ' + spSrc[i]
624+
if "no-binary" in spSrc[i] and "all" not in spSrc[i]:
625+
isSourceDownload=False #not totally robust - but basically use pip if source is overridden
626+
627+
if isSourceDownload:
628+
log("Looking for sources at https://pypi.org/pypi/"+pack.split('=')[0]+"/json")
629+
fj=urlopen("https://pypi.org/pypi/"+pack.split('=')[0]+"/json")
630+
data=json.load(fj)
631+
url=None
632+
if "releases" in data and pack.split('=')[2] in data["releases"]:
633+
for file in data["releases"][pack.split('=')[2]]:
634+
if file["packagetype"] == "sdist":
635+
url=file["url"]
636+
if url is not None:
637+
log("Found source on pypi - downloading")
638+
tempdir = createTempDir(options.workDir, options.tempDirPrefix)
639+
precmd = "cd %s; " % tempdir
640+
downloadUrllib2(url, tempdir, options)
641+
cmd="/bin/ls "+tempdir+" | grep -v files.list > "+os.path.join(tempdir,"files.list")
642+
getstatusoutput(cmd)
643+
o,e=getstatusoutput(precmd+"cat files.list")
644+
cmd=precmd+"tar cfz "+os.path.join(dest,"source.tar.gz")+" `cat files.list` files.list"
645+
o,e=getstatusoutput(cmd)
646+
getstatusoutput("rm -rf %s" % tempdir)
647+
return True
648+
622649
if not '--no-deps' in pip_opts: pip_opts = '--no-deps ' + pip_opts
623650
if not '--no-cache-dir' in pip_opts: pip_opts = '--no-cache-dir ' + pip_opts
624651
comm = pip + ' download ' + pip_opts + ' --disable-pip-version-check -d . ' + pack + '; /bin/ls | grep -v files.list > files.list'
@@ -825,6 +852,7 @@ def download(source, dest, options, pkg=None):
825852
if success:
826853
noCmssdtCache = True
827854
break
855+
828856
if not success:
829857
log("Trying to fetch source file: %s" % source, DEBUG)
830858
success = downloadHandler(source, downloadDir, downloadOptions)

0 commit comments

Comments
 (0)