diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index 908c1cbaf..000000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,21 +0,0 @@ -[bumpversion] -current_version = 3.0.2 -parse = (?P\d+)\.(?P\d+)(\.(?P\d+))? -serialize = - {major}.{minor}.{patch} - {major}.{minor} - -[bumpversion:file:src/hamster/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" - -[bumpversion:file:wscript] -search = VERSION = "{current_version}" -replace = VERSION = "{new_version}" - -[bumpversion:file:NEWS] -search = Changes since {current_version} -replace = Changes since {new_version} - - - Changes in {new_version} diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 434a9dc99..7eac188e6 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -82,6 +82,10 @@ jobs: steps: - name: Prepare repo uses: actions/checkout@v2 + # Fetch history, so we also fetch the previous tag for deriving + # the version number + with: + fetch-depth: 0 - name: Install system packages # It would be good to cache the GNOME Sdk, as it # is rather big to download each time. @@ -105,10 +109,14 @@ jobs: - name: Export bundle and try to install it run: | mkdir -p dist - flatpak build-bundle --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo build/flatpak/repo dist/Hamster.flatpak org.gnome.Hamster - flatpak --user -y install dist/Hamster.flatpak + # Note: For pull requests, this version includes the git hash + # of the autogenerated *merge* commit, not the original + # to-be-merged commit (because that's also what is tested). + VERSION=$(python src/hamster/version.py) + flatpak build-bundle --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo build/flatpak/repo "dist/Hamster-$VERSION.flatpak" org.gnome.Hamster + flatpak --user -y install "dist/Hamster-$VERSION.flatpak" - name: Upload built artifact uses: actions/upload-artifact@v2 with: name: Flatpak application - path: dist/Hamster.flatpak + path: dist/*.flatpak diff --git a/data/org.gnome.Hamster.GUI.metainfo.xml b/data/org.gnome.Hamster.metainfo.xml.in similarity index 90% rename from data/org.gnome.Hamster.GUI.metainfo.xml rename to data/org.gnome.Hamster.metainfo.xml.in index 9e19087b5..81e3000c9 100644 --- a/data/org.gnome.Hamster.GUI.metainfo.xml +++ b/data/org.gnome.Hamster.metainfo.xml.in @@ -1,6 +1,6 @@ - org.gnome.Hamster.GUI + org.gnome.Hamster CC0-1.0 GPL-3.0+ and CC-BY-SA-3.0 Hamster @@ -44,6 +44,10 @@ ​hamster https://github.com/projecthamster/hamster/wiki + + + + hamster diff --git a/data/wscript b/data/wscript index db9ac210a..e5a54fa5b 100644 --- a/data/wscript +++ b/data/wscript @@ -15,7 +15,13 @@ def build(ctx): ctx(features='glib2', settings_schema_files=['org.gnome.hamster.gschema.xml']) - ctx.install_files('${DATADIR}/metainfo', 'org.gnome.Hamster.GUI.metainfo.xml') + filename = "org.gnome.Hamster.metainfo.xml" + ctx(features = "subst", + source= "%s.in" % filename, + target= "%s" % filename, + dict = ctx.env, + install_path = "${DATADIR}/metainfo" + ) filename = "org.gnome.Hamster.GUI.desktop" ctx(features = "subst", diff --git a/setup.py b/setup.py deleted file mode 100644 index 589ed7178..000000000 --- a/setup.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python2 -import distutils -import os -from distutils.core import setup -from distutils import sysconfig - -data_dir = os.path.join(sysconfig.get_python_lib(), "hamster", "data") - -setup(name='hamster-sqlite', - version='0.3', - description='Minimal dependency nicely abstracted sqlite backend of hamster time tracker - lets you connect to your hamster db and do stuff in python', - author='Toms Baugis', - author_email='toms.baugis@gmail.com', - url='https://github.com/projecthamster/hamster', - package_dir = {'': 'src'}, - py_modules = ['hamster.storage', 'hamster.db', 'hamster.lib.__init__'], - data_files=[(data_dir, ['data/hamster.db'])], - ) diff --git a/src/hamster/VERSION b/src/hamster/VERSION new file mode 100644 index 000000000..54ae09e0c --- /dev/null +++ b/src/hamster/VERSION @@ -0,0 +1 @@ +unreleased diff --git a/src/hamster/__init__.py b/src/hamster/__init__.py index 533e1c2bb..4970a59f3 100644 --- a/src/hamster/__init__.py +++ b/src/hamster/__init__.py @@ -5,23 +5,14 @@ from gi.repository import Gtk as gtk from hamster.lib import default_logger +from hamster.version import get_version logger = default_logger(__name__) -try: - # defs.py is created by waf from defs.py.in - from hamster import defs - __version__ = defs.VERSION - installed = True -except ImportError: - # if defs is not there, we are running from sources - from subprocess import getstatusoutput - rc, output = getstatusoutput("git describe --tags --always --dirty=+") - __version__ = "3.0.2" if rc else "{} (uninstalled)".format(output) - installed = False - del getstatusoutput, rc, output +(__version__, installed) = get_version() # cleanup namespace +del get_version del default_logger del gtk # performance is retained diff --git a/src/hamster/version.py b/src/hamster/version.py new file mode 100644 index 000000000..1a3d8189b --- /dev/null +++ b/src/hamster/version.py @@ -0,0 +1,47 @@ +# Should not normally be used directly, use hamster.__version__ and +# hamster.installed instead + +def get_installed_version(): + try: + # defs.py is created by waf from defs.py.in + from hamster import defs + return defs.VERSION + except ImportError: + # if defs is not there, we are running from sources + return None + +def get_uninstalled_version(): + # If available, prefer the git version, otherwise fall back to + # the VERSION file (which is meaningful only in released + # versions) + from subprocess import getstatusoutput + rc, output = getstatusoutput("git describe --tags --always --dirty=+") + if rc == 0: + import re + # Strip "v" prefix that is used in git tags + return re.sub(r'^v', '', output) + else: + from pathlib import Path + with open(Path(__file__).parent / 'VERSION', 'r') as f: + return f.read() + +def get_version(): + """ + Figure out the hamster version. + + Returns a tuple with the version string and wether we are installed or not. + """ + + version = get_installed_version() + if version is not None: + return (version, True) + + version = get_uninstalled_version() + return ("{} (uninstalled)".format(version), False) + + +if __name__ == '__main__': + import sys + # Intended to be called by waf when installing, so only return + # uninstalled version + sys.stdout.write(get_uninstalled_version()) diff --git a/wscript b/wscript index 292408d72..cf89a7889 100644 --- a/wscript +++ b/wscript @@ -1,15 +1,13 @@ # -*- python -*- -from subprocess import getstatusoutput +import subprocess from waflib import Utils - -# slight code duplication with hamster/__init__.py, but this is finally cleaner. -rc, output = getstatusoutput("git describe --tags --always --dirty=+") -VERSION = "3.0.2" if rc else output - +# Reuse code from hamster to figure out the version number to use +process = subprocess.run(["python3", "src/hamster/version.py"], check=True, stdout=subprocess.PIPE, text=True) +VERSION = process.stdout APPNAME = 'hamster' top = '.'