Skip to content

Commit

Permalink
Merge pull request #160 from sbidoul/uv-refresh-package
Browse files Browse the repository at this point in the history
[FIX] force refreshing of project metadata when using uv
  • Loading branch information
sbidoul authored Aug 17, 2024
2 parents fcdf0b2 + 8794a20 commit b855a63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies=[
"typer[all] >=0.3.2",
# installers
"pip >=22.2",
"uv >=0.1.12",
"uv >=0.2.37",
# compat
"importlib_resources>=1.3 ; python_version<'3.9'",
"tomli ; python_version<'3.11'",
Expand Down
36 changes: 29 additions & 7 deletions src/pip_deepfreeze/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ class Installer(ABC):
@abstractmethod
def install_cmd(self, python: str) -> List[str]: ...

def editable_install_cmd(
self,
python: str,
project_root: Path,
project_name: str,
extras: Optional[Sequence[NormalizedName]],
) -> List[str]:
cmd = self.install_cmd(python)
cmd.append("-e")
if extras:
extras_str = ",".join(extras)
cmd.append(f"{project_root}[{extras_str}]")
else:
cmd.append(f"{project_root}")
return cmd

@abstractmethod
def uninstall_cmd(self, python: str) -> List[str]: ...

Expand Down Expand Up @@ -101,6 +117,18 @@ class UvpipInstaller(Installer):
def install_cmd(self, python: str) -> List[str]:
return [sys.executable, "-m", "uv", "pip", "install", "--python", python]

def editable_install_cmd(
self,
python: str,
project_root: Path,
project_name: str,
extras: Optional[Sequence[NormalizedName]],
) -> List[str]:
cmd = super().editable_install_cmd(python, project_root, project_name, extras)
# https://github.com/astral-sh/uv/issues/5484
cmd.append(f"--refresh-package={project_name}")
return cmd

def uninstall_cmd(self, python: str) -> List[str]:
return [sys.executable, "-m", "uv", "pip", "uninstall", "--python", python]

Expand Down Expand Up @@ -191,7 +219,7 @@ def pip_upgrade_project(
# 4. install project with constraints
project_name = get_project_name(python, project_root)
log_info(f"Installing/updating {project_name}")
cmd = installer.install_cmd(python)
cmd = installer.editable_install_cmd(python, project_root, project_name, extras)
if installer_options:
cmd.extend(installer_options)
cmd.extend(
Expand All @@ -201,12 +229,6 @@ def pip_upgrade_project(
*editable_constraints,
]
)
cmd.append("-e")
if extras:
extras_str = ",".join(extras)
cmd.append(f"{project_root}[{extras_str}]")
else:
cmd.append(f"{project_root}")
log_debug(f"Running {shlex.join(cmd)}")
constraints = constraints_without_editables_filename.read_text(
encoding="utf-8"
Expand Down

0 comments on commit b855a63

Please sign in to comment.