Skip to content

Commit 5b3f4bb

Browse files
authored
Use hatch-vcs for versioning pyodide-build (#4)
Instead of updating the version number manually, this use `hatch-vcs` and use git metadata to handle the version. Just same as micropip and pytest-pyodide.
1 parent 4a3accd commit 5b3f4bb

8 files changed

+27
-15
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.27.0] - 2024/06/18
11+
1012
- pyodide-build is now developed under https://github.com/pyodide/pyodide-build.

pyodide_build/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
__version__ = "0.27.0.dev0"
1+
from importlib.metadata import PackageNotFoundError, version
2+
3+
try:
4+
__version__ = version("pyodide-build")
5+
except PackageNotFoundError:
6+
__version__ = "1.0.0.dev0"

pyodide_build/tests/test_build_env.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_get_build_environment_vars_host_env(
125125
assert "RANDOM_ENV" not in e
126126

127127

128-
def test_check_emscripten_version(monkeypatch):
128+
def test_check_emscripten_version(dummy_xbuildenv, monkeypatch):
129129
s = None
130130

131131
def get_emscripten_version_info():
@@ -179,7 +179,7 @@ def get_emscripten_version_info(): # type: ignore[no-redef]
179179
build_env.check_emscripten_version()
180180

181181

182-
def test_wheel_paths():
182+
def test_wheel_paths(dummy_xbuildenv):
183183
from pathlib import Path
184184

185185
old_version = "cp38"

pyodide_build/tests/test_buildall.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_generate_dependency_graph_disabled():
4848
assert set(pkg_map.keys()) == set()
4949

5050

51-
def test_generate_lockfile(tmp_path):
51+
def test_generate_lockfile(tmp_path, dummy_xbuildenv):
5252
pkg_map = buildall.generate_dependency_graph(
5353
RECIPE_DIR, {"pkg_1", "pkg_2", "libtest", "libtest_shared"}
5454
)

pyodide_build/tests/test_buildpkg.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import pydantic
88
import pytest
99

10-
from pyodide_build import build_env, buildpkg, common
11-
from pyodide_build.build_env import BuildArgs, get_pyodide_root
10+
from pyodide_build import buildpkg, common
11+
from pyodide_build.build_env import BuildArgs
1212
from pyodide_build.buildpkg import RecipeBuilder
1313
from pyodide_build.io import _SourceSpec
1414

@@ -72,7 +72,6 @@ class subprocess_result:
7272
returncode = 0
7373
stdout = ""
7474

75-
build_env.get_build_environment_vars(get_pyodide_root())
7675
monkeypatch.setattr(subprocess, "run", lambda *args, **kwargs: subprocess_result)
7776
monkeypatch.setattr(buildpkg, "check_checksum", lambda *args, **kwargs: True)
7877
monkeypatch.setattr(shutil, "unpack_archive", lambda *args, **kwargs: True)

pyodide_build/tests/test_cli.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_build_recipe_no_deps_continue(tmp_path, dummy_xbuildenv, mock_emscripte
233233
assert f"{pkg}-{version}-py3-none-any.whl" in result.stdout
234234

235235

236-
def test_config_list():
236+
def test_config_list(dummy_xbuildenv):
237237
result = runner.invoke(
238238
config.app,
239239
[
@@ -249,7 +249,7 @@ def test_config_list():
249249

250250

251251
@pytest.mark.parametrize("cfg_name,env_var", config.PYODIDE_CONFIGS.items())
252-
def test_config_get(cfg_name, env_var):
252+
def test_config_get(cfg_name, env_var, dummy_xbuildenv):
253253
result = runner.invoke(
254254
config.app,
255255
[
@@ -411,7 +411,7 @@ def my_get_config_vars(*args):
411411
assert so_file.endswith(".cpython-311-wasm32-emscripten.so")
412412

413413

414-
def test_build_exports(monkeypatch):
414+
def test_build_exports(monkeypatch, dummy_xbuildenv):
415415
def download_url_shim(url, tmppath):
416416
(tmppath / "build").mkdir()
417417
return "blah"
@@ -469,7 +469,7 @@ def run(*args):
469469
)
470470

471471

472-
def test_build_config_settings(monkeypatch):
472+
def test_build_config_settings(monkeypatch, dummy_xbuildenv):
473473
app = typer.Typer()
474474

475475
app.command(

pyodide_build/xbuildenv.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import shutil
33
import subprocess
4+
import warnings
45
from pathlib import Path
56
from tempfile import NamedTemporaryFile
67
from urllib.request import urlopen
@@ -273,7 +274,12 @@ def _download(self, url: str, path: Path) -> None:
273274
with NamedTemporaryFile(suffix=".tar") as f:
274275
f_path = Path(f.name)
275276
f_path.write_bytes(data)
276-
shutil.unpack_archive(str(f_path), path)
277+
with warnings.catch_warnings():
278+
# Python 3.12-3.13 emits a DeprecationWarning when using shutil.unpack_archive without a filter,
279+
# but filter doesn't work well for zip files, so we suppress the warning until we find a better solution.
280+
# https://github.com/python/cpython/issues/112760
281+
warnings.simplefilter("ignore")
282+
shutil.unpack_archive(str(f_path), path)
277283

278284
def _install_cross_build_packages(
279285
self, xbuildenv_root: Path, xbuildenv_pyodide_root: Path

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = ["hatchling", "hatch-vcs"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -66,8 +66,8 @@ test = [
6666
"packaging",
6767
]
6868

69-
[tool.hatch]
70-
version.path = "pyodide_build/__init__.py"
69+
[tool.hatch.version]
70+
source = "vcs"
7171

7272
[tool.hatch.build.targets.sdist]
7373
exclude = [

0 commit comments

Comments
 (0)