From 1d2edf1051e5ece91cd0ec237863821930125f1d Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 26 Mar 2019 09:10:41 -0700 Subject: [PATCH] mkpkg: Grab sdist instead of first URL from PyPI (#356) The first URL from PyPI is often a platform-specific wheel, so it's better if we prefer to grab a source distribution that we can build with emscripten. Before: ``` $ bin/pyodide mkpkg lxml $ grep 'url: ' packages/lxml/meta.yaml url: https://files.pythonhosted.org/packages/28/32/951337aa3d14e58cae3f585e468e402141f5ac3728589eccca765c4e17ce/lxml-4.3.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl ``` After: ``` $ bin/pyodide mkpkg lxml $ grep 'url: ' packages/lxml/meta.yaml url: https://files.pythonhosted.org/packages/65/6f/d070609b415f4a24bf36b7deb94bfd791e8d023c0dbf4233659af53fe0ab/lxml-4.3.2.tar.gz ``` Closes: #363. --- pyodide_build/mkpkg.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/pyodide_build/mkpkg.py b/pyodide_build/mkpkg.py index 873721c42..a88e4a71e 100755 --- a/pyodide_build/mkpkg.py +++ b/pyodide_build/mkpkg.py @@ -3,12 +3,38 @@ import argparse import json import os -from pathlib import Path +import shutil import urllib.request - +from pathlib import Path PACKAGES_ROOT = Path(__file__).parent.parent / 'packages' +SDIST_EXTENSIONS = [] + + +def get_sdist_extensions(): + if SDIST_EXTENSIONS: + return SDIST_EXTENSIONS + + for format in shutil.get_unpack_formats(): + for ext in format[1]: + SDIST_EXTENSIONS.append(ext) + + return SDIST_EXTENSIONS + + +def get_sdist_url_entry(json_content): + sdist_extensions_tuple = tuple(get_sdist_extensions()) + + for entry in json_content['urls']: + if entry['filename'].endswith(sdist_extensions_tuple): + return entry + + raise Exception('No sdist URL found for package %s (%s)' % ( + json_content['info'].get('name'), + json_content['info'].get('package_url'), + )) + def make_package(package): import yaml @@ -18,7 +44,7 @@ def make_package(package): with urllib.request.urlopen(url) as fd: json_content = json.load(fd) - entry = json_content['urls'][0] + entry = get_sdist_url_entry(json_content) download_url = entry['url'] sha256 = entry['digests']['sha256'] version = json_content['info']['version']