From 5f5c818685168dab6f0aae6c623a386f110157bd Mon Sep 17 00:00:00 2001 From: Serge Smertin <259697+nfx@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:40:42 +0100 Subject: [PATCH] Added unreleased version fallback (#9) --- .github/workflows/push.yml | 3 --- src/databricks/labs/blueprint/wheels.py | 17 ++++++++--------- tests/unit/test_wheels.py | 4 ++++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ecd461e..0b54d8f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -25,9 +25,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Unshallow - run: git fetch --prune --unshallow - - name: Install Python uses: actions/setup-python@v4 with: diff --git a/src/databricks/labs/blueprint/wheels.py b/src/databricks/labs/blueprint/wheels.py index 4ddd349..a29fd64 100644 --- a/src/databricks/labs/blueprint/wheels.py +++ b/src/databricks/labs/blueprint/wheels.py @@ -40,7 +40,6 @@ def __init__( project_root_finder = find_project_root self._ws = ws self._install_state = install_state - self._this_file = Path(__file__) self._github_org = github_org self._verbose = verbose self._version_file_name = version_file_name @@ -70,14 +69,14 @@ def version(self): try: self.__version = self._pep0440_version_from_git() return self.__version - except Exception as err: - product = self._install_state.product() - raise OSError( - f"Cannot determine unreleased version. Please report this error " - f"message that you see on https://github.com/{self._github_org}/{product}/issues/new. " - f"Meanwhile, download, unpack, and install the latest released version from " - f"https://github.com/{self._github_org}/{product}/releases. Original error is: {err!s}" - ) from None + except subprocess.CalledProcessError as err: + logger.error( + "Cannot determine unreleased version. This can be fixed by adding " + " `git fetch --prune --unshallow` to your CI configuration.", + exc_info=err, + ) + self.__version = self.released_version() + return self.__version @staticmethod def _pep0440_version_from_git(): diff --git a/tests/unit/test_wheels.py b/tests/unit/test_wheels.py index f9e1e00..7268b0a 100644 --- a/tests/unit/test_wheels.py +++ b/tests/unit/test_wheels.py @@ -1,10 +1,12 @@ import os from unittest.mock import create_autospec +import pytest from databricks.sdk import WorkspaceClient from databricks.sdk.service.workspace import ImportFormat from databricks.labs.blueprint.__about__ import __version__ +from databricks.labs.blueprint.entrypoint import is_in_debug from databricks.labs.blueprint.installer import InstallState from databricks.labs.blueprint.wheels import Wheels @@ -36,6 +38,8 @@ def test_build_and_upload_wheel(): def test_unreleased_version(tmp_path): + if not is_in_debug(): + pytest.skip("fails without `git fetch --prune --unshallow` configured") ws = create_autospec(WorkspaceClient) state = create_autospec(InstallState) state.product.return_value = "blueprint"