2021-09-02 20:19:23 +00:00
|
|
|
import functools
|
2022-02-21 22:27:03 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import pytest
|
2021-09-02 20:19:23 +00:00
|
|
|
|
2022-05-08 07:52:08 +00:00
|
|
|
from conftest import ROOT_PATH, package_is_built
|
2021-01-11 07:59:22 +00:00
|
|
|
from pyodide_build.io import parse_package_config
|
2018-08-03 11:57:51 +00:00
|
|
|
|
2022-01-24 01:47:04 +00:00
|
|
|
PKG_DIR = ROOT_PATH / "packages"
|
2018-08-03 11:57:51 +00:00
|
|
|
|
|
|
|
|
2021-09-02 20:19:23 +00:00
|
|
|
@functools.cache
|
2022-02-20 22:13:37 +00:00
|
|
|
def registered_packages() -> list[str]:
|
2019-12-09 13:56:40 +00:00
|
|
|
"""Returns a list of registered package names"""
|
2020-07-08 14:58:10 +00:00
|
|
|
packages = []
|
|
|
|
for name in os.listdir(PKG_DIR):
|
|
|
|
if (PKG_DIR / name).is_dir() and (PKG_DIR / name / "meta.yaml").exists():
|
|
|
|
packages.append(name)
|
2018-08-03 11:57:51 +00:00
|
|
|
return packages
|
|
|
|
|
|
|
|
|
2022-02-20 22:13:37 +00:00
|
|
|
UNSUPPORTED_PACKAGES: dict[str, list[str]] = {
|
2022-01-07 19:06:52 +00:00
|
|
|
"chrome": [],
|
2021-06-19 22:49:25 +00:00
|
|
|
"firefox": [],
|
2022-06-09 12:04:28 +00:00
|
|
|
"node": ["cmyt", "yt", "galpy"],
|
2021-06-19 22:49:25 +00:00
|
|
|
}
|
2022-04-09 01:42:45 +00:00
|
|
|
if "CI" in os.environ:
|
|
|
|
UNSUPPORTED_PACKAGES["chrome"].extend(["statsmodels"])
|
2018-08-16 09:34:42 +00:00
|
|
|
|
|
|
|
|
2020-06-28 18:24:40 +00:00
|
|
|
@pytest.mark.parametrize("name", registered_packages())
|
2018-10-29 11:52:13 +00:00
|
|
|
def test_parse_package(name):
|
|
|
|
# check that we can parse the meta.yaml
|
2021-01-11 07:59:22 +00:00
|
|
|
meta = parse_package_config(PKG_DIR / name / "meta.yaml")
|
2018-10-29 11:52:13 +00:00
|
|
|
|
No replay (#2256)
Our package build process currently has a significant flaw: we first run setup.py, recording all compilation commands, then we rewrite these compilation commands to invoke emcc and replay them, and then we pray that the cross compiled executables ended up in the right place to go into the wheel. This is not a good strategy because the build script is allowed to implement arbitrary logic, and if it moves, renames, etc any of the output files then we lose track of them. This has repeatedly caused difficulty for us.
However, we also make no particularly significant use of the two pass approach. We can just do the simpler thing: capture the compiler commands as they occur, modify them as needed, and then run the fixed command.
I also added a patch to fix the numpy feature detection for wasm so that we don't have to include _npyconfig.h and config.h, numpy can generate them in the way it would for a native build. I opened a numpy PR that would fix the detection for us upstream:
numpy/numpy#21154
This clears the way for us to switch to using pypa/build (as @henryiii has suggested) by removing our dependence on specific setuptools behavior.
This is on top of #2238.
2022-03-13 18:39:06 +00:00
|
|
|
sharedlibrary = meta.get("build", {}).get("sharedlibrary", False)
|
|
|
|
if name == "sharedlib-test":
|
|
|
|
assert sharedlibrary is True
|
|
|
|
elif name == "sharedlib-test-py":
|
|
|
|
assert sharedlibrary is False
|
2018-10-29 11:52:13 +00:00
|
|
|
|
|
|
|
|
2021-03-24 23:32:26 +00:00
|
|
|
@pytest.mark.skip_refcount_check
|
2022-04-20 07:50:33 +00:00
|
|
|
@pytest.mark.driver_timeout(60)
|
2020-06-28 18:24:40 +00:00
|
|
|
@pytest.mark.parametrize("name", registered_packages())
|
2018-08-20 17:02:12 +00:00
|
|
|
def test_import(name, selenium_standalone):
|
2022-05-08 07:52:08 +00:00
|
|
|
if not package_is_built(name):
|
2021-11-21 17:26:33 +00:00
|
|
|
raise AssertionError(
|
|
|
|
"Implementation error. Test for an unbuilt package "
|
|
|
|
"should have been skipped in selenium_standalone fixture"
|
|
|
|
)
|
|
|
|
|
2021-01-11 07:59:22 +00:00
|
|
|
meta = parse_package_config(PKG_DIR / name / "meta.yaml")
|
2018-08-03 11:57:51 +00:00
|
|
|
|
2018-08-20 15:09:23 +00:00
|
|
|
if name in UNSUPPORTED_PACKAGES[selenium_standalone.browser]:
|
2018-08-16 09:34:42 +00:00
|
|
|
pytest.xfail(
|
2020-06-28 18:24:40 +00:00
|
|
|
"{} fails to load and is not supported on {}.".format(
|
|
|
|
name, selenium_standalone.browser
|
|
|
|
)
|
|
|
|
)
|
2018-08-16 09:34:42 +00:00
|
|
|
|
2022-04-09 20:41:10 +00:00
|
|
|
selenium_standalone.run("import glob, os, site")
|
2018-11-08 20:03:30 +00:00
|
|
|
|
|
|
|
baseline_pyc = selenium_standalone.run(
|
2022-04-09 20:41:10 +00:00
|
|
|
"""
|
2018-11-08 20:03:30 +00:00
|
|
|
len(list(glob.glob(
|
2022-04-09 20:41:10 +00:00
|
|
|
site.getsitepackages()[0] + '/**/*.pyc',
|
2018-11-08 20:03:30 +00:00
|
|
|
recursive=True)
|
|
|
|
))
|
|
|
|
"""
|
|
|
|
)
|
2020-06-28 18:24:40 +00:00
|
|
|
for import_name in meta.get("test", {}).get("imports", []):
|
2021-02-09 22:39:07 +00:00
|
|
|
selenium_standalone.run_async("import %s" % import_name)
|
2018-11-08 20:25:21 +00:00
|
|
|
# Make sure that even after importing, there are no additional .pyc
|
|
|
|
# files
|
2020-06-28 18:24:40 +00:00
|
|
|
assert (
|
|
|
|
selenium_standalone.run(
|
2022-04-09 20:41:10 +00:00
|
|
|
"""
|
2022-01-24 01:47:04 +00:00
|
|
|
len(list(glob.glob(
|
2022-04-09 20:41:10 +00:00
|
|
|
site.getsitepackages()[0] + '/**/*.pyc',
|
2022-01-24 01:47:04 +00:00
|
|
|
recursive=True)
|
|
|
|
))
|
|
|
|
"""
|
2020-06-28 18:24:40 +00:00
|
|
|
)
|
|
|
|
== baseline_pyc
|
|
|
|
)
|
2022-01-24 01:47:04 +00:00
|
|
|
# Make sure no exe files were loaded!
|
|
|
|
assert (
|
|
|
|
selenium_standalone.run(
|
2022-04-09 20:41:10 +00:00
|
|
|
"""
|
2022-01-24 01:47:04 +00:00
|
|
|
len(list(glob.glob(
|
2022-04-09 20:41:10 +00:00
|
|
|
site.getsitepackages()[0] + '/**/*.exe',
|
2022-01-24 01:47:04 +00:00
|
|
|
recursive=True)
|
|
|
|
))
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
== 0
|
|
|
|
)
|