Skip to content

Commit

Permalink
feat: started on 'inject'
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvandernoord committed Mar 12, 2024
1 parent 61a3674 commit 7af0558
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/uvx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .core import (
as_virtualenv,
format_bools,
inject_packages,
install_package,
list_packages,
reinstall_package,
Expand Down Expand Up @@ -68,6 +69,16 @@ def reinstall(package: str, python: Optional[str] = None, force: bool = False):
)


@app.command()
def inject(into: str, package_specs: list[str]):
output(
inject_packages(
into,
package_specs,
)
)


# list
def _list_short(name: str, metadata: Maybe[Metadata]):
rich.print("-", name, metadata.map_or("[red]?[/red]", lambda md: md.installed_version))
Expand Down Expand Up @@ -154,8 +165,6 @@ def runpython(venv: str, ctx: Context):

# self-upgrade (uv and uvx)

# inject

# ...


Expand Down
17 changes: 17 additions & 0 deletions src/uvx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,23 @@ def reinstall_package(package_name: str, python: Optional[str] = None, force: bo
return install_package(install_spec, python=python, force=force)


def inject_packages(into: str, package_specs: list[str]) -> Result[str, Exception]:
match collect_metadata(into):
case Err(e):
return Err(e)
case Ok(meta):
# just bind meta
...

workdir = ensure_local_folder()
venv = workdir / "venvs" / meta.name

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}")


def remove_dir(path: Path):
"""
Remove a directory.
Expand Down

0 comments on commit 7af0558

Please sign in to comment.