Commit efd9b8b0 authored by Gaetano Scandariato's avatar Gaetano Scandariato
Browse files

feat: Add version management

parent 3f661c24
Loading
Loading
Loading
Loading
Loading
+1 −0
Changes for PyAETNA/__init__.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ if os.path.isdir(_inner_path) and _inner_path not in sys.path:
    sys.path.insert(0, _inner_path)
# After adjusting ``sys.path`` we import everything from the inner package so
# that attributes are available directly under the top‑level ``PyAETNA`` name.
from .version import __version__
_spec = importlib.util.find_spec("PyAETNA")
if _spec is not None and _spec.origin != __file__:
    _module = importlib.import_module("PyAETNA")

PyAETNA/version.py

0 → 100644
+22 −0
Changes for PyAETNA/version.py: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
"""
Version management for PyAETNA.
"""
import os

def get_version():
    """
    Read the version string from the VERSION file in the package root.
    """
    # The VERSION file is located in the root of the PyAETNA repository/package
    # We look for it relative to this file's location.
    # This file is in PyAETNA/PyAETNA/version.py, VERSION is in PyAETNA/VERSION
    base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
    version_file = os.path.join(base_dir, "VERSION")
    try:
        with open(version_file, "r") as f:
            return f.read().strip()
    except FileNotFoundError:
        return "unknown"

__version__ = get_version()

VERSION

0 → 100644
+1 −0
Changes for VERSION: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
3.7.0
+3 −3
Changes for public/config-generator.html: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PyAETNA v3.6 — Configuration Wizard</title>
<title>PyAETNA v3.7 — Configuration Wizard</title>
<style>
/* ─── Design tokens ─── */
:root {
@@ -251,7 +251,7 @@ input:focus, select:focus, textarea:focus { outline: none; border-color: var(--c
<body>

<header>
  <h1>PyAETNA v3.6 &mdash; Configuration Wizard</h1>
  <h1>PyAETNA v3.7 &mdash; Configuration Wizard</h1>
  <div class="links">
    <a href="https://github.com/gaetanoscandariato/PyAETNA" target="_blank" rel="noopener">GitHub</a>
    <a href="https://github.com/gaetanoscandariato/PyAETNA/blob/main/docs/configuration_keys.md" target="_blank" rel="noopener">Docs</a>
@@ -1540,7 +1540,7 @@ function rmDyn(id) {
/* ────────────── YAML Generator ────────────── */
function gen() {
  try {
    var y = '# PyAETNA v3.6 \u2014 Generated Configuration\n';
    var y = '# PyAETNA v3.7 \u2014 Generated Configuration\n';
    y += '# Created by the PyAETNA Configuration Wizard\n\n';

    /* 0. Global Priors */

update_version.py

0 → 100644
+58 −0
Changes for update_version.py: 58 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env python3
import os
import sys
import re

def update_version_in_files():
    # Path to the VERSION file
    version_file_path = os.path.join(os.path.dirname(__file__), "VERSION")
    try:
        with open(version_file_path, "r") as f:
            new_version = f.read().strip()
    except FileNotFoundError:
        print("Error: VERSION file not found.")
        sys.exit(1)

    if not new_version:
        print("Error: VERSION file is empty.")
        sys.exit(1)

    # Set the version currently present in the files that needs to be replaced
    old_version = "3.7"

    # Files to update and the regex patterns to search for
    # Format: (file_path, pattern, replacement)
    # We use the old_version variable to build the regex.
    
    # Escape old_version for use in regex
    ov_esc = re.escape(old_version)
    
    files_to_update = [
        ("README.md", rf"v{ov_esc}(\.0)?", f"v{new_version}"),
        ("CHANGELOG.md", rf"Version {ov_esc}(\.0)?", f"Version {new_version}"),
        ("docs/configuration.md", rf"v{ov_esc}(\.0)?", f"v{new_version}"),
        ("docs/configuration_keys.md", rf"v{ov_esc}(\.0)?", f"v{new_version}"),
        ("docs/config-generator.html", rf"v{ov_esc}(\.0)?", f"v{new_version}"),
        ("public/config-generator.html", rf"v{ov_esc}(\.0)?", f"v{new_version}"),
    ]
    
    # Also handle the JS part in config-generator.html
    # var y = '# PyAETNA v3.7 \u2014 Generated Configuration\n';
    
    for rel_path, pattern, replacement in files_to_update:
        full_path = os.path.join(os.path.dirname(__file__), rel_path)
        if not os.path.exists(full_path):
            continue
            
        with open(full_path, "r", encoding="utf-8") as f:
            content = f.read()
            
        new_content = re.sub(pattern, replacement, content)
        
        if new_content != content:
            with open(full_path, "w", encoding="utf-8") as f:
                f.write(new_content)
            print(f"Updated {rel_path}")

if __name__ == "__main__":
    update_version_in_files()