Skip to content

Commit

Permalink
Close #65: do a safer/better job of parsing dependency versions
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Dec 8, 2022
1 parent 6b60427 commit 4e04c75
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion shinywidgets/_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ def widget_pkg(w: object) -> str:


def as_version(v: str) -> str:
return re.sub("\\D*", "", str(packaging.version.parse(v)))
try:
# version could be in node-semver format
# which is not compatible with packaging.version.parse
# so we strip out the leading non-numeric characters
# e.g., ^1.2.3 -> 1.2.3
v = re.sub("^\\D+", "", v)
return str(packaging.version.parse(v))
except Exception:
# parsing could still fail if the version is something like
# "*", but get the _actual_ version doesn't seem that important
# since I don't think it'll be possible
return "0.0"

0 comments on commit 4e04c75

Please sign in to comment.