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

Throw an error when running integration installs when uv == False but pip is not installed #2930

Merged
Merged
Show file tree
Hide file tree
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
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
Loading