From 2e3e38afcee227bd5dcc14a0110f01d4a5fe14a6 Mon Sep 17 00:00:00 2001 From: Zsolt Kovari Date: Wed, 23 Oct 2024 16:49:35 +0200 Subject: [PATCH] Store version in one place and generate timestamp dynamically --- .github/workflows/build-briefcase.yml | 2 +- pyproject.toml | 2 +- setup.py | 65 +++++++++++++++++++++++++++ src/build/settings/base.json | 6 --- src/main/python/plotlyst/__main__.py | 4 +- src/main/python/plotlyst/version.py | 1 + 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 setup.py delete mode 100644 src/build/settings/base.json create mode 100644 src/main/python/plotlyst/version.py diff --git a/.github/workflows/build-briefcase.yml b/.github/workflows/build-briefcase.yml index 068445151..66e50515c 100644 --- a/.github/workflows/build-briefcase.yml +++ b/.github/workflows/build-briefcase.yml @@ -33,6 +33,6 @@ jobs: - uses: actions/upload-artifact@v4 with: name: plotlyst-app - path: dist\Plotlyst-0.1.0.msi + path: dist\Plotlyst-*.msi diff --git a/pyproject.toml b/pyproject.toml index 25d10bb8a..f7822314d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plotlyst" -version = "0.1.0" +dynamic = ["version"] license = { text = "GNU General Public License v3 (GPLv3)" } authors = [ { name = "Zsolt Kovari" } diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..1860b7751 --- /dev/null +++ b/setup.py @@ -0,0 +1,65 @@ +import json +import os +import re +import time + +from setuptools import setup + + +def get_briefcase_version(): + with open("pyproject.toml") as f: + for line in f: + match = re.search(r'version\s*=\s*[\'"]([^\'"]+)[\'"]', line) + if match: + return match.group(1) + + raise RuntimeError("Unable to find version in pyproject.toml") + + +def get_base_version(): + with open("src/main/python/plotlyst/version.py") as f: + content = f.read() + match = re.search(r"plotlyst_version = ['\"]([^'\"]+)['\"]", content) + if match: + return match.group(1) + raise RuntimeError("Unable to find __version__ string in version.py") + + +def get_full_version(base_version): + timestamp = time.strftime("%Y%m%d.%H%M%S") + return f"{base_version}.{timestamp}" + + +def check_versions(base_version): + pyproject_version = get_briefcase_version() + if pyproject_version != base_version: + raise RuntimeError( + f"Version mismatch: [tool.briefcase] version is {pyproject_version}, but version.py has {base_version}") + + +def generate_json_file(version): + settings = { + "app_name": "Plotlyst", + "author": "Zsolt Kovari", + "main_module": "src/main/python/plotlyst/__main__.py", + "version": version, + } + + os.makedirs("src/build/settings", exist_ok=True) + + json_file_path = os.path.join("src", "build", "settings", "base.json") + with open(json_file_path, 'w') as json_file: + json.dump(settings, json_file, indent=4) + + +base_version = get_base_version() + +check_versions(base_version) + +version = get_full_version(base_version) + +generate_json_file(version) + +setup( + version=version, +) diff --git a/src/build/settings/base.json b/src/build/settings/base.json deleted file mode 100644 index 95a209bca..000000000 --- a/src/build/settings/base.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "app_name": "Plotlyst", - "author": "Zsolt Kovari", - "main_module": "src/main/python/plotlyst/__main__.py", - "version": "0.1.0" -} \ No newline at end of file diff --git a/src/main/python/plotlyst/__main__.py b/src/main/python/plotlyst/__main__.py index 39269b20c..60f379f2c 100644 --- a/src/main/python/plotlyst/__main__.py +++ b/src/main/python/plotlyst/__main__.py @@ -17,7 +17,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ - try: import logging import argparse @@ -30,6 +29,7 @@ from fbs_runtime.excepthook import enable_excepthook_for_threads from overrides import overrides + from plotlyst.version import plotlyst_version from plotlyst.env import AppMode, app_env from plotlyst.resources import resource_registry, resource_manager from plotlyst.settings import settings @@ -68,7 +68,7 @@ def run(self): appctxt = AppContext() app = appctxt.app app.setApplicationName('Plotlyst') - app.setApplicationVersion('0.1.0') + app.setApplicationVersion(plotlyst_version) sys.excepthook = handle_exception enable_excepthook_for_threads() diff --git a/src/main/python/plotlyst/version.py b/src/main/python/plotlyst/version.py new file mode 100644 index 000000000..e49b678d9 --- /dev/null +++ b/src/main/python/plotlyst/version.py @@ -0,0 +1 @@ +plotlyst_version = '0.1.0'