Skip to content

Commit

Permalink
Pass a req that's installed locally and sync it properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohinb2 committed Jul 12, 2024
1 parent 0ccf07b commit c87be93
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion runhouse/resources/packages/package.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import importlib.metadata as metadata
import json
import re
import sys
from pathlib import Path
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -495,7 +504,15 @@ 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)
install_method = "reqs"

# 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":
Expand Down

0 comments on commit c87be93

Please sign in to comment.