Skip to content

Commit 1b64406

Browse files
authored
builtins: fallback to package.json for uap-core version
In case where uap-core isn't a git repo (e.g. git archive), use uap-core's `package.json` as a fallback for getting a version.
1 parent ce12905 commit 1b64406

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

ua-parser-builtins/hatch_build.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import io
4+
import json
45
import os
56
import os.path
67
import tempfile
@@ -10,19 +11,24 @@
1011
import yaml
1112
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
1213
from hatchling.metadata.plugin.interface import MetadataHookInterface
13-
from versioningit import get_version
14+
from versioningit import errors, get_version
1415

1516

1617
class MetadataHook(MetadataHookInterface):
1718
def update(self, metadata: dict[str, Any]) -> None:
18-
v = get_version(
19-
os.path.join(self.root, "uap-core"),
20-
config={
21-
"format": {
22-
"distance": "{next_version}.dev{distance}",
23-
}
24-
},
25-
)
19+
try:
20+
v = get_version(
21+
os.path.join(self.root, "uap-core"),
22+
config={
23+
"format": {
24+
"distance": "{next_version}.dev{distance}",
25+
}
26+
},
27+
)
28+
except errors.NotSdistError:
29+
with open(os.path.join(self.root, "uap-core", "package.json")) as ufile:
30+
ujson = json.load(ufile)
31+
v = ujson["version"]
2632
if v in ("0.15.0", "0.16.0", "0.18.0"):
2733
v = f"{v}.post1"
2834

0 commit comments

Comments
 (0)