From e50931d9a4576fce97f4c2f65fff6e1795d77dc1 Mon Sep 17 00:00:00 2001 From: Rohin Bhasin Date: Fri, 12 Jul 2024 02:12:59 -0400 Subject: [PATCH] Pass a req that's installed locally and sync it properly. --- runhouse/resources/packages/package.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/runhouse/resources/packages/package.py b/runhouse/resources/packages/package.py index aaf9f229d..6c9dda6e7 100644 --- a/runhouse/resources/packages/package.py +++ b/runhouse/resources/packages/package.py @@ -1,5 +1,6 @@ import copy import importlib.metadata as metadata +import json import re import sys from pathlib import Path @@ -92,6 +93,14 @@ def _find_locally_installed_version(package_name: str): except metadata.PackageNotFoundError: return None + @staticmethod + def _get_local_install_path(package_name: str): + distribution = metadata.distribution(package_name) + direct_url_json = distribution.read_text("direct_url.json") + if direct_url_json: + # File URL starts with file:// + return json.loads(direct_url_json)["url"][len("file://") :] + @staticmethod def _prepend_python_executable( install_cmd: str, env: Union[str, "Env"] = None, cluster: "Cluster" = None @@ -501,7 +510,14 @@ def from_string(specifier: str, dryrun=False): if install_method == "pip" and Package.is_python_package_string(target): locally_installed_version = Package._find_locally_installed_version(target) if locally_installed_version: - target = f"{target}=={locally_installed_version}" + # Check if this is a package that was installed from local + local_install_path = Package._get_local_install_path(target) + if local_install_path and Path(local_install_path).exists(): + target = Folder(path=local_install_path, dryrun=True) + + # Otherwise, this is a package that was installed from pip, probably + else: + target = f"{target}=={locally_installed_version}" # "Local" install method is a special case where we just copy a local folder and add to path if install_method == "local":