Skip to content

Commit

Permalink
Refactoring install method splitting into a helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohinb2 committed Jun 20, 2024
1 parent 7f7c6a4 commit b9fe2dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion runhouse/resources/envs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _process_reqs(reqs):
package = rns_client.load_config(package)
else:
# if package refers to a local path package
path = Path(package.split(":")[-1]).expanduser()
path = Path(Package.split_req_install_method(package)[1]).expanduser()
if path.is_absolute() or (locate_working_dir() / path).exists():
package = Package.from_string(package)
elif isinstance(package, dict):
Expand Down
5 changes: 3 additions & 2 deletions runhouse/resources/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,9 @@ def _extract_pointers(raw_cls_or_fn: Union[Type, Callable], reqs: List[str]):
):
local_path = Path(req.install_target.local_path)
elif isinstance(req, str):
if req.split(":")[0] in ["local", "reqs", "pip"]:
req = req.split(":")[1]
install_method, new_req = Package.split_req_install_method(req)
if install_method in ["local", "reqs", "pip"]:
req = new_req

if Path(req).expanduser().resolve().exists():
# Relative paths are relative to the working directory in Folders/Packages!
Expand Down
12 changes: 9 additions & 3 deletions runhouse/resources/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ def to(
new_package.install_target = new_folder
return new_package

@staticmethod
def split_req_install_method(req_str: str):
"""Split a requirements string into a install method and the rest of the string."""
splat = req_str.split(" ", 1)
return splat[0], splat[1] if len(splat) > 1 else "", splat[0]

@staticmethod
def from_config(config: dict, dryrun=False, _resolve_children=True):
if isinstance(config.get("install_target"), dict):
Expand Down Expand Up @@ -410,8 +416,8 @@ def from_string(specifier: str, dryrun=False):
)

target_and_args = specifier
if specifier.split(":")[0] in INSTALL_METHODS:
target_and_args = specifier.split(":", 1)[1]
if Package.split_req_install_method(target_and_args)[0] in INSTALL_METHODS:
target_and_args = Package.split_req_install_method(target_and_args)[1]
rel_target, args = (
target_and_args.split(" ", 1)
if " " in target_and_args
Expand Down Expand Up @@ -456,7 +462,7 @@ def from_string(specifier: str, dryrun=False):
)
elif specifier.startswith("rh:"):
# Calling the factory method below
return package(name=specifier[3:], dryrun=dryrun)
return package(name=specifier[len("rh:") :], dryrun=dryrun)
else:
if Path(specifier).resolve().exists():
return Package(
Expand Down

0 comments on commit b9fe2dd

Please sign in to comment.