launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27752
[Merge] ~jugmac00/lpcraft:retrieve-version-info-directly-from-setup-cfg into lpcraft:main
Jürgen Gmach has proposed merging ~jugmac00/lpcraft:retrieve-version-info-directly-from-setup-cfg into lpcraft:main.
Commit message:
Retrieve version info directly from setup.cfg for building snaps
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jugmac00/lpcraft/+git/lpcraft/+merge/412148
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/lpcraft:retrieve-version-info-directly-from-setup-cfg into lpcraft:main.
diff --git a/lpcraft/_version.py b/lpcraft/_version.py
index 2d1f181..1271ff2 100644
--- a/lpcraft/_version.py
+++ b/lpcraft/_version.py
@@ -7,22 +7,6 @@ __all__ = [
]
import importlib.metadata
-from configparser import ConfigParser
-from pathlib import Path
-
-def _get_version() -> str:
- try:
- return importlib.metadata.version("lpcraft")
- except importlib.metadata.PackageNotFoundError:
- setup_cfg_path = Path(__file__).parent.parent / "setup.cfg"
- if setup_cfg_path.exists():
- parser = ConfigParser()
- parser.read(setup_cfg_path)
- return parser.get("metadata", "version")
- else:
- raise RuntimeError("Cannot determine lpcraft version")
-
-
-version = _get_version()
+version = importlib.metadata.version("lpcraft")
version_description = f"lpcraft, version {version}"
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index 31ea43e..7251e32 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -69,7 +69,7 @@ parts:
# do the usual pull stuff
snapcraftctl pull
# set the version
- snapcraftctl set-version "$( python3 -c 'from lpcraft._version import version; print(version)' )"
+ snapcraftctl set-version "$( sed -n '/^version = /s///p' $SNAPCRAFT_PROJECT_DIR/setup.cfg )"
override-build: |
snapcraftctl build
# python3 fixup symlink (snapcraft bug)
Follow ups