Merge branch 'issue-1883' into 'master'

Fix build part of version number

Closes #1883

See merge request openlp/openlp!745
This commit is contained in:
Raoul Snyman 2024-04-20 22:13:26 +00:00
commit 32d132c2f0
2 changed files with 32 additions and 10 deletions

View File

@ -162,11 +162,23 @@ def get_version():
except OSError: except OSError:
log.exception('Error in version file.') log.exception('Error in version file.')
full_version = '0.0.0' full_version = '0.0.0'
bits = full_version.split('.dev')
if '.dev' in full_version:
# Old way of doing build numbers, but also how hatch does them
version_number, build_number = full_version.split('.dev', 1)
build_number = build_number.split('+', 1)[1]
elif '+' in full_version:
# Current way of doing build numbers, may be replaced by hatch later
version_number, build_number = full_version.split('+', 1)
else:
# If this is a release, there is no build number
version_number = full_version
build_number = None
APPLICATION_VERSION = { APPLICATION_VERSION = {
'full': full_version, 'full': full_version,
'version': bits[0], 'version': version_number,
'build': full_version.split('+')[1] if '+' in full_version else None 'build': build_number
} }
if APPLICATION_VERSION['build']: if APPLICATION_VERSION['build']:
log.info('OpenLP version {version} build {build}'.format(version=APPLICATION_VERSION['version'], log.info('OpenLP version {version} build {build}'.format(version=APPLICATION_VERSION['version'],

View File

@ -21,10 +21,10 @@
""" """
Package to test the openlp.core.version package. Package to test the openlp.core.version package.
""" """
import sys
from datetime import date from datetime import date
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError
from openlp.core.version import VersionWorker, check_for_update, get_version, update_check_date from openlp.core.version import VersionWorker, check_for_update, get_version, update_check_date
@ -251,15 +251,25 @@ def test_check_for_update_skipped(mocked_run_thread, mock_settings):
assert mocked_run_thread.call_count == 0 assert mocked_run_thread.call_count == 0
def test_get_version_dev_version(): @pytest.mark.parametrize('in_version, out_version', [
('3.1.1', {'full': '3.1.1', 'version': '3.1.1', 'build': None}),
('3.0.2+git.cb1db9f43', {'full': '3.0.2+git.cb1db9f43', 'version': '3.0.2', 'build': 'git.cb1db9f43'}),
('3.1.2.dev15+gff6b05ed3', {'full': '3.1.2.dev15+gff6b05ed3', 'version': '3.1.2', 'build': 'gff6b05ed3'})
])
@patch('openlp.core.version.AppLocation.get_directory')
def test_get_version(mocked_get_directory: MagicMock, in_version: str, out_version: dict):
""" """
Test the get_version() function Test the get_version() function
""" """
# GIVEN: We're in dev mode # GIVEN: Some mocks and predefined versions
with patch.object(sys, 'argv', ['--dev-version']), \ mocked_path = MagicMock()
patch('openlp.core.version.APPLICATION_VERSION', None): mocked_path.__truediv__.return_value = mocked_path
# WHEN: get_version() is run mocked_path.read_text.return_value = in_version
mocked_get_directory.return_value = mocked_path
# WHEN: get_version() is run
with patch('openlp.core.version.APPLICATION_VERSION', None):
version = get_version() version = get_version()
# THEN: version is something # THEN: version is something
assert version assert version == out_version