Skip to content

Commit 3f5b071

Browse files
authored
Enable test CI + more packaging improvement (#3)
1 parent b47358d commit 3f5b071

23 files changed

+2587
-32
lines changed

.github/FUNDING.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: pyodide
2+
open_collective: pyodide

.github/codecov.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
comment: false
2+
codecov:
3+
branch: main
4+
require_ci_to_pass: false
5+
notify:
6+
wait_for_ci: false

.github/workflows/main.yml

+81
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,87 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13+
download-pyodide:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
pyodide-version: [0.21.3]
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Cache Pyodide
23+
uses: actions/cache@v3
24+
id: cache-pyodide
25+
with:
26+
path: dist
27+
key: pyodide-${{ matrix.pyodide-version }}-${{ hashFiles('.github/**/*.yml') }}
28+
29+
- name: Download Pyodide
30+
shell: bash -l {0}
31+
if: steps.cache-pyodide.outputs.cache-hit != 'true'
32+
run: |
33+
wget -q https://github.com/pyodide/pyodide/releases/download/${{ matrix.pyodide-version }}/pyodide-build-${{ matrix.pyodide-version }}.tar.bz2
34+
tar xjf pyodide-build-${{ matrix.pyodide-version }}.tar.bz2
35+
mv pyodide dist/
36+
37+
test:
38+
needs: download-pyodide
39+
runs-on: ${{ matrix.os }}
40+
env:
41+
DISPLAY: :99
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
os: [ubuntu-latest]
46+
pyodide-version: [0.21.3]
47+
test-config: [
48+
{runner: selenium, runtime: chrome, chrome-version: latest, chromedriver-version: latest },
49+
]
50+
51+
steps:
52+
- uses: actions/checkout@v2
53+
54+
- uses: actions/setup-python@v3
55+
with:
56+
python-version: 3.10.2
57+
58+
59+
- name: Install chrome
60+
uses: browser-actions/setup-chrome@latest
61+
if: ${{ matrix.test-config.runner == 'selenium' && contains(matrix.test-config.runtime, 'chrome') }}
62+
with:
63+
chrome-version: ${{ matrix.test-config.geckodriver-version }}
64+
65+
- name: Install chromedriver
66+
if: ${{ matrix.test-config.runner == 'selenium' && contains(matrix.test-config.runtime, 'chrome') }}
67+
uses: nanasess/setup-chromedriver@v1
68+
69+
- name: Install requirements
70+
shell: bash -l {0}
71+
run: |
72+
python3 -m pip install -e .[test]
73+
74+
- name: Get Pyodide from cache
75+
uses: actions/cache@v3
76+
with:
77+
path: dist
78+
key: pyodide-${{ matrix.pyodide-version }}-${{ hashFiles('.github/**/*.yml') }}
79+
80+
- name: Run tests
81+
shell: bash -l {0}
82+
run: |
83+
STANDALONE_REFRESH=${{ env.STANDALONE_REFRESH }} pytest -v \
84+
--cov=micropip \
85+
--dist-dir=./dist/ \
86+
--runner=${{ matrix.test-config.runner }} \
87+
--rt ${{ matrix.test-config.runtime }}
88+
89+
- uses: codecov/codecov-action@v3
90+
if: ${{ github.event.repo.name == 'pyodide/micropip' || github.event_name == 'pull_request' }}
91+
with:
92+
fail_ci_if_error: true
93+
1394
deploy:
1495
runs-on: ubuntu-latest
1596
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__
2+
micropip/_version.py
3+
*.egg-info
4+
dist/

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
default_language_version:
22
python: "3.10"
33

4-
exclude: ^micropip/externals
4+
exclude: (^micropip/externals|^tests/vendored)
55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
77
rev: "v4.3.0"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# micropip
22

3-
[![PyPI Latest Release](https://img.shields.io/pypi/v/matplotlib-pyodide.svg)](https://pypi.org/project/micropip/)
3+
[![PyPI Latest Release](https://img.shields.io/pypi/v/micropip.svg)](https://pypi.org/project/micropip/)
44
![GHA](https://github.com/pyodide/micropip/actions/workflows/main.yml/badge.svg)
55

66
A lightweight Python package installer for the web
77

88
## Installation
99

10-
In Pyodide, you can install micropip,
10+
In [Pyodide](https://pyodide.org), you can install micropip,
1111
- either implicitly by importing it in the REPL
1212
- or explicitly via `pyodide.loadPackage('micropip')`. You can also install by URL from PyPI for instance.
1313

micropip/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
from ._micropip import _list as list
22
from ._micropip import freeze, install
33

4-
__all__ = ["install", "list", "freeze"]
4+
try:
5+
from ._version import __version__
6+
except ImportError:
7+
pass
8+
9+
__all__ = ["install", "list", "freeze", "__version__"]

pyproject.toml

+30
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1+
[project]
2+
name = "micropip"
3+
authors = [
4+
{ name="Pyodide developers"},
5+
]
6+
description = "A lightweight Python package installer for the web "
7+
readme = "README.md"
8+
license = { file="LICENSE" }
9+
requires-python = ">=3.7"
10+
classifiers = [
11+
"Programming Language :: Python :: 3",
12+
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
13+
"Operating System :: OS Independent",
14+
]
15+
dynamic = ["version"]
16+
dependencies = []
17+
[project.optional-dependencies]
18+
test = [
19+
"pytest-pyodide",
20+
"pytest-cov"
21+
]
22+
23+
24+
[project.urls]
25+
"Homepage" = "https://github.com/pyodide/micropip"
26+
"Bug Tracker" = "https://github.com/pyodide/micropip/issues"
27+
28+
29+
130
[build-system]
231
requires = ["setuptools>=42", "setuptools_scm[toml]>=6.2"]
332

433
build-backend = "setuptools.build_meta"
534

635
# Evable versioning via setuptools_scm
736
[tool.setuptools_scm]
37+
write_to = "micropip/_version.py"
838

939
[tool.pycln]
1040
all = true

setup.py

-15
This file was deleted.

tests/test_micropip.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99
from pytest_pyodide import run_in_pyodide, spawn_web_server
1010

11-
sys.path.append(str(Path(__file__).resolve().parent / "src"))
11+
sys.path.append(str(Path(__file__).resolve().parent / "vendored"))
1212

1313
from importlib.metadata import Distribution, PackageNotFoundError
1414

@@ -19,17 +19,26 @@
1919
except ImportError:
2020
pass
2121

22-
from pyodide_build import common
22+
EMSCRIPTEN_VER = "3.1.14"
23+
24+
25+
def _platform() -> str:
26+
# Vendored from pyodide_build.common
27+
version = EMSCRIPTEN_VER.replace(".", "_")
28+
return f"emscripten_{version}_wasm32"
29+
30+
31+
PLATFORM = _platform()
2332

2433
cpver = f"cp{sys.version_info.major}{sys.version_info.minor}"
2534

2635

2736
@pytest.fixture
2837
def mock_platform(monkeypatch):
29-
monkeypatch.setenv("_PYTHON_HOST_PLATFORM", common.platform())
38+
monkeypatch.setenv("_PYTHON_HOST_PLATFORM", _platform())
3039
from micropip import _micropip
3140

32-
monkeypatch.setattr(_micropip, "get_platform", common.platform)
41+
monkeypatch.setattr(_micropip, "get_platform", _platform)
3342

3443

3544
def _mock_importlib_version(name: str) -> str:
@@ -82,7 +91,7 @@ def make_wheel_filename(name: str, version: str, platform: str = "generic") -> s
8291
if platform == "generic":
8392
platform_str = "py3-none-any"
8493
elif platform == "emscripten":
85-
platform_str = f"{cpver}-{cpver}-{common.platform()}"
94+
platform_str = f"{cpver}-{cpver}-{_platform()}"
8695
elif platform == "native":
8796
platform_str = f"{cpver}-{cpver}-manylinux_2_31_x86_64"
8897
else:
@@ -272,7 +281,7 @@ def test_parse_wheel_url3():
272281
def test_install_custom_url(selenium_standalone_micropip, base_url):
273282
selenium = selenium_standalone_micropip
274283

275-
with spawn_web_server(Path(__file__).parent / "test") as server:
284+
with spawn_web_server(Path(__file__).parent / "dist") as server:
276285
server_hostname, server_port, _ = server
277286
base_url = f"http://{server_hostname}:{server_port}/"
278287
url = base_url + SNOWBALL_WHEEL
@@ -325,7 +334,7 @@ async def test_add_requirement():
325334
pytest.importorskip("packaging")
326335
from micropip._micropip import Transaction
327336

328-
with spawn_web_server(Path(__file__).parent / "test") as server:
337+
with spawn_web_server(Path(__file__).parent / "dist") as server:
329338
server_hostname, server_port, _ = server
330339
base_url = f"http://{server_hostname}:{server_port}/"
331340
url = base_url + SNOWBALL_WHEEL
@@ -673,7 +682,7 @@ async def test_list_wheel_name_mismatch(mock_fetch: mock_fetch_cls) -> None:
673682

674683

675684
def test_list_load_package_from_url(selenium_standalone_micropip):
676-
with spawn_web_server(Path(__file__).parent / "test") as server:
685+
with spawn_web_server(Path(__file__).parent / "dist") as server:
677686
server_hostname, server_port, _ = server
678687
base_url = f"http://{server_hostname}:{server_port}/"
679688
url = base_url + SNOWBALL_WHEEL
@@ -808,7 +817,7 @@ async def test_freeze(mock_fetch: mock_fetch_cls) -> None:
808817

809818

810819
def test_emfs(selenium_standalone_micropip):
811-
with spawn_web_server(Path(__file__).parent / "test") as server:
820+
with spawn_web_server(Path(__file__).parent / "dist") as server:
812821
server_hostname, server_port, _ = server
813822
url = f"http://{server_hostname}:{server_port}/"
814823

@@ -843,10 +852,6 @@ def raiseValueError(msg):
843852
return pytest.raises(ValueError, match=msg)
844853

845854

846-
PLATFORM = common.platform()
847-
EMSCRIPTEN_VER = common.emscripten_version()
848-
849-
850855
@pytest.mark.parametrize(
851856
"interp, abi, arch,ctx",
852857
[

tests/vendored/_pyodide/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# _pyodide is imported at the very beginning of the initialization process so it
2+
# cannot import from js, pyodide_js, or _pyodide_core. The one class here that
3+
# does use such functions is JsFinder which requires access to
4+
# _pyodide_core.JsProxy.
5+
#
6+
# register_js_finder is called from pyodide.js after _pyodide_core is completely
7+
# initialized.
8+
#
9+
# All pure Python code that doesn't require imports from js, pyodide_js, or
10+
# _pyodide_core belongs in _pyodide. Code that requires such imports belongs in
11+
# pyodide.
12+
from . import _base, _importhook
13+
14+
__all__ = ["_base", "_importhook"]

0 commit comments

Comments
 (0)