Skip to content

Commit

Permalink
Test on Python 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed Apr 16, 2024
1 parent 310690d commit 6eefa0a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 32 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
python-version: ["3.11", "3.12"]
include:
- { os: ubuntu-latest, python-version: "3.10" }
# - os: ubuntu-latest
# python-version: "3.13"
# python-install-version: "3.13-dev"
- os: ubuntu-latest
python-version: "3.13"
python-install-version: "3.13-dev"
runs-on: ${{ matrix.os }}
steps:
- name: Clone the repo
Expand Down Expand Up @@ -75,9 +75,9 @@ jobs:
python-version: ["3.11", "3.12"]
include:
- { os: ubuntu-latest, python-version: "3.10" }
# - os: ubuntu-latest
# python-version: "3.13"
# python-install-version: "3.13-dev"
- os: ubuntu-latest
python-version: "3.13"
python-install-version: "3.13-dev"
runs-on: ${{ matrix.os }}
steps:
- name: Clone the repo
Expand Down
50 changes: 40 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
import tempfile
from importlib.metadata import Distribution
from pathlib import Path

Expand All @@ -11,7 +12,7 @@
nox.options.error_on_external_run = True


def install_coverage_hook(session: nox.Session):
def _install_coverage_hook(session: nox.Session):
session.run(
'python',
'-c',
Expand All @@ -27,6 +28,28 @@ def install_coverage_hook(session: nox.Session):
)


def _session_install_for_python313(session: nox.Session, install_args: list[str]):
with tempfile.TemporaryDirectory() as temp_dir:
constraints_txt = Path(temp_dir, 'python313-constraints.txt')
constraints_txt.write_text("""\
sqlalchemy @ git+https://github.com/sqlalchemy/sqlalchemy ; python_version >= "3.13"
truststore @ git+https://github.com/sethmlarson/truststore@support-for-python-313 ; python_version >= "3.13"
""")

session.install(
'-c',
os.fspath(constraints_txt),
*install_args,
env={f'{p}_NO_EXTENSIONS': '1' for p in ['AIOHTTP', 'MULTIDICT', 'YARL']},
)


@nox.session(reuse_venv=True)
def dev_env(session: nox.Session):
_session_install_for_python313(session, ['-e', '.[gui, test, types]'])
print(session.virtualenv.bin, end='')


@nox.session(name='format')
def format_code(session: nox.Session):
"Format source code."
Expand Down Expand Up @@ -70,21 +93,25 @@ def test(session: nox.Session, minimum_versions: bool):
wheel_metadata_json,
)['wheel-path']

install_requires = [
install_args = [
f'instawow[gui, test] @ {package_path}',
'instawow_test_plugin @ tests/plugin',
]

if minimum_versions:
(package_metadata,) = Distribution.discover(name='instawow', path=[package_path])

session.install(
'--resolution', 'lowest-direct', *install_requires, *package_metadata.requires or ()
_session_install_for_python313(
session,
[
'--resolution',
'lowest-direct',
*install_args,
*(package_metadata.requires or ()),
],
)
else:
session.install(*install_requires)
_session_install_for_python313(session, install_args)

install_coverage_hook(session)
_install_coverage_hook(session)

session.run(
*'coverage run -m pytest -n auto'.split(),
Expand Down Expand Up @@ -117,7 +144,11 @@ def type_check(session: nox.Session):
wheel_metadata_json,
)['wheel-path']

session.install(f'instawow[gui, types] @ {package_path}')
_session_install_for_python313(
session,
[f'instawow[gui, types] @ {package_path}'],
)

session.run('npx', 'pyright', external=True)


Expand Down Expand Up @@ -165,7 +196,6 @@ def publish_dists(session: nox.Session):
def freeze_cli(session: nox.Session):
import argparse
import shutil
import tempfile

PYAPP_VERSION = 'v0.15.1'

Expand Down
23 changes: 7 additions & 16 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
{ pkgs ? import <nixpkgs> { } }:
let
python = pkgs.python312;
venvDir = toString ./venvs + ("/" + python.pythonVersion);
python = pkgs.python313.override { enableGIL = false; enableOptimizations = true; };
in
pkgs.mkShell {
buildInputs = [
pkgs.nixpkgs-fmt
pkgs.nodejs_20
pkgs.nil
pkgs.nixpkgs-fmt
pkgs.nodejs_21
pkgs.python312.pkgs.nox
pkgs.uv
python
python.pkgs.venvShellHook
];

SOURCE_DATE_EPOCH = "315532800"; # The year 1980
PYTHONBREAKPOINT = "IPython.terminal.debugger.set_trace";

shellHook = ''
if [ -d "${venvDir}" ]; then
echo "Skipping venv creation, '${venvDir}' already exists"
else
echo "Creating new venv environment in path: '${venvDir}'"
# Note that the module venv was only introduced in python 3, so for 2.7
# this needs to be replaced with a call to virtualenv
uv venv "${venvDir}"
fi
source "${venvDir}/bin/activate"
set -ex
AIOHTTP_NO_EXTENSIONS=1 MULTIDICT_NO_EXTENSIONS=1 CC=clang++ uv pip install nox -e ".[gui, test, types]"
VENV_BIN_DIR=$(nox -vv -s dev_env --force-python ${python.pythonVersion})
source "$VENV_BIN_DIR/activate"
'';
}

0 comments on commit 6eefa0a

Please sign in to comment.