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

refactor version checks for pandas, pyarrow #769

Closed
tswast opened this issue Jul 14, 2021 · 2 comments · Fixed by #1711
Closed

refactor version checks for pandas, pyarrow #769

tswast opened this issue Jul 14, 2021 · 2 comments · Fixed by #1711
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. type: process A process-related concern. May include testing, release, or the like.

Comments

@tswast
Copy link
Contributor

tswast commented Jul 14, 2021

We're using pkg_resources.parse_version from setuptools, which is just a thin wrapper over packaging.

Also, we have some version comparisons for features. I think it'd be cleaner to implement these as properties like we do in BQStorageVersions that I propose adding in #748

import packaging.version


_MIN_BQ_STORAGE_VERSION = packaging.version.Version("2.0.0")
_BQ_STORAGE_OPTIONAL_READ_SESSION_VERSION = packaging.version.Version("2.6.0")


class BQStorageVersions:
    def __init__(self):
        self._installed_version = None

    @property
    def installed_version(
        self,
    ) -> Union[packaging.version.LegacyVersion, packaging.version.Version]:
        if self._installed_version is None:
            from google.cloud import bigquery_storage

            self._installed_version = packaging.version.parse(
                getattr(bigquery_storage, "__version__", "legacy")
            )

        return self._installed_version

    @property
    def is_read_session_optional(self) -> bool:
        return self.installed_version >= _BQ_STORAGE_OPTIONAL_READ_SESSION_VERSION

    def verify_version(self):
        """Verify that a recent enough version of BigQuery Storage extra is installed.

        The function assumes that google-cloud-bigquery-storage extra is installed, and
        should thus be used in places where this assumption holds.

        Because `pip` can install an outdated version of this extra despite the constraints
        in setup.py, the the calling code can use this helper to verify the version
        compatibility at runtime.

        Raises:
            LegacyBigQueryStorageError: If google-cloud-bigquery-storage is outdated.
        """
        if self.installed_version < _MIN_BQ_STORAGE_VERSION:
            msg = (
                "Dependency google-cloud-bigquery-storage is outdated, please upgrade "
                f"it to version >= 2.0.0 (version found: {self.installed_version})."
            )
            raise LegacyBigQueryStorageError(msg)


BQ_STORAGE_VERSIONS = BQStorageVersions()
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Jul 14, 2021
@tswast tswast added the type: process A process-related concern. May include testing, release, or the like. label Jul 14, 2021
@plamut
Copy link
Contributor

plamut commented Jul 15, 2021

I support this.

As a bonus, this will make it easier to break the dependency on setuptools if we choose to switch to a different build system at some point.

@tswast
Copy link
Contributor Author

tswast commented Nov 6, 2023

We don't have any version checks for google-cloud-core as of #1487

@tswast tswast changed the title refactor version checks for pandas, pyarrow, google-cloud-core refactor version checks for pandas, pyarrow, ~google-cloud-core~ Nov 6, 2023
@tswast tswast changed the title refactor version checks for pandas, pyarrow, ~google-cloud-core~ refactor version checks for pandas, pyarrow Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. type: process A process-related concern. May include testing, release, or the like.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants