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

Snow 1532860 clean deprecated snowpark flags, clean help messages #1378

Merged
merged 8 commits into from
Jul 30, 2024
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Dropped support for Python below 3.10 version.
* `snow object stage` commands are removed in favour of `snow stage`.
* `snow snowpark init` and `snow streamlit init` commands are removed in favor of `snow init` command.
* Removed deprecated flags from `snow snowpark` commands.

## Deprecations

Expand Down
3 changes: 2 additions & 1 deletion src/snowflake/cli/plugins/connection/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ def test(
@app.command(requires_connection=False)
def set_default(
name: str = typer.Argument(
help="Name of the connection, as defined in your `config.toml`"
help="Name of the connection, as defined in your `config.toml`",
show_default=False,
),
**options,
):
Expand Down
2 changes: 2 additions & 0 deletions src/snowflake/cli/plugins/git/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _repo_path_argument_callback(path):
" For example: @my_repo/branches/main/"
),
callback=_repo_path_argument_callback,
show_default=False,
)
add_object_command_aliases(
app=app,
Expand Down Expand Up @@ -245,6 +246,7 @@ def copy(
repository_path: str = RepoPathArgument,
destination_path: str = typer.Argument(
help="Target path for copy operation. Should be a path to a directory on remote stage or local file system.",
show_default=False,
),
parallel: int = typer.Option(
4,
Expand Down
1 change: 1 addition & 0 deletions src/snowflake/cli/plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def app_init(
path: str = typer.Argument(
...,
help=f"""Directory to be initialized with the Snowflake Native App project. This directory must not already exist.""",
show_default=False,
),
name: str = typer.Option(
None,
Expand Down
1 change: 1 addition & 0 deletions src/snowflake/cli/plugins/notebook/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"--notebook-file",
"-f",
help="Stage path with notebook file. For example `@stage/path/to/notebook.ipynb`",
show_default=False,
)


Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/cli/plugins/object/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)


NameArgument = typer.Argument(help="Name of the object")
NameArgument = typer.Argument(help="Name of the object.", show_default=False)
ObjectArgument = typer.Argument(
help="Type of object. For example table, database, compute-pool.",
case_sensitive=False,
Expand Down
33 changes: 1 addition & 32 deletions src/snowflake/cli/plugins/snowpark/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
)
from snowflake.cli.api.commands.flags import (
ReplaceOption,
deprecated_flag_callback_enum,
execution_identifier_argument,
identifier_argument,
like_option,
Expand Down Expand Up @@ -71,7 +70,6 @@
check_if_replace_is_required,
)
from snowflake.cli.plugins.snowpark.manager import FunctionManager, ProcedureManager
from snowflake.cli.plugins.snowpark.models import YesNoAsk
from snowflake.cli.plugins.snowpark.package.anaconda_packages import (
AnacondaPackages,
AnacondaPackagesManager,
Expand All @@ -80,12 +78,9 @@
from snowflake.cli.plugins.snowpark.snowpark_package_paths import SnowparkPackagePaths
from snowflake.cli.plugins.snowpark.snowpark_shared import (
AllowSharedLibrariesOption,
DeprecatedCheckAnacondaForPyPiDependencies,
IgnoreAnacondaOption,
IndexUrlOption,
SkipVersionCheckOption,
deprecated_allow_native_libraries_option,
resolve_allow_shared_libraries_yes_no_ask,
)
from snowflake.cli.plugins.snowpark.zipper import zip_dir
from snowflake.cli.plugins.stage.manager import StageManager
Expand Down Expand Up @@ -364,18 +359,6 @@ def _deploy_single_object(
}


deprecated_pypi_download_option = typer.Option(
YesNoAsk.NO.value,
"--pypi-download",
help="Whether to download non-Anaconda packages from PyPi.",
hidden=True,
callback=deprecated_flag_callback_enum(
"--pypi-download flag is deprecated. Snowpark build command"
" always tries to download non-Anaconda packages from external index (PyPi by default)."
),
)


def _read_snowflake_requrements_file(file_path: SecurePath):
if not file_path.exists():
return []
Expand All @@ -389,11 +372,6 @@ def build(
allow_shared_libraries: bool = AllowSharedLibrariesOption,
index_url: Optional[str] = IndexUrlOption,
skip_version_check: bool = SkipVersionCheckOption,
deprecated_package_native_libraries: YesNoAsk = deprecated_allow_native_libraries_option(
"--package-native-libraries"
),
deprecated_check_anaconda_for_pypi_deps: bool = DeprecatedCheckAnacondaForPyPiDependencies,
_deprecated_pypi_download: YesNoAsk = deprecated_pypi_download_option,
**options,
) -> CommandResult:
"""
Expand All @@ -402,9 +380,6 @@ def build(
"""

assert_project_type("snowpark")

if not deprecated_check_anaconda_for_pypi_deps:
ignore_anaconda = True
cli_context = get_cli_context()
snowpark_paths = SnowparkPackagePaths.for_snowpark_project(
project_root=SecurePath(cli_context.project_root),
Expand Down Expand Up @@ -439,13 +414,7 @@ def build(
if package_utils.detect_and_log_shared_libraries(
download_result.downloaded_packages_details
):
# TODO: yes/no/ask logic should be removed in 3.0
if not (
allow_shared_libraries
or resolve_allow_shared_libraries_yes_no_ask(
deprecated_package_native_libraries
)
):
if not allow_shared_libraries:
raise ClickException(
"Some packages contain shared (.so/.dll) libraries. "
"Try again with --allow-shared-libraries."
Expand Down
7 changes: 0 additions & 7 deletions src/snowflake/cli/plugins/snowpark/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@
import re
import zipfile
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import List

from requirements import requirement


class YesNoAsk(Enum):
YES = "yes"
NO = "no"
ASK = "ask"


class Requirement(requirement.Requirement):
extra_pattern = re.compile("'([^']*)'")

Expand Down
69 changes: 4 additions & 65 deletions src/snowflake/cli/plugins/snowpark/package/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@

import typer
from click import ClickException
from snowflake.cli.api.commands.flags import (
deprecated_flag_callback,
)
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
from snowflake.cli.api.output.types import CommandResult, MessageResult
from snowflake.cli.api.secure_path import SecurePath
from snowflake.cli.plugins.snowpark.models import (
Requirement,
YesNoAsk,
)
from snowflake.cli.plugins.snowpark.package.anaconda_packages import (
AnacondaPackages,
Expand All @@ -46,8 +42,6 @@
IgnoreAnacondaOption,
IndexUrlOption,
SkipVersionCheckOption,
deprecated_allow_native_libraries_option,
resolve_allow_shared_libraries_yes_no_ask,
)
from snowflake.cli.plugins.snowpark.zipper import zip_dir

Expand All @@ -58,36 +52,11 @@
log = logging.getLogger(__name__)


lookup_install_option = typer.Option(
False,
"--pypi-download",
hidden=True,
callback=deprecated_flag_callback(
"Using --pypi-download is deprecated. Lookup command no longer checks for package in PyPi."
),
help="Installs packages that are not available on the Snowflake Anaconda channel.",
)

lookup_deprecated_install_option = typer.Option(
False,
"--yes",
"-y",
hidden=True,
callback=deprecated_flag_callback(
"Using --yes is deprecated. Lookup command no longer checks for package in PyPi."
),
help="Installs packages that are not available on the Snowflake Anaconda channel.",
)


@app.command("lookup", requires_connection=True)
def package_lookup(
package_name: str = typer.Argument(
..., help="Name of the package.", show_default=False
),
# todo: remove with 3.0
_: bool = lookup_install_option,
__: bool = lookup_deprecated_install_option,
**options,
) -> CommandResult:
"""
Expand Down Expand Up @@ -125,12 +94,14 @@ def package_upload(
"-f",
help="Path to the file to upload.",
exists=False,
show_default=False,
),
stage: str = typer.Option(
...,
"--stage",
"-s",
help="Name of the stage in which to upload the file, not including the @ symbol.",
show_default=False,
),
overwrite: bool = typer.Option(
False,
Expand All @@ -146,43 +117,17 @@ def package_upload(
return MessageResult(upload(file=file, stage=stage, overwrite=overwrite))


deprecated_pypi_download_option = typer.Option(
False,
"--pypi-download",
hidden=True,
callback=deprecated_flag_callback(
"Using --pypi-download is deprecated. Create command always checks for package in PyPi."
),
help="Installs packages that are not available on the Snowflake Anaconda channel.",
)

deprecated_install_option = typer.Option(
False,
"--yes",
"-y",
hidden=True,
help="Installs packages that are not available on the Snowflake Anaconda channel.",
callback=deprecated_flag_callback(
"Using --yes is deprecated. Create command always checks for package in PyPi."
),
)


@app.command("create", requires_connection=True)
def package_create(
name: str = typer.Argument(
...,
help="Name of the package to create.",
show_default=False,
),
ignore_anaconda: bool = IgnoreAnacondaOption,
index_url: Optional[str] = IndexUrlOption,
skip_version_check: bool = SkipVersionCheckOption,
allow_shared_libraries: bool = AllowSharedLibrariesOption,
deprecated_allow_native_libraries: YesNoAsk = deprecated_allow_native_libraries_option(
"--allow-native-libraries"
),
_deprecated_install_option: bool = deprecated_install_option,
_deprecated_install_packages: bool = deprecated_pypi_download_option,
**options,
) -> CommandResult:
"""
Expand Down Expand Up @@ -217,13 +162,7 @@ def package_create(
# The package is not in anaconda, so we have to pack it
log.info("Checking to see if packages have shared (.so/.dll) libraries...")
if detect_and_log_shared_libraries(download_result.downloaded_packages_details):
# TODO: yes/no/ask logic should be removed in 3.0
if not (
allow_shared_libraries
or resolve_allow_shared_libraries_yes_no_ask(
deprecated_allow_native_libraries
)
):
if not allow_shared_libraries:
raise ClickException(
"Some packages contain shared (.so/.dll) libraries. "
"Try again with --allow-shared-libraries."
Expand Down
36 changes: 0 additions & 36 deletions src/snowflake/cli/plugins/snowpark/snowpark_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,14 @@

from __future__ import annotations

import click
import typer
from snowflake.cli.api.commands.flags import (
deprecated_flag_callback,
deprecated_flag_callback_enum,
)
from snowflake.cli.plugins.snowpark.models import YesNoAsk


def deprecated_allow_native_libraries_option(old_flag_name: str):
return typer.Option(
YesNoAsk.NO.value,
old_flag_name,
help="Allows native libraries, when using packages installed through PIP",
hidden=True,
callback=deprecated_flag_callback_enum(
f"{old_flag_name} flag is deprecated. Use --allow-shared-libraries flag instead."
),
)


def resolve_allow_shared_libraries_yes_no_ask(allow_shared_libraries: YesNoAsk) -> bool:
if allow_shared_libraries == YesNoAsk.ASK:
return click.confirm("Continue with package installation?", default=False)
else:
return allow_shared_libraries == YesNoAsk.YES


AllowSharedLibrariesOption: bool = typer.Option(
False,
"--allow-shared-libraries",
help="Allows shared (.so) libraries, when using packages installed through PIP.",
)

DeprecatedCheckAnacondaForPyPiDependencies: bool = typer.Option(
True,
"--check-anaconda-for-pypi-deps/--no-check-anaconda-for-pypi-deps",
"-a",
help="""Checks if any of missing Anaconda packages dependencies can be imported directly from Anaconda. Valid values include: `true`, `false`, Default: `true`.""",
hidden=True,
callback=deprecated_flag_callback(
"--check-anaconda-for-pypi-deps flag is deprecated. Use --ignore-anaconda flag instead."
),
)

IgnoreAnacondaOption: bool = typer.Option(
False,
Expand Down
13 changes: 9 additions & 4 deletions src/snowflake/cli/plugins/spcs/jobs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
@app.command(requires_connection=True)
def create(
compute_pool: str = typer.Option(
..., "--compute-pool", help="Name of the pool in which to run the job."
...,
"--compute-pool",
help="Name of the pool in which to run the job.",
show_default=False,
),
spec_path: Path = typer.Option(
...,
Expand All @@ -40,6 +43,7 @@ def create(
file_okay=True,
dir_okay=False,
exists=True,
show_default=False,
),
**options,
) -> CommandResult:
Expand All @@ -52,9 +56,9 @@ def create(

@app.command(requires_connection=True)
def logs(
identifier: str = typer.Argument(..., help="Job id"),
identifier: str = typer.Argument(..., help="Job id", show_default=False),
container_name: str = typer.Option(
..., "--container-name", help="Name of the container."
..., "--container-name", help="Name of the container.", show_default=False
),
**options,
):
Expand All @@ -69,7 +73,8 @@ def logs(

@app.command(requires_connection=True)
def status(
identifier: str = typer.Argument(..., help="ID of the job."), **options
identifier: str = typer.Argument(..., help="ID of the job.", show_default=False),
**options,
) -> CommandResult:
"""
Returns the status of a named Snowpark Container Services job.
Expand Down
Loading
Loading