Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add add_mock_package #26

Merged
merged 34 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
525d0d7
added support for creating mock packages
joemarshall Nov 17, 2022
111046f
Merge branch 'main' of github.com:pyodide/micropip into add_package_mock
joemarshall Nov 17, 2022
799560d
reverted typo change
joemarshall Nov 17, 2022
f66370c
removed unneeded imports
joemarshall Nov 17, 2022
43fa3f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 17, 2022
16739f5
remembered to run pre-commit hooks
joemarshall Nov 17, 2022
0a6471a
added test
joemarshall Nov 17, 2022
5e5b0d9
removed debug print
joemarshall Nov 17, 2022
0eb9803
merged and linted
joemarshall Nov 17, 2022
20b74f0
Merge branch 'add_package_mock' of https://github.com/joemarshall/mic…
joemarshall Nov 17, 2022
c76a8e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 17, 2022
3418848
dist-info metadata for easier package finding etc.
joemarshall Nov 23, 2022
ea8c424
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 23, 2022
6628396
added support for temporary modules
joemarshall Nov 23, 2022
9cb4ac2
default to non-persistent mocking
joemarshall Nov 23, 2022
d6aab95
in memory sub packages fixes
joemarshall Nov 23, 2022
005efec
Merge branch 'add_package_mock' of https://github.com/joemarshall/mic…
joemarshall Nov 23, 2022
a12cd86
test in pyodide with correct (local) version of micropip
joemarshall Nov 23, 2022
10c7f84
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 23, 2022
5d96d84
fixed missing package in test
joemarshall Nov 23, 2022
786e5e8
Merge branch 'add_package_mock' of https://github.com/joemarshall/mic…
joemarshall Nov 23, 2022
35539ef
dedent in memory modules
joemarshall Nov 23, 2022
107004d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 23, 2022
ac8bc37
simpler std output capture
joemarshall Nov 23, 2022
98b9192
Merge branch 'add_package_mock' of https://github.com/joemarshall/mic…
joemarshall Nov 23, 2022
e83cb59
invalidate importlib cache for pyodide
joemarshall Nov 23, 2022
4d719c2
testing different order to see what is broken
joemarshall Nov 23, 2022
fd037ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 23, 2022
3b77d88
fixed tests for pyodide
joemarshall Nov 23, 2022
782b6af
Merge branch 'add_package_mock' of https://github.com/joemarshall/mic…
joemarshall Nov 23, 2022
d34ff58
review fixes
joemarshall Nov 24, 2022
5e8f5e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 24, 2022
2c34df0
added changelog
joemarshall Nov 24, 2022
9c16b28
Merge branch 'add_package_mock' of https://github.com/joemarshall/mic…
joemarshall Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed tests for pyodide
  • Loading branch information
joemarshall committed Nov 23, 2022
commit 3b77d88e4b824a60b4f229f71a1e6d8cbbfa03f0
6 changes: 6 additions & 0 deletions micropip/_micropip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import shutil
import site
import sys
import warnings
from asyncio import gather
from dataclasses import dataclass, field
Expand Down Expand Up @@ -782,6 +783,11 @@ def init_fn(module):
if persistent:
# make empty mock modules with the requested names in user site packages
site_packages = Path(site.getusersitepackages())
# in pyodide site packages isn't on sys.path initially
if not site_packages.exists():
site_packages.mkdir(parents=True, exist_ok=True)
if site_packages not in sys.path:
sys.path.append(str(site_packages))
metadata_dir = site_packages / (name + "-" + version + ".dist-info")
metadata_dir.mkdir(parents=True, exist_ok=False)
metadata_file = metadata_dir / "METADATA"
Expand Down
7 changes: 3 additions & 4 deletions tests/test_micropip.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ def test_check_compatible(mock_platform, interp, abi, arch, ctx):


@run_in_pyodide()
def test_add_mock_package_in_pyodide(selenium_standalone_micropip): #
def test_persistent_mock_pyodide(selenium_standalone_micropip): #
import sys
from importlib.metadata import version as importlib_version
from io import StringIO
Expand All @@ -948,7 +948,6 @@ def test_add_mock_package_in_pyodide(selenium_standalone_micropip): #
capture_stdio = StringIO()

sys.stdout = capture_stdio

add_mock_package("test_1", "1.0.0", persistent=True)
add_mock_package(
"test_2",
Expand Down Expand Up @@ -979,7 +978,7 @@ def fn():
assert importlib_version("test_1") == "1.0.0"


def test_add_mock_package(monkeypatch, capsys):
def test_persistent_mock(monkeypatch, capsys):
import site
from importlib.metadata import version as importlib_version

Expand Down Expand Up @@ -1069,7 +1068,7 @@ def mod_init(module):


@run_in_pyodide()
def test_memory_mock_in_pyodide(selenium_standalone_micropip):
def test_memory_mock_pyodide(selenium_standalone_micropip):
from micropip import _micropip

def mod_init(module):
Expand Down