Created
April 30, 2025 14:22
-
-
Save zanieb/081bac4a56004b336cc0eaaa1b4a275c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
$ uvx [email protected] run get-uv-version.py | |
0.6.0 | |
$ uvx [email protected] run get-uv-version.py | |
0.7.0 | |
""" | |
import json | |
import os | |
import subprocess | |
def get_uv_version() -> str: | |
uv = os.environ.get("UV", "uv") | |
result = json.loads( | |
subprocess.check_output( | |
[uv, "version", "--output-format", "json"], stderr=subprocess.DEVNULL | |
) | |
) | |
package = result.get("package_name") | |
# Either pre 0.7.0, or not in a project and uv's version was returned | |
if package is None or package == "uv": | |
return result["version"] | |
# Post 0.7.0, `uv self version` should be used | |
return json.loads( | |
subprocess.check_output([uv, "self", "version", "--output-format", "json"]) | |
)["version"] | |
print(get_uv_version()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment