Ejemplo n.º 1
0
def test_download_and_extract(monkeypatch):
    monkeypatch.setattr(subprocess, "run", lambda *args, **kwargs: True)
    monkeypatch.setattr(buildpkg, "check_checksum",
                        lambda *args, **kwargs: True)
    monkeypatch.setattr(shutil, "unpack_archive", lambda *args, **kwargs: True)

    test_pkgs = []

    # tarballname == version
    test_pkgs.append(parse_package_config("./packages/scipy/meta.yaml"))
    test_pkgs.append(parse_package_config("./packages/numpy/meta.yaml"))

    # tarballname != version
    test_pkgs.append({
        "package": {
            "name": "pyyaml",
            "version": "5.3.1"
        },
        "source": {
            "url":
            "https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz"
        },
    })

    for pkg in test_pkgs:
        packagedir = pkg["package"]["name"] + "-" + pkg["package"]["version"]
        buildpath = Path(pkg["package"]["name"]) / "build"
        srcpath = buildpkg.download_and_extract(buildpath,
                                                packagedir,
                                                pkg,
                                                args=None)

        assert srcpath.name.lower().endswith(packagedir.lower())
Ejemplo n.º 2
0
def test_mkpkg_update(tmpdir, monkeypatch):
    pytest.importorskip("ruamel")
    base_dir = Path(str(tmpdir))
    monkeypatch.setattr(pyodide_build.mkpkg, "PACKAGES_ROOT", base_dir)

    db_init = {
        "package": {"name": "idna", "version": "2.0"},
        "source": {
            "sha256": "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
            "url": "https://<some>/idna-2.0.tar.gz",
        },
        "test": {"imports": ["idna"]},
    }

    os.mkdir(base_dir / "idna")
    meta_path = base_dir / "idna" / "meta.yaml"
    with open(meta_path, "w") as fh:
        yaml.dump(db_init, fh)
    pyodide_build.mkpkg.update_package("idna")

    db = parse_package_config(meta_path)
    assert list(db.keys()) == list(db_init.keys())
    assert parse_version(db["package"]["version"]) > parse_version(
        db_init["package"]["version"]
    )
Ejemplo n.º 3
0
def test_import(name, selenium_standalone):
    # check that we can parse the meta.yaml
    meta = parse_package_config(PKG_DIR / name / "meta.yaml")

    if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]:
        pytest.xfail("{} fails to load and is not supported on {}.".format(
            name, selenium_standalone.browser))

    built_packages = _parse_package_subset(os.environ.get("PYODIDE_PACKAGES"))
    # only a subset of packages were built
    if built_packages is not None and name not in built_packages:
        pytest.skip(f"{name} was skipped due to PYODIDE_PACKAGES")

    selenium_standalone.run("import glob, os")

    baseline_pyc = selenium_standalone.run("""
        len(list(glob.glob(
            '/lib/python3.9/site-packages/**/*.pyc',
            recursive=True)
        ))
        """)
    for import_name in meta.get("test", {}).get("imports", []):
        selenium_standalone.run_async("import %s" % import_name)
        # Make sure that even after importing, there are no additional .pyc
        # files
        assert (selenium_standalone.run("""
            len(list(glob.glob(
                '/lib/python3.9/site-packages/**/*.pyc',
                recursive=True)
            ))
            """) == baseline_pyc)
Ejemplo n.º 4
0
        def parse_package_info(self,
                               config: pathlib.Path) -> tuple[str, str, bool]:
            yaml_data = parse_package_config(config)

            name = yaml_data["package"]["name"]
            version = yaml_data["package"]["version"]
            is_library = yaml_data.get("build", {}).get("library", False)

            return name, version, is_library
Ejemplo n.º 5
0
def test_parse_package(name):
    # check that we can parse the meta.yaml
    meta = parse_package_config(PKG_DIR / name / "meta.yaml")

    skip_host = meta.get("build", {}).get("skip_host", True)
    if name == "numpy":
        assert skip_host is False
    elif name == "pandas":
        assert skip_host is True
Ejemplo n.º 6
0
def registered_packages_meta():
    """Returns a dictionary with the contents of `meta.yaml`
    for each registered package
    """
    packages = registered_packages
    return {
        name: parse_package_config(PKG_DIR / name / "meta.yaml")
        for name in packages
    }
Ejemplo n.º 7
0
def test_parse_package(name):
    # check that we can parse the meta.yaml
    meta = parse_package_config(PKG_DIR / name / "meta.yaml")

    sharedlibrary = meta.get("build", {}).get("sharedlibrary", False)
    if name == "sharedlib-test":
        assert sharedlibrary is True
    elif name == "sharedlib-test-py":
        assert sharedlibrary is False
Ejemplo n.º 8
0
def test_mkpkg(tmpdir, monkeypatch):
    base_dir = Path(str(tmpdir))
    monkeypatch.setattr(pyodide_build.mkpkg, "PACKAGES_ROOT", base_dir)
    pyodide_build.mkpkg.make_package("idna")
    assert os.listdir(base_dir) == ["idna"]
    meta_path = base_dir / "idna" / "meta.yaml"
    assert meta_path.exists()

    db = parse_package_config(meta_path)

    assert db["package"]["name"] == "idna"
    assert db["source"]["url"].endswith(".tar.gz")
Ejemplo n.º 9
0
def test_import(name, selenium_standalone):
    if not _package_is_built(name):
        raise AssertionError(
            "Implementation error. Test for an unbuilt package "
            "should have been skipped in selenium_standalone fixture"
        )

    meta = parse_package_config(PKG_DIR / name / "meta.yaml")

    if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]:
        pytest.xfail(
            "{} fails to load and is not supported on {}.".format(
                name, selenium_standalone.browser
            )
        )

    selenium_standalone.run("import glob, os, site")

    baseline_pyc = selenium_standalone.run(
        """
        len(list(glob.glob(
            site.getsitepackages()[0] + '/**/*.pyc',
            recursive=True)
        ))
        """
    )
    for import_name in meta.get("test", {}).get("imports", []):
        selenium_standalone.run_async("import %s" % import_name)
        # Make sure that even after importing, there are no additional .pyc
        # files
        assert (
            selenium_standalone.run(
                """
                len(list(glob.glob(
                    site.getsitepackages()[0] + '/**/*.pyc',
                    recursive=True)
                ))
                """
            )
            == baseline_pyc
        )
        # Make sure no exe files were loaded!
        assert (
            selenium_standalone.run(
                """
                len(list(glob.glob(
                    site.getsitepackages()[0] + '/**/*.exe',
                    recursive=True)
                ))
                """
            )
            == 0
        )
Ejemplo n.º 10
0
def test_prepare_source(monkeypatch):
    monkeypatch.setattr(subprocess, "run", lambda *args, **kwargs: True)
    monkeypatch.setattr(buildpkg, "check_checksum", lambda *args, **kwargs: True)
    monkeypatch.setattr(shutil, "unpack_archive", lambda *args, **kwargs: True)
    monkeypatch.setattr(shutil, "move", lambda *args, **kwargs: True)

    test_pkgs = []

    test_pkgs.append(parse_package_config(PACKAGES_DIR / "packaging/meta.yaml"))
    test_pkgs.append(parse_package_config(PACKAGES_DIR / "micropip/meta.yaml"))

    for pkg in test_pkgs:
        pkg["source"]["patches"] = []

    for pkg in test_pkgs:
        source_dir_name = pkg["package"]["name"] + "-" + pkg["package"]["version"]
        pkg_root = Path(pkg["package"]["name"])
        buildpath = pkg_root / "build"
        src_metadata = pkg["source"]
        srcpath = buildpath / source_dir_name
        buildpkg.prepare_source(pkg_root, buildpath, srcpath, src_metadata)

        assert srcpath.is_dir()
Ejemplo n.º 11
0
def test_prepare_source(monkeypatch):
    monkeypatch.setattr(subprocess, "run", lambda *args, **kwargs: True)
    monkeypatch.setattr(buildpkg, "check_checksum",
                        lambda *args, **kwargs: True)
    monkeypatch.setattr(shutil, "unpack_archive", lambda *args, **kwargs: True)
    monkeypatch.setattr(shutil, "move", lambda *args, **kwargs: True)

    test_pkgs = []

    # tarballname == version
    test_pkgs.append(parse_package_config("./packages/scipy/meta.yaml"))
    test_pkgs.append(parse_package_config("./packages/numpy/meta.yaml"))

    # tarballname != version
    test_pkgs.append({
        "package": {
            "name": "pyyaml",
            "version": "5.3.1"
        },
        "source": {
            "url":
            "https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz"
        },
    })

    for pkg in test_pkgs:
        pkg["source"]["patches"] = []

    for pkg in test_pkgs:
        source_dir_name = pkg["package"]["name"] + "-" + pkg["package"][
            "version"]
        pkg_root = Path(pkg["package"]["name"])
        buildpath = pkg_root / "build"
        src_metadata = pkg["source"]
        srcpath = buildpath / source_dir_name
        buildpkg.prepare_source(pkg_root, buildpath, srcpath, src_metadata)
Ejemplo n.º 12
0
def test_mkpkg(tmpdir, capsys, source_fmt):
    base_dir = Path(str(tmpdir))

    pyodide_build.mkpkg.make_package(base_dir, "idna", None, source_fmt)
    assert os.listdir(base_dir) == ["idna"]
    meta_path = base_dir / "idna" / "meta.yaml"
    assert meta_path.exists()
    captured = capsys.readouterr()
    assert f"Output written to {meta_path}" in captured.out

    db = parse_package_config(meta_path)

    assert db["package"]["name"] == "idna"
    if source_fmt == "wheel":
        assert db["source"]["url"].endswith(".whl")
    else:
        assert db["source"]["url"].endswith(".tar.gz")
Ejemplo n.º 13
0
def test_mkpkg_update(tmpdir, old_dist_type, new_dist_type):
    base_dir = Path(str(tmpdir))

    old_ext = ".tar.gz" if old_dist_type == "sdist" else ".whl"
    old_url = "https://<some>/idna-2.0" + old_ext
    db_init: dict[str, dict[str, str | list[str]]] = {
        "package": {
            "name": "idna",
            "version": "2.0"
        },
        "source": {
            "sha256":
            "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
            "url": old_url,
        },
        "test": {
            "imports": ["idna"]
        },
    }

    package_dir = base_dir / "idna"
    package_dir.mkdir(parents=True)
    meta_path = package_dir / "meta.yaml"
    with open(meta_path, "w") as f:
        yaml.dump(db_init, f)
    source_fmt = new_dist_type
    if new_dist_type == "same":
        source_fmt = None
    pyodide_build.mkpkg.update_package(base_dir, "idna", None, False,
                                       source_fmt)

    db = parse_package_config(meta_path)
    assert list(db.keys()) == list(db_init.keys())
    assert parse_version(db["package"]["version"]) > parse_version(
        db_init["package"]["version"]  # type: ignore[arg-type]
    )
    if new_dist_type == "wheel":
        assert db["source"]["url"].endswith(".whl")
    elif new_dist_type == "sdist":
        assert db["source"]["url"].endswith(".tar.gz")
    else:
        assert db["source"]["url"].endswith(old_ext)
Ejemplo n.º 14
0
def test_mkpkg(tmpdir, monkeypatch, capsys, source_fmt):
    pytest.importorskip("ruamel")
    assert pyodide_build.mkpkg.PACKAGES_ROOT.exists()
    base_dir = Path(str(tmpdir))
    monkeypatch.setattr(pyodide_build.mkpkg, "PACKAGES_ROOT", base_dir)

    pyodide_build.mkpkg.make_package("idna", None, source_fmt)
    assert os.listdir(base_dir) == ["idna"]
    meta_path = base_dir / "idna" / "meta.yaml"
    assert meta_path.exists()
    captured = capsys.readouterr()
    assert f"Output written to {meta_path}" in captured.out

    db = parse_package_config(meta_path)

    assert db["package"]["name"] == "idna"
    if source_fmt == "wheel":
        assert db["source"]["url"].endswith(".whl")
    else:
        assert db["source"]["url"].endswith(".tar.gz")
Ejemplo n.º 15
0
def test_mkpkg_update(tmpdir, monkeypatch, old_dist_type, new_dist_type):
    pytest.importorskip("ruamel")
    base_dir = Path(str(tmpdir))
    monkeypatch.setattr(pyodide_build.mkpkg, "PACKAGES_ROOT", base_dir)

    old_ext = ".tar.gz" if old_dist_type == "sdist" else ".whl"
    old_url = "https://<some>/idna-2.0" + old_ext
    db_init = {
        "package": {
            "name": "idna",
            "version": "2.0"
        },
        "source": {
            "sha256":
            "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
            "url": old_url,
        },
        "test": {
            "imports": ["idna"]
        },
    }

    os.mkdir(base_dir / "idna")
    meta_path = base_dir / "idna" / "meta.yaml"
    with open(meta_path, "w") as fh:
        yaml.dump(db_init, fh)
    source_fmt = new_dist_type
    if new_dist_type == "same":
        source_fmt = None
    pyodide_build.mkpkg.update_package("idna", None, source_fmt)

    db = parse_package_config(meta_path)
    assert list(db.keys()) == list(db_init.keys())
    assert parse_version(db["package"]["version"]) > parse_version(
        db_init["package"]["version"])
    if new_dist_type == "wheel":
        assert db["source"]["url"].endswith(".whl")
    elif new_dist_type == "sdist":
        assert db["source"]["url"].endswith(".tar.gz")
    else:
        assert db["source"]["url"].endswith(old_ext)