Skip to content

Commit

Permalink
builtins: fallback to package.json for uap-core version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bryteise authored Feb 15, 2025
1 parent ce12905 commit 1b64406
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ua-parser-builtins/hatch_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import io
import json
import os
import os.path
import tempfile
Expand All @@ -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"

Expand Down

0 comments on commit 1b64406

Please sign in to comment.