Skip to content

Commit

Permalink
Check if pip is installed when not using uv flag (zenml-io#2929)
Browse files Browse the repository at this point in the history
  • Loading branch information
mennoliefstingh committed Aug 13, 2024
1 parent e41b791 commit 5b87b9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/zenml/cli/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,19 @@ def install(
force: Force the installation of the required packages.
uv: Use uv for package installation (experimental).
"""
from zenml.cli.utils import is_uv_installed
from zenml.cli.utils import is_pip_installed, is_uv_installed
from zenml.integrations.registry import integration_registry

if uv and not is_uv_installed():
error(
"UV is not installed but the uv flag was passed in. Please install uv or remove the uv flag."
)

if not uv and not is_pip_installed():
error(
"Pip is not installed. Please install pip or use the uv flag for package installation."
)

if not integrations:
# no integrations specified, use all registered integrations
integrations = set(integration_registry.integrations.keys())
Expand Down Expand Up @@ -346,12 +351,17 @@ def uninstall(
force: Force the uninstallation of the required packages.
uv: Use uv for package uninstallation (experimental).
"""
from zenml.cli.utils import is_uv_installed
from zenml.cli.utils import is_pip_installed, is_uv_installed
from zenml.integrations.registry import integration_registry

if uv and not is_uv_installed():
error("Package `uv` is not installed. Please install it and retry.")

if not uv and not is_pip_installed():
error(
"Pip is not installed. Please install pip or use the uv flag (--uv) for package installation."
)

if not integrations:
# no integrations specified, use all registered integrations
integrations = tuple(integration_registry.integrations.keys())
Expand Down Expand Up @@ -423,12 +433,17 @@ def upgrade(
force: Force the installation of the required packages.
uv: Use uv for package installation (experimental).
"""
from zenml.cli.utils import is_uv_installed
from zenml.cli.utils import is_pip_installed, is_uv_installed
from zenml.integrations.registry import integration_registry

if uv and not is_uv_installed():
error("Package `uv` is not installed. Please install it and retry.")

if not uv and not is_pip_installed():
error(
"Pip is not installed. Please install pip or use the uv flag (--uv) for package installation."
)

if not integrations:
# no integrations specified, use all registered integrations
integrations = set(integration_registry.integrations.keys())
Expand Down
13 changes: 13 additions & 0 deletions src/zenml/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,19 @@ def is_uv_installed() -> bool:
return False


def is_pip_installed() -> bool:
"""Check if pip is installed in the current environment.
Returns:
True if pip is installed, False otherwise.
"""
try:
pkg_resources.get_distribution("pip")
return True
except pkg_resources.DistributionNotFound:
return False


def pretty_print_secret(
secret: Dict[str, str],
hide_secret: bool = True,
Expand Down

0 comments on commit 5b87b9c

Please sign in to comment.