Skip to content

Commit

Permalink
feat: started with uvx upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvandernoord committed Mar 11, 2024
1 parent 1880062 commit 2d68e14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/uvx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from typing import Optional

import plumbum # type: ignore
import rich
import typer
from typer import Context
Expand All @@ -23,6 +22,7 @@
reinstall_package,
run_command,
uninstall_package,
upgrade_package,
)
from .metadata import Metadata

Expand All @@ -36,6 +36,11 @@ def install(package_name: str, force: bool = False, python: str = ""):
install_package(package_name, python=python, force=force)


@app.command(name="upgrade")
@app.command(name="update")
def upgrade(package_name: str, force: bool = False):
upgrade_package(package_name, force=force)

@app.command(name="remove")
@app.command(name="uninstall")
def uninstall(package_name: str, force: bool = False):
Expand Down Expand Up @@ -128,8 +133,6 @@ def runpython(venv: str, ctx: Context):
subprocess.run([python, *ctx.args]) # nosec


# upgrade

# 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 @@ -195,6 +195,23 @@ def remove_dir(path: Path):
if path.exists():
shutil.rmtree(path)

def upgrade_package(package_name: str, force: bool = False):
# run `uv pip install --upgrade package` with requested install spec (version, extras, injected)
# if --force is used, the previous version is ignored.
print('upgrade', package_name)

spec_metadata = collect_metadata(package_name)

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

if not venv.exists():
rich.print(
f"No virtualenv for '{package_name}', stopping. Use '--force' to remove an executable with that name anyway.",
file=sys.stderr,
)
exit(1)


def uninstall_package(package_name: str, force: bool = False):
"""
Expand Down

0 comments on commit 2d68e14

Please sign in to comment.