Last active
November 9, 2019 03:09
-
-
Save jakirkham/7baa42250a0bddf0e2eb5e7db3dca1bc to your computer and use it in GitHub Desktop.
Searches for matching Conda packages, downloads them, and converts them to wheels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import contextlib | |
import json | |
import os | |
import shutil | |
import tempfile | |
import subprocess | |
import sys | |
import urllib | |
import urllib.request | |
@contextlib.contextmanager | |
def mkdtemp(): | |
dn = tempfile.mkdtemp() | |
try: | |
yield dn | |
finally: | |
shutil.rmtree(dn) | |
def main(*argv): | |
parser = argparse.ArgumentParser("Download and convert Conda packages.") | |
parser.add_argument("channel") | |
parser.add_argument("name") | |
parser.add_argument("version") | |
args = parser.parse_args(argv) | |
name = args.name | |
channel = args.channel | |
version = args.version | |
urls = [] | |
for subdir in ["linux-64", "osx-64", "win-64"]: | |
r = subprocess.run( | |
["conda", "search", "--json", | |
f"{name}[channel={channel}, subdir={subdir}]={version}"], | |
capture_output=True | |
) | |
j = json.loads(r.stdout) | |
p = j[name] | |
urls.extend([e["url"] for e in p]) | |
with mkdtemp() as dn: | |
print(f"Working dir: {dn}") | |
for each_url in urls: | |
fn = os.path.join(dn, os.path.basename(each_url)) | |
req = urllib.request.urlopen(each_url) | |
if req.status == 200: | |
with open(fn, "wb") as fh: | |
shutil.copyfileobj(req, fh, 1024) | |
subprocess.run([ | |
"conda", "press", "--skip-python", "--fatten", fn | |
]) | |
print("Wheels done!") | |
input() | |
return 0 | |
if __name__ == "__main__": | |
sys.exit(main(*sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment