-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Py.typed #1685
Py.typed #1685
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
The Python API of `uv` is not guaranteed to be stable and may chance at any time. It is | ||
strongly discouraged to import from our `uv` Python module, but you can do so at your | ||
own risk. | ||
""" | ||
from uv.__main__ import detect_virtualenv, find_uv_bin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not import then from I think |
||
|
||
__all__ = ["detect_virtualenv", "find_uv_bin"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,17 @@ | ||
import os | ||
import sys | ||
import sysconfig | ||
|
||
|
||
def detect_virtualenv() -> str: | ||
""" | ||
Find the virtual environment path for the current Python executable. | ||
""" | ||
|
||
# If it's already set, then just use it | ||
value = os.getenv("VIRTUAL_ENV") | ||
if value: | ||
return value | ||
|
||
# Otherwise, check if we're in a venv | ||
venv_marker = os.path.join(sys.prefix, "pyvenv.cfg") | ||
|
||
if os.path.exists(venv_marker): | ||
return sys.prefix | ||
|
||
return "" | ||
from pathlib import Path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are explicitly not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you revert those changes? |
||
|
||
|
||
def find_uv_bin() -> str: | ||
"""Return the uv binary path.""" | ||
|
||
uv_exe = "uv" + sysconfig.get_config_var("EXE") | ||
|
||
path = os.path.join(sysconfig.get_path("scripts"), uv_exe) | ||
if os.path.isfile(path): | ||
return path | ||
path = Path(sysconfig.get_path("scripts")) / uv_exe | ||
if path.is_file(): | ||
return str(path) | ||
|
||
if sys.version_info >= (3, 10): | ||
user_scheme = sysconfig.get_preferred_scheme("user") | ||
|
@@ -40,11 +22,31 @@ def find_uv_bin() -> str: | |
else: | ||
user_scheme = "posix_user" | ||
|
||
path = os.path.join(sysconfig.get_path("scripts", scheme=user_scheme), uv_exe) | ||
if os.path.isfile(path): | ||
return path | ||
path = Path(sysconfig.get_path("scripts", scheme=user_scheme)) / uv_exe | ||
if path.is_file(): | ||
return str(path) | ||
|
||
raise FileNotFoundError(path) | ||
msg = str(path) | ||
raise FileNotFoundError(msg) | ||
|
||
|
||
def detect_virtualenv() -> str: | ||
""" | ||
Find the virtual environment path for the current Python executable. | ||
""" | ||
|
||
# If it's already set, then just use it | ||
value = os.getenv("VIRTUAL_ENV") | ||
if value: | ||
return value | ||
|
||
# Otherwise, check if we're in a venv | ||
venv_marker = Path(sys.prefix) / "pyvenv.cfg" | ||
|
||
if venv_marker.exists(): | ||
return sys.prefix | ||
|
||
return "" | ||
|
||
|
||
if __name__ == "__main__": | ||
|
@@ -58,7 +60,7 @@ def find_uv_bin() -> str: | |
if sys.platform == "win32": | ||
import subprocess | ||
|
||
completed_process = subprocess.run([uv, *sys.argv[1:]], env=env) | ||
completed_process = subprocess.run([uv, *sys.argv[1:]], env=env, check=False) | ||
sys.exit(completed_process.returncode) | ||
else: | ||
os.execvpe(uv, [uv, *sys.argv[1:]], env=env) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a typo and this seems sufficient. I was only strongly discouraging people from importing from
__main__
.