-
Notifications
You must be signed in to change notification settings - Fork 322
Closed
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.Issues related to the googleapis/python-bigquery API.type: processA process-related concern. May include testing, release, or the like.A process-related concern. May include testing, release, or the like.
Description
We're using pkg_resources.parse_version from setuptools, which is just a thin wrapper over packaging.
- parse_version implementation: https://github.com/pypa/setuptools/blob/a4dbe3457d89cf67ee3aa571fdb149e6eb544e88/pkg_resources/__init__.py#L112
- Our usage: https://github.com/googleapis/python-bigquery/search?q=pkg_resources
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.Issues related to the googleapis/python-bigquery API.type: processA process-related concern. May include testing, release, or the like.A process-related concern. May include testing, release, or the like.