Skip to content

Commit e5b7986

Browse files
BLD: Update versioning approach
– Fix python development version and cicd version with .python-version – Move project version back to pyproject.toml. – Delete bash scripts in tool folder
1 parent 1a0fdd4 commit e5b7986

9 files changed

Lines changed: 110 additions & 125 deletions

File tree

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13.9

environment.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ dependencies:
4040
- pooch
4141
- scipy
4242

43+
# -------- Scripts --------
44+
- packaging
45+
4346
# -------- Publish --------
4447
- twine
4548

49+
# -------- Pip installs --------
4650
- pip
4751
- pip:
4852
- psi-io # Python runtime package

mapflpy/__init__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@
77
visualizing and analyzing the traced fieldlines.
88
"""
99

10+
1011
# mapflpy/__init__.py
1112
try:
1213
# If Meson generated this file:
1314
from ._version import __version__ # type: ignore[attr-defined]
14-
except Exception:
15+
except ModuleNotFoundError as e:
1516
try:
16-
# Fallback to installed metadata (wheel/sdist)
1717
from importlib.metadata import version as _pkg_version
18+
from importlib.metadata import PackageNotFoundError
19+
from pathlib import Path
20+
# Fallback to installed metadata (wheel/sdist)
1821
__version__ = _pkg_version("mapflpy") # type: ignore[assignment]
19-
except Exception: # dev/editable without metadata
20-
__version__ = "0+unknown" # type: ignore[assignment]
22+
except PackageNotFoundError as e: # dev/editable without metadata
23+
try:
24+
import tomllib # Python 3.11+
25+
except ModuleNotFoundError: # pragma: no cover
26+
import tomli as tomllib # pip install tomli
27+
28+
pyproject = Path(__file__).parents[1].resolve() / 'pyproject.toml'
29+
data = tomllib.loads(pyproject.read_text())
2130

31+
project_version = data.get("project", {}).get("version", "0+unknown")
32+
project_version = project_version.replace('"', '').replace("'", '')
33+
__version__ = project_version

meson.build

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ py.extension_module(
9595
install : true,
9696
)
9797

98-
# ---- Install the pure-Python package tree (future-proof)
99-
install_subdir('mapflpy', install_dir : py.get_install_dir())
100-
101-
# ---- Generate mapflpy/_version.py with Meson project version
98+
# ---- Generate mapflpy/_version.py
10299
conf = configuration_data()
103100
conf.set('VERSION', meson.project_version())
104101
configure_file(
@@ -108,3 +105,14 @@ configure_file(
108105
install : true,
109106
install_dir : py.get_install_dir() / 'mapflpy',
110107
)
108+
109+
# ---- Install the pure-Python package tree
110+
install_subdir(
111+
'mapflpy',
112+
install_dir : py.get_install_dir(),
113+
exclude_files: [
114+
'_version.py.in',
115+
'__pycache__',
116+
'*.pyc',
117+
]
118+
)

noxfile.py

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,40 @@
22
from __future__ import annotations
33

44
import os
5+
import re
56
import json
67
import platform
78
import subprocess
89
from pathlib import Path
910
import nox
1011

11-
# Speed up reruns; reuse envs when deps unchanged
12-
nox.options.reuse_existing_virtualenvs = False
12+
nox.options.reuse_existing_virtualenvs = True
13+
pyproject = nox.project.load_toml()
1314

15+
PY_VERSIONS = nox.project.python_versions(pyproject)
16+
try:
17+
txt = Path('.python-version').read_text(encoding="utf-8").strip().splitlines()[0]
18+
m = re.search(r"(\d+)\.(\d+)", txt) # grab major.minor; ignore patch/suffix
19+
SYS_PYTHON = f"{m.group(1)}.{m.group(2)}" if m else PY_VERSIONS[-1]
20+
except FileNotFoundError as e:
21+
SYS_PYTHON = PY_VERSIONS[-1]
1422

15-
PY_VERSIONS = [
16-
# "3.10",
17-
# "3.11",
18-
# "3.12",
19-
"3.13",
20-
]
21-
PY_TARGET = PY_VERSIONS[-1]
22-
23+
PROJECT_NAME = pyproject["project"]["name"]
2324
PROJECT_NAME_PATH = Path(__file__).parent.resolve()
24-
ARTIFACTS = PROJECT_NAME_PATH / ".nox" / "_artifacts"
25-
WHEEL_DIR = ARTIFACTS / "wheels"
26-
SDIST_DIR = ARTIFACTS / "sdist"
27-
WHEELHOUSE_DIR = ARTIFACTS / "wheelhouse"
28-
DOCDIST_DIR = ARTIFACTS / "docs"
25+
_ARTIFACTS = PROJECT_NAME_PATH / ".nox" / "_artifacts"
2926

30-
pyproject = nox.project.load_toml("pyproject.toml")
31-
PROJECT_NAME = pyproject["project"]["name"]
32-
CONDA_ENV_BUILD_COMPILERS = pyproject["tool"][PROJECT_NAME].get("conda", [])
27+
WHEEL_DIR = _ARTIFACTS / "wheels"
28+
SDIST_DIR = _ARTIFACTS / "sdist"
29+
WHEELHOUSE_DIR = _ARTIFACTS / "wheelhouse"
30+
DOCDIST_DIR = _ARTIFACTS / "docs"
3331

3432
REPAIR_TOOLS: dict[str, list[str]] = {
3533
"linux": ["auditwheel"],
3634
"darwin": ["delocate"],
3735
"windows": ["delvewheel"],
3836
}
3937

38+
SDIST_DIR.mkdir(parents=True, exist_ok=True)
4039
WHEEL_DIR.mkdir(parents=True, exist_ok=True)
4140
WHEELHOUSE_DIR.mkdir(parents=True, exist_ok=True)
4241
DOCDIST_DIR.mkdir(parents=True, exist_ok=True)
@@ -49,15 +48,6 @@ def _darwin_sdk_env() -> dict[str, str]:
4948
# Prefer already-set values; otherwise best-effort defaults
5049
env = {}
5150
env.setdefault("MACOSX_DEPLOYMENT_TARGET", os.environ.get("MACOSX_DEPLOYMENT_TARGET", "11.0"))
52-
# SDKPROJECT_NAME_PATH may be needed for clang/gfortran during Meson sanity checks
53-
# if "SDKPROJECT_NAME_PATH" not in os.environ:
54-
# try:
55-
# import subprocess
56-
# sdk = subprocess.check_output(["xcrun", "--show-sdk-path"], text=True).strip()
57-
# env["SDKPROJECT_NAME_PATH"] = sdk
58-
# except Exception:
59-
# pass
60-
# return env
6151
try:
6252
sdk = subprocess.check_output(
6353
["xcrun", "--sdk", "macosx", "--show-sdk-path"],
@@ -77,7 +67,7 @@ def _darwin_sdk_env() -> dict[str, str]:
7767
def _build_env(session: nox.Session) -> Path:
7868
"""Build a wheel into ./dist and return its path."""
7969
session.conda_install(
80-
*CONDA_ENV_BUILD_COMPILERS,
70+
*pyproject["tool"][PROJECT_NAME].get("conda", []),
8171
channel="conda-forge"
8272
)
8373
session.env.update(_darwin_sdk_env())
@@ -112,7 +102,8 @@ def build(session: nox.Session) -> None:
112102
external=False
113103
)
114104

115-
@nox.session(python=PY_TARGET)
105+
106+
@nox.session(python=SYS_PYTHON)
116107
def repair(session: nox.Session) -> None:
117108
"""Repair wheels in dist/ into wheelhouse/ using the OS-specific tool."""
118109
platform_id = platform.system().lower()
@@ -141,8 +132,6 @@ def test(session: nox.Session) -> None:
141132
"""Build the wheel (with compilers), install it, then run pytest from a temp dir."""
142133
# Build wheel
143134
_dist_env(session)
144-
145-
# Runtime/test deps
146135
session.install(*pyproject["project"].get("optional-dependencies", {}).get("test", []))
147136

148137
tmp = session.create_tmp()
@@ -151,7 +140,8 @@ def test(session: nox.Session) -> None:
151140
# Pytest
152141
session.run("pytest", PROJECT_NAME_PATH.as_posix())
153142

154-
@nox.session(venv_backend='conda|mamba|micromamba', python=PY_TARGET)
143+
144+
@nox.session(venv_backend='conda|mamba|micromamba', python=SYS_PYTHON)
155145
def sdist(session: nox.Session) -> None:
156146
"""Build the package wheel (with compilers)."""
157147
_build_env(session)
@@ -166,22 +156,25 @@ def sdist(session: nox.Session) -> None:
166156
external=False
167157
)
168158

169-
@nox.session(python=PY_TARGET)
159+
160+
@nox.session(python=SYS_PYTHON)
170161
def types(session: nox.Session) -> None:
171162
"""Mypy type checking (analyzes source tree)."""
172163
session.install(*pyproject["project"].get("optional-dependencies", {}).get("types", []))
173164

174165
session.run("mypy")
175166

176-
@nox.session(python=PY_TARGET)
167+
168+
@nox.session(python=SYS_PYTHON)
177169
def lint(session: nox.Session) -> None:
178170
"""Ruff lint + format check."""
179171
session.install(*pyproject["project"].get("optional-dependencies", {}).get("lint", []))
180172

181173
session.run("ruff", "check", PROJECT_NAME)
182174
session.run("ruff", "format", "--check", PROJECT_NAME)
183175

184-
@nox.session(python=PY_TARGET)
176+
177+
@nox.session(python=SYS_PYTHON)
185178
def docs(session: nox.Session) -> None:
186179
"""Build Sphinx docs against the installed wheel."""
187180
_dist_env(session)
@@ -207,3 +200,40 @@ def docs(session: nox.Session) -> None:
207200
out_dir = DOCDIST_DIR / f"html-{tag.get('tags', ['none'])[0]}"
208201
src_dir = PROJECT_NAME_PATH / "docs" / "source"
209202
session.run("sphinx-build", src_dir.as_posix(), out_dir.as_posix(), *args)
203+
204+
205+
@nox.session(python=SYS_PYTHON)
206+
def build_matrix(session: nox.Session) -> None:
207+
"""Build, repair, and test in order (single entrypoint)."""
208+
session.notify("sdist")
209+
session.notify("build")
210+
session.notify("repair")
211+
session.notify("test")
212+
213+
214+
@nox.session(python=SYS_PYTHON)
215+
def build_target(session: nox.Session) -> None:
216+
"""Build, repair, and test in order (single entrypoint)."""
217+
session.notify("sdist")
218+
session.notify(f"build-{session.python}")
219+
session.notify("repair")
220+
session.notify(f"test-{session.python}")
221+
222+
223+
@nox.session(python=SYS_PYTHON)
224+
def build_docs(session: nox.Session) -> None:
225+
"""Build, repair, and test in order (single entrypoint)."""
226+
session.notify("build_target")
227+
session.notify("docs")
228+
229+
230+
@nox.session(python=SYS_PYTHON)
231+
def build_qa(session: nox.Session) -> None:
232+
"""Build, repair, and test in order (single entrypoint)."""
233+
session.notify("build_target")
234+
session.notify(f"types")
235+
session.notify(f"lint")
236+
237+
238+
if __name__ == "__main__":
239+
nox.main()

pyproject.toml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ keywords = [
3434
classifiers = [
3535
"Development Status :: 4 - Beta",
3636
"Intended Audience :: Science/Research",
37-
"Operating System :: Unix",
38-
"Operating System :: POSIX :: Linux",
39-
"Operating System :: MacOS :: MacOS X",
4037
"Natural Language :: English",
38+
"Programming Language :: Fortran",
4139
"Programming Language :: Python",
4240
"Programming Language :: Python :: 3",
4341
"Programming Language :: Python :: 3.10",
4442
"Programming Language :: Python :: 3.11",
4543
"Programming Language :: Python :: 3.12",
4644
"Programming Language :: Python :: 3.13",
47-
"Programming Language :: Fortran",
45+
"Programming Language :: Python :: 3 :: Only",
46+
"Operating System :: Unix",
47+
"Operating System :: POSIX :: Linux",
48+
"Operating System :: MacOS :: MacOS X",
49+
"Typing :: Typed",
4850
"Topic :: Scientific/Engineering :: Astronomy",
4951
"Topic :: Scientific/Engineering :: Physics",
5052
]
@@ -73,7 +75,8 @@ data = [
7375
"scipy"
7476
]
7577
build = [
76-
"python-build"
78+
"python-build",
79+
"packaging"
7780
]
7881
test = [
7982
"pytest>=8.4.0",
@@ -95,8 +98,11 @@ docs = [
9598
"scipy",
9699
"pthree==1.0.1"
97100
]
101+
dev = [
102+
"nox>=2025.11.12",
103+
]
98104
all = [
99-
"mapflpy[hdf4,data,build,test,types,lint,docs]",
105+
"mapflpy[hdf4,data,build,test,types,lint,docs,dev]",
100106
]
101107

102108
# Tools & Extensions

tools/fetch.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

tools/makedist.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

tools/makedocs.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)