Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@

# -- Project information -----------------------------------------------------

# Import the version string
from simopt import __version__ # noqa: E402

project = "SimOpt"
copyright = "2025, simopt-admin" # noqa: A001
project_copyright = "%Y, simopt-admin"
author = "simopt-admin"
release = "1.2.1"
release = __version__
version: str = ".".join(release.split(".")[:2])

# -- General configuration ---------------------------------------------------

Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = ["build*"]

[project]
name = "simoptlib"
version = "1.2.2.dev0"
dynamic = ["version"]
authors = [
{ name = "David Eckman", email = "eckman@tamu.edu" },
{ name = "Shane Henderson", email = "sgh9@cornell.edu" },
Expand Down Expand Up @@ -54,6 +54,9 @@ dev = [
docs = ["sphinx>=8.2.3", "sphinx-autoapi>=3.6.1", "sphinx-rtd-theme>=3.0.2"]
notebooks = ["ipykernel>=7.1.0"]

[tool.setuptools.dynamic]
version = { attr = "simopt.__version__" }

[project.urls]
"Homepage" = "https://github.com/simopt-admin/simopt"
"Documentation" = "https://simopt.readthedocs.io/en/latest/"
73 changes: 73 additions & 0 deletions scripts/sync_citation_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python

"""A script to synchronize the version from _version.py to CITATION.cff."""

import re
import sys
from pathlib import Path

# --- Configuration ---------------------------------------------------

# Append the parent directory (simopt package) to the system path
SIMOPT_PACKAGE_DIR = Path(__file__).resolve().parent.parent
sys.path.append(str(SIMOPT_PACKAGE_DIR))

# Source directory containing the _version.py file
SIMOPT_DIR = SIMOPT_PACKAGE_DIR / "simopt"

# Source of the citation file
CITATION_FILENAME = "CITATION.cff"
CITATION_FILE: Path = SIMOPT_PACKAGE_DIR / CITATION_FILENAME

# Regex pattern to identify the version line in CITATION.cff

VERSION_PATTERN = re.compile(r"^(version:\s*).+$")

# ---------------------------------------------------------------------


def main() -> None:
"""Reads the version and updates the CITATION.cff file."""
# --- Get the source version ---
from simopt._version import __version__

# --- Read and update the CITATION.cff file ---
if not CITATION_FILE.exists():
print(f"Error: File not found at {CITATION_FILE}")
sys.exit(1)

# We use 'str(__version__)' to handle non-string version types
# and add quotes to be safe YAML, especially for pre-release tags.
replacement_line = f'version: "{__version__!s}"'

print(f"Updating {CITATION_FILE}...")

new_lines = []
found = False

with CITATION_FILE.open("r") as f:
for line in f:
# Check if the line matches our version pattern
if not found and VERSION_PATTERN.match(line):
# If it matches, replace it with our new line
new_lines.append(replacement_line + "\n")
found = True
print(f" - Replaced: {line.strip()}")
print(f" + With: {replacement_line}")
else:
# Otherwise, keep the line as-is
new_lines.append(line)

if not found:
print("Error: A 'version:' line was not found in the file.")
sys.exit(1)

# Write the modified content back to the file
with CITATION_FILE.open("w") as f:
f.writelines(new_lines)

print("Update complete.")


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions simopt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
"""Init file for the simopt package."""

# Make the version easily accessible to users
from simopt._version import __version__ # noqa: F401
1 change: 1 addition & 0 deletions simopt/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.2.2.dev0"