From 127452b4672584954692970e5f149af50afbf440 Mon Sep 17 00:00:00 2001 From: William Douglas Date: Fri, 14 Feb 2025 09:13:01 -0800 Subject: [PATCH 1/2] Fallback to package.json for uap-core version In case where uap-core isn't a git repo, use uap-core's package.json file as a fallback for getting a version. Signed-off-by: William Douglas --- ua-parser-builtins/hatch_build.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ua-parser-builtins/hatch_build.py b/ua-parser-builtins/hatch_build.py index 1eac776..63fe8c5 100644 --- a/ua-parser-builtins/hatch_build.py +++ b/ua-parser-builtins/hatch_build.py @@ -1,6 +1,7 @@ from __future__ import annotations import io +import json import os import os.path import tempfile @@ -10,19 +11,24 @@ import yaml from hatchling.builders.hooks.plugin.interface import BuildHookInterface from hatchling.metadata.plugin.interface import MetadataHookInterface -from versioningit import get_version +from versioningit import errors, get_version class MetadataHook(MetadataHookInterface): def update(self, metadata: dict[str, Any]) -> None: - v = get_version( - os.path.join(self.root, "uap-core"), - config={ - "format": { - "distance": "{next_version}.dev{distance}", - } - }, - ) + try: + v = get_version( + os.path.join(self.root, "uap-core"), + config={ + "format": { + "distance": "{next_version}.dev{distance}", + } + }, + ) + except errors.NotSdistError: + with open(os.path.join(self.root, "uap-core", 'package.json')) as ufile: + ujson = json.load(ufile) + v = ujson['version'] if v in ("0.15.0", "0.16.0", "0.18.0"): v = f"{v}.post1" From da7b5d8206b04a4e3d82d3658847674dfa78f745 Mon Sep 17 00:00:00 2001 From: masklinn Date: Sat, 15 Feb 2025 13:17:00 +0100 Subject: [PATCH 2/2] fix formatting --- ua-parser-builtins/hatch_build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ua-parser-builtins/hatch_build.py b/ua-parser-builtins/hatch_build.py index 63fe8c5..9bbe23f 100644 --- a/ua-parser-builtins/hatch_build.py +++ b/ua-parser-builtins/hatch_build.py @@ -26,9 +26,9 @@ def update(self, metadata: dict[str, Any]) -> None: }, ) except errors.NotSdistError: - with open(os.path.join(self.root, "uap-core", 'package.json')) as ufile: + with open(os.path.join(self.root, "uap-core", "package.json")) as ufile: ujson = json.load(ufile) - v = ujson['version'] + v = ujson["version"] if v in ("0.15.0", "0.16.0", "0.18.0"): v = f"{v}.post1"