From 8794a203ecfcc60f6795be6c7f0b1f85a3b57a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 17 Aug 2024 12:23:01 +0200 Subject: [PATCH] [FIX] force refreshing of project metadata when using uv I prefer a less surprising default at a very minor cost of recomputing metadata when doing the editable install. --- pyproject.toml | 2 +- src/pip_deepfreeze/pip.py | 36 +++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c044884..478211e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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'", diff --git a/src/pip_deepfreeze/pip.py b/src/pip_deepfreeze/pip.py index a33f2b4..1cde772 100644 --- a/src/pip_deepfreeze/pip.py +++ b/src/pip_deepfreeze/pip.py @@ -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]: ... @@ -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] @@ -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( @@ -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"