Commit 94e935b4 authored by Michael Droettboom's avatar Michael Droettboom Committed by GitHub

Merge pull request #107 from rth/pyodide-package

Refactoring common functions under pyodide_build
parents 556041c1 bde0b964
...@@ -34,16 +34,6 @@ jobs: ...@@ -34,16 +34,6 @@ jobs:
pip install pytest pytest-xdist pytest-instafail selenium PyYAML pip install pytest pytest-xdist pytest-instafail selenium PyYAML
# Get recent version of Firefox and geckodriver
wget -O firefox.tar.bz2 https://download.mozilla.org/\?product\=firefox-latest-ssl\&os\=linux64\&lang\=en-US
tar jxf firefox.tar.bz2
wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
tar zxf geckodriver-v0.21.0-linux64.tar.gz -C firefox
# Get recent version of chromedriver
wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver firefox
- run: - run:
name: lint name: lint
...@@ -79,7 +69,6 @@ jobs: ...@@ -79,7 +69,6 @@ jobs:
paths: paths:
- ./build - ./build
- ./pyodide-env - ./pyodide-env
- ./firefox
- store_artifacts: - store_artifacts:
path: /home/circleci/repo/build/ path: /home/circleci/repo/build/
...@@ -97,6 +86,12 @@ jobs: ...@@ -97,6 +86,12 @@ jobs:
# causes Firefox to complain when loading it. Let's just add the new mime type. # causes Firefox to complain when loading it. Let's just add the new mime type.
sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types" sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types"
# Get recent version of Firefox and geckodriver
wget -O firefox.tar.bz2 https://download.mozilla.org/\?product\=firefox-latest-ssl\&os\=linux64\&lang\=en-US
tar jxf firefox.tar.bz2
wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
tar zxf geckodriver-v0.21.0-linux64.tar.gz -C firefox
source pyodide-env/bin/activate source pyodide-env/bin/activate
export PATH=$PWD/firefox:$PATH export PATH=$PWD/firefox:$PATH
pytest test -v -k firefox pytest test -v -k firefox
...@@ -114,8 +109,12 @@ jobs: ...@@ -114,8 +109,12 @@ jobs:
# causes Firefox to complain when loading it. Let's just add the new mime type. # causes Firefox to complain when loading it. Let's just add the new mime type.
sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types" sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types"
# Get recent version of chromedriver
wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver pyodide-env/bin/
source pyodide-env/bin/activate source pyodide-env/bin/activate
export PATH=$PWD/firefox:$PATH
pytest test -v -k chrome pytest test -v -k chrome
deploy: deploy:
......
...@@ -22,3 +22,4 @@ ccache ...@@ -22,3 +22,4 @@ ccache
/six/six-1.11.0 /six/six-1.11.0
/lz4/lz4-1.8.3 /lz4/lz4-1.8.3
*.egg-info/
#!/bin/bash
# get the absolute path to the root directory
ROOTDIR=$(python -c 'import pathlib, sys; \
print(pathlib.Path(sys.argv[1]).resolve().parents[1])' \
"${BASH_SOURCE[0]}")
export PYTHONPATH="${PYTHONPATH}:${ROOTDIR}"
python -m pyodide_build "$@"
...@@ -2,7 +2,8 @@ PYODIDE_ROOT=$(abspath ..) ...@@ -2,7 +2,8 @@ PYODIDE_ROOT=$(abspath ..)
include ../Makefile.envs include ../Makefile.envs
all: all:
../tools/buildall . ../build --ldflags="$(SIDE_LDFLAGS)" --host=$(HOSTPYTHONROOT) --target=$(TARGETPYTHONROOT) ../bin/pyodide buildall . ../build \
--ldflags="$(SIDE_LDFLAGS)" --host=$(HOSTPYTHONROOT) --target=$(TARGETPYTHONROOT)
clean: clean:
rm -rf ./*/build rm -rf ./*/build
__version__ = '0.1.0'
#!/usr/bin/env python3
import argparse
from . import buildall
from . import buildpkg
from . import pywasmcross
def main():
main_parser = argparse.ArgumentParser(prog='pyodide')
subparsers = main_parser.add_subparsers(help='action')
for command_name, module in (("buildpkg", buildpkg),
("buildall", buildall),
("pywasmcross", pywasmcross)):
parser = module.make_parser(subparsers.add_parser(command_name))
parser.set_defaults(func=module.main)
args = main_parser.parse_args()
# run the selected action
args.func(args)
if __name__ == '__main__':
main()
...@@ -10,8 +10,8 @@ from pathlib import Path ...@@ -10,8 +10,8 @@ from pathlib import Path
import shutil import shutil
import common from . import common
import buildpkg from . import buildpkg
def build_package(pkgname, dependencies, packagesdir, outputdir, args): def build_package(pkgname, dependencies, packagesdir, outputdir, args):
...@@ -54,9 +54,8 @@ def build_packages(packagesdir, outputdir, args): ...@@ -54,9 +54,8 @@ def build_packages(packagesdir, outputdir, args):
json.dump({'dependencies': dependencies}, fd) json.dump({'dependencies': dependencies}, fd)
def parse_args(): def make_parser(parser):
parser = argparse.ArgumentParser( parser.description = "Build all of the packages in a given directory"
"Build all of the packages in a given directory")
parser.add_argument( parser.add_argument(
'dir', type=str, nargs=1, 'dir', type=str, nargs=1,
help='Input directory containing a tree of package definitions') help='Input directory containing a tree of package definitions')
...@@ -75,7 +74,7 @@ def parse_args(): ...@@ -75,7 +74,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--target', type=str, nargs='?', default=common.TARGETPYTHON, '--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation') help='The path to the target Python installation')
return parser.parse_args() return parser
def main(args): def main(args):
...@@ -85,5 +84,6 @@ def main(args): ...@@ -85,5 +84,6 @@ def main(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parse_args() parser = make_parser(argparse.ArgumentParser())
args = parser.parse_args()
main(args) main(args)
...@@ -12,10 +12,7 @@ import shutil ...@@ -12,10 +12,7 @@ import shutil
import subprocess import subprocess
import common from . import common
ROOTDIR = Path(__file__).parent.resolve()
def check_checksum(path, pkg): def check_checksum(path, pkg):
...@@ -88,7 +85,7 @@ def compile(path, srcpath, pkg, args): ...@@ -88,7 +85,7 @@ def compile(path, srcpath, pkg, args):
try: try:
subprocess.run([ subprocess.run([
str(Path(args.host) / 'bin' / 'python3'), str(Path(args.host) / 'bin' / 'python3'),
str(ROOTDIR / 'pywasmcross'), '-m', 'pyodide_build', 'pywasmcross',
'--cflags', '--cflags',
args.cflags + ' ' + args.cflags + ' ' +
pkg.get('build', {}).get('cflags', ''), pkg.get('build', {}).get('cflags', ''),
...@@ -124,7 +121,7 @@ def package_files(buildpath, srcpath, pkg, args): ...@@ -124,7 +121,7 @@ def package_files(buildpath, srcpath, pkg, args):
install_prefix = (srcpath / 'install').resolve() install_prefix = (srcpath / 'install').resolve()
subprocess.run([ subprocess.run([
'python', 'python',
Path(ROOTDIR) / 'file_packager.py', common.ROOTDIR / 'file_packager.py',
name + '.data', name + '.data',
'--lz4', '--lz4',
'--preload', '--preload',
...@@ -163,8 +160,8 @@ def build_package(path, args): ...@@ -163,8 +160,8 @@ def build_package(path, args):
os.chdir(orig_path) os.chdir(orig_path)
def parse_args(): def make_parser(parser):
parser = argparse.ArgumentParser('Build a pyodide package.') parser.description = 'Build a pyodide package.'
parser.add_argument( parser.add_argument(
'package', type=str, nargs=1, 'package', type=str, nargs=1,
help="Path to meta.yaml package description") help="Path to meta.yaml package description")
...@@ -180,7 +177,7 @@ def parse_args(): ...@@ -180,7 +177,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--target', type=str, nargs='?', default=common.TARGETPYTHON, '--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation') help='The path to the target Python installation')
return parser.parse_args() return parser
def main(args): def main(args):
...@@ -189,5 +186,6 @@ def main(args): ...@@ -189,5 +186,6 @@ def main(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parse_args() parser = make_parser(argparse.ArgumentParser())
args = parser.parse_args()
main(args) main(args)
from pathlib import Path from pathlib import Path
ROOTDIR = Path(__file__).parent.resolve() ROOTDIR = Path(__file__).parents[1].resolve() / 'tools'
HOSTPYTHON = ROOTDIR / '..' / 'cpython' / 'build' / '3.7.0' / 'host' HOSTPYTHON = ROOTDIR / '..' / 'cpython' / 'build' / '3.7.0' / 'host'
TARGETPYTHON = ROOTDIR / '..' / 'cpython' / 'installs' / 'python-3.7.0' TARGETPYTHON = ROOTDIR / '..' / 'cpython' / 'installs' / 'python-3.7.0'
DEFAULTCFLAGS = '' DEFAULTCFLAGS = ''
......
...@@ -34,10 +34,12 @@ import subprocess ...@@ -34,10 +34,12 @@ import subprocess
import sys import sys
import common # absolute import is necessary as this file will be symlinked
# under tools
from pyodide_build import common
ROOTDIR = Path(__file__).parent.resolve() ROOTDIR = common.ROOTDIR
symlinks = set(['cc', 'c++', 'ld', 'ar', 'gcc']) symlinks = set(['cc', 'c++', 'ld', 'ar', 'gcc'])
...@@ -186,7 +188,7 @@ def clean_out_native_artifacts(): ...@@ -186,7 +188,7 @@ def clean_out_native_artifacts():
path.unlink() path.unlink()
def install_for_distribution(): def install_for_distribution(args):
subprocess.check_call( subprocess.check_call(
[Path(args.host) / 'bin' / 'python3', [Path(args.host) / 'bin' / 'python3',
'setup.py', 'setup.py',
...@@ -202,33 +204,46 @@ def build_wrap(args): ...@@ -202,33 +204,46 @@ def build_wrap(args):
capture_compile(args) capture_compile(args)
clean_out_native_artifacts() clean_out_native_artifacts()
replay_compile(args) replay_compile(args)
install_for_distribution() install_for_distribution(args)
def parse_args():
parser = argparse.ArgumentParser(
'Cross compile a Python distutils package. '
'Run from the root directory of the package\'s source')
parser.add_argument(
'--cflags', type=str, nargs='?', default=common.DEFAULTCFLAGS,
help='Extra compiling flags')
parser.add_argument(
'--ldflags', type=str, nargs='?', default=common.DEFAULTLDFLAGS,
help='Extra linking flags')
parser.add_argument(
'--host', type=str, nargs='?', default=common.HOSTPYTHON,
help='The path to the host Python installation')
parser.add_argument(
'--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation')
args = parser.parse_args()
return args
if __name__ == '__main__': def make_parser(parser):
basename = Path(sys.argv[0]).name
if basename in symlinks:
# skip parsing of all arguments
parser._actions = []
else:
parser.description = (
'Cross compile a Python distutils package. '
'Run from the root directory of the package\'s source')
parser.add_argument(
'--cflags', type=str, nargs='?', default=common.DEFAULTCFLAGS,
help='Extra compiling flags')
parser.add_argument(
'--ldflags', type=str, nargs='?', default=common.DEFAULTLDFLAGS,
help='Extra linking flags')
parser.add_argument(
'--host', type=str, nargs='?', default=common.HOSTPYTHON,
help='The path to the host Python installation')
parser.add_argument(
'--target', type=str, nargs='?', default=common.TARGETPYTHON,
help='The path to the target Python installation')
return parser
def main(args):
basename = Path(sys.argv[0]).name basename = Path(sys.argv[0]).name
if basename in symlinks: if basename in symlinks:
collect_args(basename) collect_args(basename)
else: else:
args = parse_args()
build_wrap(args) build_wrap(args)
if __name__ == '__main__':
basename = Path(sys.argv[0]).name
if basename in symlinks:
main(None)
else:
parser = make_parser(argparse.ArgumentParser())
args = parser.parse_args()
main(args)
...@@ -7,7 +7,7 @@ from pathlib import Path ...@@ -7,7 +7,7 @@ from pathlib import Path
TEST_DIR = (Path(__file__).parent TEST_DIR = (Path(__file__).parent
/ "cpython/build/3.6.4/host/lib/python3.7/test") / "cpython/build/3.7.0/host/lib/python3.7/test")
def collect_tests(base_dir): def collect_tests(base_dir):
......
import pytest import pytest
import os import os
from pathlib import Path from pathlib import Path
import sys from pyodide_build.common import parse_package
BASE_DIR = Path(__file__).parent.parent BASE_DIR = Path(__file__).parent.parent
PKG_DIR = BASE_DIR / 'packages' PKG_DIR = BASE_DIR / 'packages'
# TODO: remove once we have a proper Python package for common functions
sys.path.append(str(BASE_DIR / 'tools'))
import common # noqa
def registered_packages(): def registered_packages():
"""Returns a list of registred package names""" """Returns a list of registred package names"""
...@@ -23,7 +19,7 @@ def registered_packages_meta(): ...@@ -23,7 +19,7 @@ def registered_packages_meta():
for each registed package for each registed package
""" """
packages = registered_packages packages = registered_packages
return {name: common.parse_package(PKG_DIR / name / 'meta.yaml') return {name: parse_package(PKG_DIR / name / 'meta.yaml')
for name in packages} for name in packages}
...@@ -34,7 +30,7 @@ UNSUPPORTED_PACKAGES = {'chrome': ['pandas'], ...@@ -34,7 +30,7 @@ UNSUPPORTED_PACKAGES = {'chrome': ['pandas'],
@pytest.mark.parametrize('name', registered_packages()) @pytest.mark.parametrize('name', registered_packages())
def test_import(name, selenium_standalone): def test_import(name, selenium_standalone):
# check that we can parse the meta.yaml # check that we can parse the meta.yaml
meta = common.parse_package(PKG_DIR / name / 'meta.yaml') meta = parse_package(PKG_DIR / name / 'meta.yaml')
if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]: if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]:
pytest.xfail( pytest.xfail(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment