Skip to content

Commit 543056a

Browse files
authored
split redis into extra (#36772)
* split redis into extra * guard missing imports * yapf * Get coverage tasks
1 parent 876cda3 commit 543056a

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

sdks/python/apache_beam/io/requestresponse.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from typing import TypeVar
3636
from typing import Union
3737

38-
import redis
3938
from google.api_core.exceptions import TooManyRequests
4039

4140
import apache_beam as beam
@@ -46,6 +45,11 @@
4645
from apache_beam.transforms.util import BatchElements
4746
from apache_beam.utils import retry
4847

48+
try:
49+
import redis
50+
except ImportError:
51+
redis = None
52+
4953
RequestT = TypeVar('RequestT')
5054
ResponseT = TypeVar('ResponseT')
5155

@@ -689,6 +693,11 @@ def __init__(
689693
self._kwargs = kwargs if kwargs else {}
690694
self._source_caller = None
691695

696+
if redis is None:
697+
raise ImportError(
698+
'Failed to import redis. You can ensure it is '
699+
'installed by installing the redis beam extra')
700+
692701
def get_read(self):
693702
"""get_read returns a PTransform for reading from the cache."""
694703
ensure_coders_exist(self._request_coder)

sdks/python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ def get_portability_package_data():
402402
'protobuf>=3.20.3,<7.0.0.dev0,!=4.0.*,!=4.21.*,!=4.22.0,!=4.23.*,!=4.24.*', # pylint: disable=line-too-long
403403
'python-dateutil>=2.8.0,<3',
404404
'pytz>=2018.3',
405-
'redis>=5.0.0,<6',
406405
'requests>=2.32.4,<3.0.0',
407406
'sortedcontainers>=2.4.0',
408407
'typing-extensions>=3.7.0',
@@ -588,6 +587,7 @@ def get_portability_package_data():
588587
'torch==2.8.0+cpu',
589588
'transformers>=4.28.0,<4.56.0'
590589
],
590+
'redis': ['redis>=5.0.0,<6'],
591591
'tft': [
592592
'tensorflow_transform>=1.14.0,<1.15.0'
593593
# tensorflow-transform requires dill, but doesn't set dill as a

sdks/python/tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pip_pre = True
3333
# allow apps that support color to use it.
3434
passenv=TERM,CLOUDSDK_CONFIG,DOCKER_*,TESTCONTAINERS_*,TC_*,ALLOYDB_PASSWORD
3535
# Set [] options for pip installation of apache-beam tarball.
36-
extras = test,dataframe,tfrecord,yaml
36+
extras = test,dataframe,redis,tfrecord,yaml
3737
# Don't warn that these commands aren't installed.
3838
allowlist_externals =
3939
false
@@ -97,7 +97,7 @@ install_command = {envbindir}/python.exe {envbindir}/pip.exe install --retries 1
9797
list_dependencies_command = {envbindir}/python.exe {envbindir}/pip.exe freeze
9898

9999
[testenv:py{310,311,312,313}-cloud]
100-
; extras = test,gcp,interactive,dataframe,aws,azure
100+
; extras = test,gcp,interactive,dataframe,aws,azure,redis
101101
extras = test,gcp,interactive,dataframe,aws,azure
102102
commands =
103103
python apache_beam/examples/complete/autocomplete_test.py
@@ -173,7 +173,7 @@ setenv =
173173
TC_SLEEP_TIME = {env:TC_SLEEP_TIME:1}
174174

175175
# NOTE: we could add ml_test to increase the collected code coverage metrics, but it would make the suite slower.
176-
extras = test,gcp,interactive,dataframe,aws
176+
extras = test,gcp,interactive,dataframe,aws,redis
177177
commands =
178178
bash {toxinidir}/scripts/run_pytest.sh {envname} "{posargs}" "--cov-report=xml --cov=. --cov-append"
179179

0 commit comments

Comments
 (0)