Skip to content

Commit

Permalink
fix: (WIP) try to resolve local packages by dry-run installing them
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvandernoord committed Mar 4, 2024
1 parent 0aa813f commit 2f2a780
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
5 changes: 0 additions & 5 deletions src/uvx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def list_venvs(short: bool = False, verbose: bool = False, json: bool = False):
_list_normal(name, metadata, verbose=verbose)



@app.command(context_settings={"allow_extra_args": True, "ignore_unknown_options": True})
def runuv(venv: str, ctx: Context):
"""Run 'uv' in the right venv."""
Expand All @@ -118,8 +117,6 @@ def runuv(venv: str, ctx: Context):
def runpip(venv: str, ctx: Context):
"""Run 'pip' in the right venv."""
with as_virtualenv(venv) as venv_path:
python = venv_path / "bin" / "python"
plumbum.local[str(python)]("-m", "uv", "pip", "install", "pip")
run_command("pip", *ctx.args)


Expand All @@ -137,8 +134,6 @@ def runpython(venv: str, ctx: Context):

# inject

# version or --version (incl. 'uv' version and Python version)

# ...


Expand Down
8 changes: 7 additions & 1 deletion src/uvx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def ensure_local_folder() -> Path:
return WORK_DIR


def create_venv(name: str, python: Optional[str] = None, force: bool = False) -> Path:
def create_venv(name: str, python: Optional[str] = None, force: bool = False, with_pip: bool = True) -> Path:
"""
Create a virtual environment.
Expand Down Expand Up @@ -269,6 +269,12 @@ def create_venv(name: str, python: Optional[str] = None, force: bool = False) ->

uv(*args).join()

if with_pip:
with virtualenv(venv_path):
animate(
uv("pip", "install", "pip", "uv")
)

return venv_path


Expand Down
48 changes: 35 additions & 13 deletions src/uvx/metadata.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""This file contains Logic related to the .metadata file."""

import sys
import typing
from pathlib import Path
from typing import Optional

import plumbum
import quickle # type: ignore
from packaging.requirements import Requirement
import threadful
from packaging.requirements import Requirement, InvalidRequirement

from ._python import _run_python_in_venv
from ._symlinks import check_symlinks

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -45,19 +48,38 @@ def check_script_symlinks(self, name: str) -> "Self":
quickle_dec = quickle.Decoder(registry=[Metadata])


@threadful.thread
def resolve_local(spec: str):
# todo: finish
_python = plumbum.local[sys.executable]

_python("-m", "uv", "pip", "install", "pip") # ensure we have pip

result = _python("-m", "pip", "install", "--no-deps", "--dry-run", "--ignore-installed", "--report",
"/tmp/out.json", spec)

print(result)
return result


def collect_metadata(spec: str) -> Metadata:
"""Parse an install spec into a (incomplete) Metadata object."""
parsed_spec = Requirement(spec)

return Metadata(
install_spec=spec,
name=parsed_spec.name,
scripts={}, # postponed
extras=parsed_spec.extras,
requested_version=str(parsed_spec.specifier),
installed_version="", # postponed
python="", # postponed
)
try:
parsed_spec = Requirement(spec)

return Metadata(
install_spec=spec,
name=parsed_spec.name,
scripts={}, # postponed
extras=parsed_spec.extras,
requested_version=str(parsed_spec.specifier),
installed_version="", # postponed
python="", # postponed
)
except InvalidRequirement:
threadful.animate(resolve_local(spec), text=f"Trying to install local package '{spec}'")
print("reeeeeeeeeeeeeeee")
exit(1)


def store_metadata(meta: Metadata, venv: Path):
Expand Down

0 comments on commit 2f2a780

Please sign in to comment.