-
Notifications
You must be signed in to change notification settings - Fork 309
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: omit read_session
with latest google-cloud-bigquery-storage
#748
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b80f727
refactor: omit `read_session` with latest google-cloud-bigquery-storage
tswast 920c973
Merge remote-tracking branch 'upstream/master' into issue742-read_ses…
tswast c153afb
optimize _verify_bq_storage_version
tswast bcfa3e0
fix failing tests due to optimization
tswast d4211b2
fix unit tests
tswast ed6cff4
Merge remote-tracking branch 'upstream/master' into issue742-read_ses…
tswast 6c18969
create BQStorageVersions class for version comparisons
tswast 237cdd1
add type annotations
tswast 0d49387
allow legacy versions
tswast 2bb9e4c
Merge remote-tracking branch 'upstream/master' into issue742-read_ses…
tswast c50b08c
fix coverage
tswast 44ef80b
fix coverage
tswast 9d161c5
add tests for version helpers
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,7 +26,7 @@ | |||||
from google.cloud._helpers import _RFC3339_MICROS | ||||||
from google.cloud._helpers import _RFC3339_NO_FRACTION | ||||||
from google.cloud._helpers import _to_bytes | ||||||
import pkg_resources | ||||||
import packaging.version | ||||||
|
||||||
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError | ||||||
|
||||||
|
@@ -41,31 +41,51 @@ | |||||
re.VERBOSE, | ||||||
) | ||||||
|
||||||
_MIN_BQ_STORAGE_VERSION = pkg_resources.parse_version("2.0.0") | ||||||
_MIN_BQ_STORAGE_VERSION = packaging.version.Version("2.0.0") | ||||||
_BQ_STORAGE_OPTIONAL_READ_SESSION_VERSION = packaging.version.Version("2.6.0") | ||||||
|
||||||
|
||||||
def _verify_bq_storage_version(): | ||||||
"""Verify that a recent enough version of BigQuery Storage extra is installed. | ||||||
class BQStorageVersions: | ||||||
def __init__(self): | ||||||
self._installed_version = None | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This version checker, sir, is classy (pun intended). Well done! |
||||||
|
||||||
The function assumes that google-cloud-bigquery-storage extra is installed, and | ||||||
should thus be used in places where this assumption holds. | ||||||
@property | ||||||
def installed_version(self) -> packaging.version.Version: | ||||||
if self._installed_version is None: | ||||||
from google.cloud import bigquery_storage | ||||||
|
||||||
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. | ||||||
""" | ||||||
from google.cloud import bigquery_storage | ||||||
self._installed_version = packaging.version.Version( | ||||||
getattr(bigquery_storage, "__version__", "legacy") | ||||||
) | ||||||
|
||||||
installed_version = pkg_resources.parse_version( | ||||||
getattr(bigquery_storage, "__version__", "legacy") | ||||||
) | ||||||
return self._installed_version | ||||||
|
||||||
if 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: {installed_version})." | ||||||
) | ||||||
raise LegacyBigQueryStorageError(msg) | ||||||
@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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I now noticed you copied my typo, let's remove it.
Suggested change
|
||||||
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() | ||||||
|
||||||
|
||||||
def _not_null(value, field): | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to add type annotations, but it turns out
pkg_resources
is just a thin wrapper aroundpackaging
.https://github.com/pypa/setuptools/blob/a4dbe3457d89cf67ee3aa571fdb149e6eb544e88/pkg_resources/__init__.py/#L112