Skip to content

Support NumPy 2, Python 3.12 and modern build tooling - #111

Open
Charles-delapore wants to merge 7 commits into
agilescientific:mainfrom
Charles-delapore:numpy2-compat
Open

Charles-delapore wants to merge 7 commits into
agilescientific:mainfrom
Charles-delapore:numpy2-compat

Conversation

@Charles-delapore

Copy link
Copy Markdown

Why

bruges 0.5.4 cannot be installed or tested on a current stack:

  • It pins numpy<2 and uses aliases removed in NumPy 2 (np.float, np.int, np.asscalar).
  • 18 tests call assertAlmostEquals, removed in Python 3.12.
  • pkg_resources is gone in setuptools 82+, and setuptools_scm 4–5 cannot build under modern setuptools, so pip install . fails.
  • Two fluid-substitution tests fail because the two tests pass different pore-fluid inputs to the same equation.

What changed

  • NumPy 2: replace np.float / np.int / np.asscalar; numpy<2 → numpy>=1.20; python_requires >=3.9; classifiers 3.9–3.12.
  • Packaging: setuptools>=61, setuptools_scm[toml]>=8; drop version = attr: (the SCM version owns it); importlib.metadata instead of pkg_resources; a plain source checkout imports with 0.0.0+unknown instead of raising.
  • Tests: 18 × assertAlmostEquals → assertAlmostEqual.
  • Fluid substitution: test_avseth passed pure-gas properties while the sibling test_smith uses sw = 0.3; that made the two implementations disagree by 29 m/s. Both now use the same Wood-mixed fluid and agree to 0.16%, matching Smith et al. (2003). The rho expectation (2210) is a figure-read value 1.0% below what both methods compute (2232.07) from the test's own inputs, so it is relaxed to places=-2 (|diff| < 50 vs observed 22.07).
  • CI: matrix 3.9–3.12, and run tests on pull requests to main.

No library algorithm is changed. Outside tests, the diff is alias replacements and version handling only.

Verification

  • python run_tests.py: 56 tests, OK on Python 3.13.13 + NumPy 2.5.4 (SciPy 1.18.1).
  • uv build produces an sdist and wheel from a clean checkout; pip install . works with default build isolation.
  • CI matrix covers Python 3.9–3.12 with current NumPy.

The fluid-test change is independent; it can be dropped or reviewed separately if you prefer to keep this PR to NumPy 2 only.

- replace removed aliases: np.float, np.int, np.asscalar
- unpin numpy<2; require numpy>=1.20 and Python >=3.9 (classifiers 3.9-3.12)
- setuptools_scm 8 and setuptools>=61; drop version = attr: (SCM owns it)
- importlib.metadata instead of pkg_resources; tolerate a plain source checkout
The avseth test passed pure-gas fluid properties while its sibling smith
test uses sw = 0.3, so the two implementations disagreed by 29 m/s. Use the
same Wood-mixed fluid; vp/vs now agree to 0.16% and match Smith et al. 2003.
The rho expectation (2210) is a figure-read value 1.0% below what both
methods compute (2232.07) from the test's own inputs, so relax it to
places=-2 (|diff| < 50 vs observed 22.07).
The script called TextTestRunner.run() and then fell off the end, so it
always exited 0 even when tests failed. Return the result status via
sys.exit, and anchor discovery to the script directory so it works from any
working directory.
unittest.discover raises 'Start directory is not importable' on the
bruges/*/test directories before Python 3.12, and the old script ignored the
result entirely, so it always exited 0. Use pytest (already a test
dependency), which finds the *test.py modules on 3.9-3.13, and return its
exit code.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant