From 504279b86d9f19fc0488e6835a80ba7966d11668 Mon Sep 17 00:00:00 2001 From: Sean Law Date: Thu, 30 Jul 2026 15:09:27 -0400 Subject: [PATCH 1/2] Initial commit --- conftest.py | 72 +++++++++++++++++++++++++++++++++++++++++---------- stumpy/rng.py | 20 -------------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/conftest.py b/conftest.py index 7078739dc..72bf87f59 100644 --- a/conftest.py +++ b/conftest.py @@ -5,32 +5,76 @@ # running tests from inside VS code. # See https://stackoverflow.com/a/34520971 -import json +import os +from importlib.metadata import PackageNotFoundError, version import pytest from stumpy import rng +def get_specs(): + """ + Find and return all package versions + """ + pkgs = [ + # Alphabetical Order + "black", + "coverage", + "dask", + "distributed", + "flake8", + "isort", + "numba", + "numpy", + "pandas", + "polars", + "pytest", + "python", + "ray", + "scipy", + ] + + specs = [] + for pkg in pkgs: + try: # pragma: no cover + pkg_version = version(pkg) + specs.append(f"--spec {pkg}={pkg_version}") + except PackageNotFoundError: + pass + + return " ".join(specs) + + +def get_env_vars(): + """ + Find and return all environment variables + """ + keys = [ + "NUMBA_DISABLE_JIT", + "NUMBA_ENABLE_CUDASIM", + ] + + env_vars = [] + for key in keys: + value = os.getenv(key) + if value is not None: + env_vars.append(f"{key}={value}") + + return " ".join(env_vars) + + def pytest_configure(config): """ Called after command line options have been parsed and all plugins and initial conftest files been loaded. """ - state = rng.STATE - state_str = json.dumps( - ( - state[0], - state[1].tolist(), - state[2], - state[3], - state[4], - ) - ) - - # Store details of starting random state in case of failure + # Store details of starting random seed in case of failure + env_vars = get_env_vars() + specs = get_specs() pytest.STUMPY_MSG = ( - f"\n\nSTUMPY_STATE='{state_str}' pixi run tests custom {config.args[0]}" + f"\n\nSTUMPY_SEED={rng.SEED} {env_vars} " + f"pixi exec {specs} ./test.sh custom 1 {config.args[0]}" ) diff --git a/stumpy/rng.py b/stumpy/rng.py index 3225d904b..d83235a60 100644 --- a/stumpy/rng.py +++ b/stumpy/rng.py @@ -1,6 +1,4 @@ -import json import os -import warnings from contextlib import contextmanager import numpy as np @@ -13,24 +11,6 @@ SEED = np.random.randint(1, 4_294_967_296, dtype=np.uint32) RNG = np.random.RandomState(seed=SEED) -if os.getenv("STUMPY_STATE") is not None: # pragma: no cover - if os.getenv("STUMPY_SEED") is not None: # pragma: no cover - warnings.warn("STUMPY_SEED was ignored in lieu of STUMPY_STATE") - state_str = os.getenv("STUMPY_STATE") - state = json.loads(state_str) - STATE = ( - state[0], - np.array(state[1], dtype=np.uint32), - state[2], - state[3], - state[4], - ) - RNG.set_state(STATE) -else: - STATE = RNG.get_state() - -# seed = RNG.get_state()[1][0] - @contextmanager def fix_seed(seed): From 7c63a8e0c8c7245eb18cd1aeb0d94516db79951d Mon Sep 17 00:00:00 2001 From: Sean Law Date: Fri, 31 Jul 2026 08:00:17 -0400 Subject: [PATCH 2/2] Addressed comments --- conftest.py | 6 ++---- stumpy/rng.py | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/conftest.py b/conftest.py index 72bf87f59..b2b357672 100644 --- a/conftest.py +++ b/conftest.py @@ -72,10 +72,8 @@ def pytest_configure(config): # Store details of starting random seed in case of failure env_vars = get_env_vars() specs = get_specs() - pytest.STUMPY_MSG = ( - f"\n\nSTUMPY_SEED={rng.SEED} {env_vars} " - f"pixi exec {specs} ./test.sh custom 1 {config.args[0]}" - ) + pytest.STUMPY_MSG = f"\n\nSTUMPY_SEED={rng.SEED} {env_vars} " + pytest.STUMPY_MSG += f"pixi exec {specs} ./test.sh custom 1 {config.args[0]}" def pytest_sessionfinish(session, exitstatus): diff --git a/stumpy/rng.py b/stumpy/rng.py index d83235a60..5e0bfb2bb 100644 --- a/stumpy/rng.py +++ b/stumpy/rng.py @@ -7,6 +7,8 @@ # in order to account for unit testing if os.getenv("STUMPY_SEED") is not None: # pragma: no cover SEED = int(os.getenv("STUMPY_SEED")) + if SEED == 0: + raise ValueError("STUMPY_SEED must be greater than zero!") else: SEED = np.random.randint(1, 4_294_967_296, dtype=np.uint32) RNG = np.random.RandomState(seed=SEED)