Skip to content

Commit

Permalink
[FIX] force refreshing of project metadata when using uv
Browse files Browse the repository at this point in the history
I prefer a less surprising default at a very minor cost of
recomputing metadata when doing the editable install.
  • Loading branch information
sbidoul committed Aug 17, 2024
1 parent 75813d3 commit 3ec2382
Showing 1 changed file with 29 additions and 7 deletions.
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 3ec2382

Please sign in to comment.