Skip to content

Commit

Permalink
Store version in one place and generate timestamp dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Oct 23, 2024
1 parent 6e06595 commit 2e3e38a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-briefcase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
65 changes: 65 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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,
)
6 changes: 0 additions & 6 deletions src/build/settings/base.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/python/plotlyst/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

try:
import logging
import argparse
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/main/python/plotlyst/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plotlyst_version = '0.1.0'

0 comments on commit 2e3e38a

Please sign in to comment.