-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented reinstall and list methods, save .metadata file in …
…app-specific venv
- Loading branch information
1 parent
609e990
commit 8a44dab
Showing
7 changed files
with
322 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ dependencies = [ | |
"typer", | ||
"plumbum", | ||
"threadful>=0.2", | ||
"quickle", | ||
] | ||
|
||
[project.optional-dependencies] | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pathlib import Path | ||
|
||
BIN_DIR = Path.home() / ".local/bin" | ||
WORK_DIR = ( | ||
Path.home() / ".local/uvx" | ||
) # use 'ensure_local_folder()' instead, whenever possible! |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import textwrap | ||
from pathlib import Path | ||
|
||
import plumbum | ||
from plumbum.cmd import grep, uv | ||
|
||
|
||
def _run_python_in_venv(*args: str, venv: Path) -> str: | ||
python = venv / "bin" / "python" | ||
|
||
return plumbum.local[python](*args) | ||
|
||
|
||
def run_python_code_in_venv(code: str, venv: Path) -> str: | ||
""" | ||
Run Python code in a virtual environment. | ||
Args: | ||
code (str): The Python code to run. | ||
venv (Path): The path of the virtual environment. | ||
Returns: | ||
str: The output of the Python code. | ||
""" | ||
code = textwrap.dedent(code) | ||
return _run_python_in_venv("-c", code, venv=venv) | ||
|
||
|
||
def get_python_version(venv: Path): | ||
return _run_python_in_venv("--version", venv=venv).strip() | ||
|
||
|
||
def get_python_executable(venv: Path): | ||
executable = venv / "bin" / "python" | ||
return str(executable.resolve()) # /usr/bin/python3.xx | ||
|
||
|
||
def get_package_version(package: str) -> str: | ||
# assumes `with virtualenv(venv)` block executing this function | ||
# uv pip freeze | grep ^su6== | ||
return (uv["pip", "freeze"] | grep[f"^{package}=="])().strip().split("==")[-1] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import typing | ||
|
||
from ._constants import BIN_DIR, WORK_DIR | ||
|
||
|
||
def check_symlink(symlink: str, venv: str) -> bool: | ||
symlink_path = BIN_DIR / symlink | ||
target_path = WORK_DIR / "venvs" / venv | ||
|
||
return symlink_path.is_symlink() and target_path in symlink_path.resolve().parents | ||
|
||
|
||
def check_symlinks(symlinks: typing.Iterable[str], venv: str) -> dict[str, bool]: | ||
return {k: check_symlink(k, venv) for k in symlinks} |
This file contains 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
Oops, something went wrong.