Skip to content

Commit e8be2ff

Browse files
authored
Merge pull request #7 from TaskBeacon/codex/standardize-version-management
Read version from pyproject
2 parents 3cff245 + a603a4e commit e8be2ff

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

docs/conf.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
project = 'psyflow'
1010
copyright = '2025, Zhipeng Cao'
1111
author = 'Zhipeng Cao'
12-
release = '0.1.0'
12+
import os
13+
import sys
14+
sys.path.insert(0, os.path.abspath("..")) # so Sphinx can find your package
15+
from psyflow._version import read_version
16+
release = read_version()
1317

1418
# -- General configuration ---------------------------------------------------
1519
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -27,11 +31,6 @@
2731
html_theme = 'alabaster'
2832
html_static_path = ['_static']
2933

30-
31-
import os
32-
import sys
33-
sys.path.insert(0, os.path.abspath("..")) # so Sphinx can find your package
34-
3534
# Enable extensions
3635
extensions = [
3736
"myst_parser", # Markdown support

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Start with one of the tutorials below or explore the API reference.
3535

3636
modules
3737

38+
.. toctree::
39+
:maxdepth: 1
40+
:caption: Development
41+
42+
release
43+
3844

3945
Indices and tables
4046
==================

docs/release.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release workflow
2+
3+
1. Update the version number in `pyproject.toml` under the `[project]` section.
4+
2. Commit the change with a message that includes `[publish]` to trigger the release pipeline.
5+
3. Build and upload the package as usual.

psyflow/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
"""
2-
psyflow: A utility package for modular PsychoPy experiment development
3-
"""
4-
__version__ = "0.1.0"
1+
"""psyflow: A utility package for modular PsychoPy experiment development."""
2+
3+
from ._version import __version__
54
from .BlockUnit import BlockUnit
65
from .StimBank import StimBank
76
from .SubInfo import SubInfo

psyflow/_version.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from __future__ import annotations
2+
from pathlib import Path
3+
import re
4+
5+
6+
def read_version() -> str:
7+
"""Return project version from pyproject.toml."""
8+
root = Path(__file__).resolve().parent.parent
9+
pyproject = root / "pyproject.toml"
10+
text = pyproject.read_text()
11+
match = re.search(r'^version\s*=\s*"([^"]+)"', text, re.MULTILINE)
12+
if not match:
13+
raise RuntimeError("Version not found in pyproject.toml")
14+
return match.group(1)
15+
16+
17+
__version__ = read_version()

setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
from pathlib import Path
2+
import re
13
from setuptools import setup, find_packages
24

5+
6+
def read_version() -> str:
7+
text = Path(__file__).with_name("pyproject.toml").read_text()
8+
match = re.search(r'^version\s*=\s*"([^"]+)"', text, re.MULTILINE)
9+
if not match:
10+
raise RuntimeError("Version not found in pyproject.toml")
11+
return match.group(1)
12+
313
setup(
414
name="psyflow",
5-
version="0.1.0",
15+
version=read_version(),
616
description="A utility package for building modular PsychoPy experiments.",
717
author="Zhipeng Cao",
818
author_email="[email protected]",

0 commit comments

Comments
 (0)