Skip to content

Commit

Permalink
Test under python 3.12 (#1167)
Browse files Browse the repository at this point in the history
* test: test under python 3.12

* fix: use shell=True rather than shutil.which to find npm binary

This works around a bug in python 3.12.0's `shutil.which` when running
on Windows.

See python/cpython#109590
  • Loading branch information
dairiki committed Nov 2, 2023
1 parent 66dcd82 commit ffa0f49
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,26 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
exclude:
- os: "macos-latest"
python: "3.8"
- os: "macos-latest"
python: "3.9"
- os: "macos-latest"
python: "3.10"
- os: "macos-latest"
python: "3.11"
- os: "windows-latest"
python: "3.8"
- os: "windows-latest"
python: "3.9"
- os: "windows-latest"
python: "3.10"
- os: "windows-latest"
python: "3.11"
include:
- python: "3.11"
- python: "3.12"
install-ffmpeg: true
steps:
- uses: actions/checkout@v3
Expand Down
14 changes: 9 additions & 5 deletions build_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ def initialize(self, version, build_data):
app.display_info(f"{APP_JS} exists, skipping frontend build")
return

npm = shutil.which("npm")
if npm is None:
app.abort("npm is not available. can not build frontend")
try:
proc = subprocess.run(
"npm -v", capture_output=True, text=True, shell=True, check=True
)
except subprocess.CalledProcessError as exc:
app.abort(f"{exc.cmd!r} failed (is node/npm installed?)")
app.display_info(f"found npm version {proc.stdout.strip()}")

frontend = Path(root, FRONTEND)
if not frontend.is_dir():
app.abort("frontend source is missing. can not build frontend")

app.display_info("npm install")
subprocess.run((npm, "install"), cwd=frontend, check=True)
subprocess.run("npm install", cwd=frontend, shell=True, check=True)
app.display_info("npm run build")
subprocess.run((npm, "run", "build"), cwd=frontend, check=True)
subprocess.run("npm run build", cwd=frontend, shell=True, check=True)
app.display_success("built frontend static files")
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules",
]
Expand Down
7 changes: 5 additions & 2 deletions tests/test_build_frontend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the hatch build hooks in ../build_frontend.py."""
import os
import shutil
import sys
from importlib.util import module_from_spec
Expand Down Expand Up @@ -81,8 +82,10 @@ def test_initialize_skips_build_if_output_exists(


@pytest.mark.usefixtures("frontend_src")
def test_initialize_aborts_if_no_npm(frontend_build_hook, mocker):
mocker.patch("shutil.which").return_value = None
def test_initialize_aborts_if_no_npm(
frontend_build_hook, frontend_build_module, monkeypatch
):
monkeypatch.setitem(os.environ, "PATH", "")
with pytest.raises(SystemExit) as exc_info:
frontend_build_hook.initialize("standard", build_data={})
assert exc_info.value.args[0] == 1
Expand Down
9 changes: 5 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
minversion = 4.1
envlist =
lint
{py37,py38,py39,py310,py311}{,-mistune0}
{py37,py38,py39,py310,py311,py312}{,-mistune0}
py311-noutils
py311-pytz
py311-tzdata
Expand All @@ -18,6 +18,7 @@ python =
3.9: py39, cover
3.10: py310, cover
3.11: py311, cover
3.12: py312, cover

[testenv]
commands =
Expand All @@ -42,8 +43,8 @@ deps =
pillow6: pillow<6.1.0
pillow7: pillow<7.1.0
depends =
py{37,38,39,310,311}: cover-clean
cover-report: py{37,38,39,310,311}{,-mistune0,-noutils,-pytz,-tzdata,-pillow6,-pillow7}
py{37,38,39,310,311,312}: cover-clean
cover-report: py{37,38,39,310,311,312}{,-mistune0,-noutils,-pytz,-tzdata,-pillow6,-pillow7}
# XXX: I've been experiencing sporadic failures when running tox in parallel mode.
# The crux of the error messages when this happens appears to be something like:
#
Expand All @@ -63,7 +64,7 @@ depends =
# Hopefully, at some point this can be removed.
download = true

[testenv:py{37,38,39,310,311}-noutils]
[testenv:py{37,38,39,310,311,312}-noutils]
# To test in environment without external utitilities like ffmpeg and git installed,
# break PATH in noutils environment(s).
allowlist_externals = env
Expand Down

0 comments on commit ffa0f49

Please sign in to comment.