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

Add deprecation warning #675

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
16 changes: 16 additions & 0 deletions databricks_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
# pylint:disable=import-error
# pylint:disable=bare-except

import warnings


def issue_deprecation_warning():
# Don't print deprecation warning when running the CLI itself.
import sys
import os
if sys.argv and os.path.basename(sys.argv[0]) == 'databricks':
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a check here to only fire the warning once?

I ran python3 -m databricks_cli.cli and got a spew of a dozen identical warnings.

warnings.warn("the databricks_cli module is deprecated in favor of databricks-sdk-py. Python "
"3.12 will be the last version of Python supported by databricks-cli. Please "
"migrate to databricks-sdk-py as documented in the migration guide: "
"https://docs.databricks.com/en/dev-tools/cli/migrate.html",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration guide doesn't mention the SDK, only the CLI.

We should link to SDK docs here, assuming callers are trying to leverage this code as SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, we never made a migration guide for the Python SDK...

DeprecationWarning, stacklevel=3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the stacklevel mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, if folks use the Databricks CLI itself, they don't see these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stacklevel changes the output of warnings.warn. Normally, the warning message starts with the line that the warning.warn call is on, but increasing stacklevel allows the warning to point to the place where the caller uses the library/function in question. In this case, the warning will point to the line with import databricks_cli:
Screenshot 2023-10-05 at 10 41 20


issue_deprecation_warning()

def initialize_cli_for_databricks_notebooks():
import IPython
Expand Down
3 changes: 3 additions & 0 deletions databricks_cli/cluster_policies/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/clusters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/configure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/dbfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/groups/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/instance_pools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/jobs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/libraries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/oauth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/pipelines/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
6 changes: 5 additions & 1 deletion databricks_cli/repos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/runs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@
"""
from .service import *
from .api_client import ApiClient

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/secrets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/stack/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
4 changes: 4 additions & 0 deletions databricks_cli/tokens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/unity_catalog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
3 changes: 3 additions & 0 deletions databricks_cli/workspace/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databricks_cli import issue_deprecation_warning

issue_deprecation_warning()
Loading