Skip to content

refactor version checks for pandas, pyarrow #769

@tswast

Description

@tswast

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()

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.type: processA process-related concern. May include testing, release, or the like.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions