Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
- "3.13"

runs-on: ${{ matrix.os }}
env:
PYTHONIOENCODING: utf-8
steps:
- name: Get source code
uses: actions/checkout@v4
Expand Down Expand Up @@ -94,6 +96,8 @@ jobs:
- "3.13"

runs-on: ${{ matrix.os }}
env:
PYTHONIOENCODING: utf-8
steps:
- name: Get source code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ bandit_report.csv
tests/fixtures/http-test-local/qdt-files.json
docs/reference/rules_context.json
safety_report.html
qgis_deployment_toolbelt/_version.py
32 changes: 28 additions & 4 deletions builder/version_info_templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

# Standard library
import argparse
import re
import sys
from os import W_OK, access, path
from pathlib import Path

# 3rd party
from packaging.version import parse as parse_version

sys.path.insert(0, path.abspath(r"."))

# module
Expand All @@ -29,9 +31,31 @@
# ########### MAIN #################
# ##################################

# Define a regular expression pattern to match the version string
pattern = re.compile(r"(\d+)\.(\d+)\.(\d+)")
semver = pattern.match(__about__.__version__).groups()
# Parse the version using packaging.version which handles setuptools_scm formats
# This supports formats like:
# - Standard releases: "1.2.3"
# - Development versions: "1.2.3.dev4+g1234567"
# - Pre-releases: "1.2.3a1", "1.2.3b2", "1.2.3rc1"
try:
parsed_version = parse_version(__about__.__version__)
# Extract major, minor, patch from the parsed version
# For development versions like "0.1.dev1+ge6f014e", this will give us (0, 1, 0)
if hasattr(parsed_version, "release") and len(parsed_version.release) >= 3:
semver = parsed_version.release[:3] # (major, minor, patch)
elif hasattr(parsed_version, "release") and len(parsed_version.release) == 2:
# Handle case where only major.minor is provided
semver = (*parsed_version.release, 0) # (major, minor, 0)
elif hasattr(parsed_version, "release") and len(parsed_version.release) == 1:
# Handle case where only major is provided
semver = (parsed_version.release[0], 0, 0) # (major, 0, 0)
else:
# Fallback for unexpected formats
semver = (0, 1, 0)
except Exception as e:
raise ValueError(
f"Invalid version format: {__about__.__version__}. "
f"Error parsing version: {e}"
)


REPLACEMENT_VALUES = {
Expand Down
1 change: 0 additions & 1 deletion docs/development/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
1. In `Choose a tag`, enter the new tag (obviously complying with [SemVer](https://semver.org/))
1. Click on `Generate release notes`
1. Copy/paste the generated text from `## What's changed` until the line before `**Full changelog**:...` in the CHANGELOG.md replacing `What's changed` with the tag and the publication date
1. Change the version number in `__about__.py`
1. Commit changes with a message like `release: bump version to X.x.x` to the main branch
1. Apply a git tag with the relevant version: `git tag -a 0.3.0 {git commit hash} -m "New awesome feature"`
1. Push commit and tag to main branch: `git push --tags`
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ norecursedirs = ".* build dev development dist docs CVS fixtures _darcs {arch} *
python_files = "test_*.py"
testpaths = ["tests"]

[tool.setuptools_scm]
write_to = "qgis_deployment_toolbelt/_version.py"

[tool.setuptools.dynamic]
version = { attr = "qgis_deployment_toolbelt.__about__.__version__" }
version = { attr = "qgis_deployment_toolbelt._version.version" }

[tool.setuptools.package-data]
qgis_deployment_toolbelt = ["shortcuts/*.template"]
Expand Down
18 changes: 11 additions & 7 deletions qgis_deployment_toolbelt/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@
__uri_tracker__ = f"{__uri_repository__}issues/"
__uri__ = __uri_repository__

__version__ = "0.38.0"
__version_info__ = tuple(
[
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
]
)
try:
from ._version import version as __version__
except ImportError:
try:
# Fallback for development versions or when package is not installed
from importlib.metadata import version

__version__ = version("qgis-deployment-toolbelt")
except ImportError:
# Final fallback
__version__ = "0.0.0+unknown"
5 changes: 4 additions & 1 deletion qgis_deployment_toolbelt/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import logging
import sys
from collections.abc import Iterable
from os import getenv
from os import environ, getenv
from pathlib import Path
from sys import platform as opersys
from urllib.parse import urlsplit, urlunsplit
Expand Down Expand Up @@ -47,6 +47,9 @@

logger = logging.getLogger(__name__)

if sys.platform == "win32":
environ["PYTHONIOENCODING"] = "utf-8"

# #############################################################################
# ####### Functions ###############
# #################################
Expand Down
1 change: 0 additions & 1 deletion tests/test_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_metadata_types(self):
self.assertIsInstance(__about__.__uri_tracker__, str)
self.assertIsInstance(__about__.__uri__, str)
self.assertIsInstance(__about__.__version__, str)
self.assertIsInstance(__about__.__version_info__, tuple)

# misc
self.assertLessEqual(len(__about__.__title_clean__), len(__about__.__title__))
Expand Down