Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a req that's installed locally and sync it properly. #997

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 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,20 @@ 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://
try:
url = json.loads(direct_url_json).get("url", None)
if url:
if url.startswith("file://"):
return url[len("file://") :]
except json.JSONDecodeError:
return None

@staticmethod
def _prepend_python_executable(
install_cmd: str, env: Union[str, "Env"] = None, cluster: "Cluster" = None
Expand Down Expand Up @@ -501,7 +516,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":
Expand Down
Loading