Skip to content

Commit

Permalink
Throw an error when running integration installs when uv == False but…
Browse files Browse the repository at this point in the history
… pip is not installed (#2930)

* Check if pip is installed when not using uv flag (#2929)

* fix: Include --uv flag hint more explicitly in error message

Co-authored-by: Alex Strick van Linschoten <[email protected]>

---------

Co-authored-by: Alex Strick van Linschoten <[email protected]>
Co-authored-by: Barış Can Durak <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent ed62d10 commit a496fff
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 (--uv) 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 a496fff

Please sign in to comment.