Skip to content

Commit

Permalink
feat: continued inject cli functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvandernoord committed Mar 15, 2024
1 parent 7af0558 commit ffd3792
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/uvx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def _list_normal(name: str, metadata: Maybe[Metadata], verbose: bool = False):
TAB,
f"Installed Version: {md.installed_version} on {md.python}.",
)
if md.injected:
p = ", ".join([f"'{_}'" for _ in md.injected])
rich.print(TAB, f"Injected Packages: {p}")
rich.print(TAB, "Scripts:", format_bools(md.scripts))


Expand Down
18 changes: 17 additions & 1 deletion src/uvx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,23 @@ def inject_packages(into: str, package_specs: list[str]) -> Result[str, Exceptio
if not venv.exists():
return Err(ValueError(f"'{meta.name}' was not previously installed. Please run 'uvx install {into}' first."))

return Ok(f"todo in {meta}")
# after getting the right venv, load actual metadata (with fallback to previous emptier metadata):
meta = read_metadata(venv).unwrap_or(meta)

with virtualenv(venv), exit_on_pb_error():
try:
animate(uv("pip", "install", *package_specs), text=f"injecting {package_specs}")
except plumbum.ProcessExecutionError as e:
return Err(e)

# todo: update metadata
meta.injected = (meta.injected or []) + package_specs

print(f"{meta = }")

store_metadata(meta, venv)

return Ok(f"💉 Injected {package_specs} into {meta.name}.") # :needle:


def remove_dir(path: Path):
Expand Down

0 comments on commit ffd3792

Please sign in to comment.