Skip to content

Commit

Permalink
Enable test CI + more packaging improvement (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
rth authored Sep 18, 2022
1 parent b47358d commit 3f5b071
Show file tree
Hide file tree
Showing 23 changed files with 2,587 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: pyodide
open_collective: pyodide
6 changes: 6 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
comment: false
codecov:
branch: main
require_ci_to_pass: false
notify:
wait_for_ci: false
81 changes: 81 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,87 @@ concurrency:
cancel-in-progress: true

jobs:
download-pyodide:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pyodide-version: [0.21.3]
steps:
- uses: actions/checkout@v2

- name: Cache Pyodide
uses: actions/cache@v3
id: cache-pyodide
with:
path: dist
key: pyodide-${{ matrix.pyodide-version }}-${{ hashFiles('.github/**/*.yml') }}

- name: Download Pyodide
shell: bash -l {0}
if: steps.cache-pyodide.outputs.cache-hit != 'true'
run: |
wget -q https://github.com/pyodide/pyodide/releases/download/${{ matrix.pyodide-version }}/pyodide-build-${{ matrix.pyodide-version }}.tar.bz2
tar xjf pyodide-build-${{ matrix.pyodide-version }}.tar.bz2
mv pyodide dist/
test:
needs: download-pyodide
runs-on: ${{ matrix.os }}
env:
DISPLAY: :99
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
pyodide-version: [0.21.3]
test-config: [
{runner: selenium, runtime: chrome, chrome-version: latest, chromedriver-version: latest },
]

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v3
with:
python-version: 3.10.2


- name: Install chrome
uses: browser-actions/setup-chrome@latest
if: ${{ matrix.test-config.runner == 'selenium' && contains(matrix.test-config.runtime, 'chrome') }}
with:
chrome-version: ${{ matrix.test-config.geckodriver-version }}

- name: Install chromedriver
if: ${{ matrix.test-config.runner == 'selenium' && contains(matrix.test-config.runtime, 'chrome') }}
uses: nanasess/setup-chromedriver@v1

- name: Install requirements
shell: bash -l {0}
run: |
python3 -m pip install -e .[test]
- name: Get Pyodide from cache
uses: actions/cache@v3
with:
path: dist
key: pyodide-${{ matrix.pyodide-version }}-${{ hashFiles('.github/**/*.yml') }}

- name: Run tests
shell: bash -l {0}
run: |
STANDALONE_REFRESH=${{ env.STANDALONE_REFRESH }} pytest -v \
--cov=micropip \
--dist-dir=./dist/ \
--runner=${{ matrix.test-config.runner }} \
--rt ${{ matrix.test-config.runtime }}
- uses: codecov/codecov-action@v3
if: ${{ github.event.repo.name == 'pyodide/micropip' || github.event_name == 'pull_request' }}
with:
fail_ci_if_error: true

deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__
micropip/_version.py
*.egg-info
dist/
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_language_version:
python: "3.10"

exclude: ^micropip/externals
exclude: (^micropip/externals|^tests/vendored)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.3.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# micropip

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

A lightweight Python package installer for the web

## Installation

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

Expand Down
7 changes: 6 additions & 1 deletion micropip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from ._micropip import _list as list
from ._micropip import freeze, install

__all__ = ["install", "list", "freeze"]
try:
from ._version import __version__
except ImportError:
pass

__all__ = ["install", "list", "freeze", "__version__"]
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
[project]
name = "micropip"
authors = [
{ name="Pyodide developers"},
]
description = "A lightweight Python package installer for the web "
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Operating System :: OS Independent",
]
dynamic = ["version"]
dependencies = []
[project.optional-dependencies]
test = [
"pytest-pyodide",
"pytest-cov"
]


[project.urls]
"Homepage" = "https://github.com/pyodide/micropip"
"Bug Tracker" = "https://github.com/pyodide/micropip/issues"



[build-system]
requires = ["setuptools>=42", "setuptools_scm[toml]>=6.2"]

build-backend = "setuptools.build_meta"

# Evable versioning via setuptools_scm
[tool.setuptools_scm]
write_to = "micropip/_version.py"

[tool.pycln]
all = true
Expand Down
15 changes: 0 additions & 15 deletions setup.py

This file was deleted.

31 changes: 18 additions & 13 deletions tests/test_micropip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
from pytest_pyodide import run_in_pyodide, spawn_web_server

sys.path.append(str(Path(__file__).resolve().parent / "src"))
sys.path.append(str(Path(__file__).resolve().parent / "vendored"))

from importlib.metadata import Distribution, PackageNotFoundError

Expand All @@ -19,17 +19,26 @@
except ImportError:
pass

from pyodide_build import common
EMSCRIPTEN_VER = "3.1.14"


def _platform() -> str:
# Vendored from pyodide_build.common
version = EMSCRIPTEN_VER.replace(".", "_")
return f"emscripten_{version}_wasm32"


PLATFORM = _platform()

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


@pytest.fixture
def mock_platform(monkeypatch):
monkeypatch.setenv("_PYTHON_HOST_PLATFORM", common.platform())
monkeypatch.setenv("_PYTHON_HOST_PLATFORM", _platform())
from micropip import _micropip

monkeypatch.setattr(_micropip, "get_platform", common.platform)
monkeypatch.setattr(_micropip, "get_platform", _platform)


def _mock_importlib_version(name: str) -> str:
Expand Down Expand Up @@ -82,7 +91,7 @@ def make_wheel_filename(name: str, version: str, platform: str = "generic") -> s
if platform == "generic":
platform_str = "py3-none-any"
elif platform == "emscripten":
platform_str = f"{cpver}-{cpver}-{common.platform()}"
platform_str = f"{cpver}-{cpver}-{_platform()}"
elif platform == "native":
platform_str = f"{cpver}-{cpver}-manylinux_2_31_x86_64"
else:
Expand Down Expand Up @@ -272,7 +281,7 @@ def test_parse_wheel_url3():
def test_install_custom_url(selenium_standalone_micropip, base_url):
selenium = selenium_standalone_micropip

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

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


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


def test_emfs(selenium_standalone_micropip):
with spawn_web_server(Path(__file__).parent / "test") as server:
with spawn_web_server(Path(__file__).parent / "dist") as server:
server_hostname, server_port, _ = server
url = f"http://{server_hostname}:{server_port}/"

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


PLATFORM = common.platform()
EMSCRIPTEN_VER = common.emscripten_version()


@pytest.mark.parametrize(
"interp, abi, arch,ctx",
[
Expand Down
14 changes: 14 additions & 0 deletions tests/vendored/_pyodide/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# _pyodide is imported at the very beginning of the initialization process so it
# cannot import from js, pyodide_js, or _pyodide_core. The one class here that
# does use such functions is JsFinder which requires access to
# _pyodide_core.JsProxy.
#
# register_js_finder is called from pyodide.js after _pyodide_core is completely
# initialized.
#
# All pure Python code that doesn't require imports from js, pyodide_js, or
# _pyodide_core belongs in _pyodide. Code that requires such imports belongs in
# pyodide.
from . import _base, _importhook

__all__ = ["_base", "_importhook"]
Loading

0 comments on commit 3f5b071

Please sign in to comment.