Skip to content

Commit

Permalink
Check correctly for things that could be Python packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohinb2 committed Jul 12, 2024
1 parent 41ab1af commit 764fe33
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion runhouse/resources/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def __str__(self):
return f"Package: {self.install_target.path}"
return f"Package: {self.install_target}"

@staticmethod
def is_python_package_string(s: str):
return re.match(r"^[a-zA-Z0-9\._-]+$", s) is not None

@staticmethod
def _find_locally_installed_version(package_name: str):
try:
Expand Down Expand Up @@ -488,7 +492,7 @@ def from_string(specifier: str, dryrun=False):
# If we are just defaulting to pip, attempt to install the same version of the package
# that is already installed locally
# Check if the target is only letters, nothing else. This means its a string like 'numpy'.
if install_method == "pip" and target.isalpha():
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}"
Expand Down

0 comments on commit 764fe33

Please sign in to comment.