Skip to content

Commit a30f004

Browse files
authored
fix!: drop support for Python 2.7 / 3.5 (googleapis#212)
Drop 'six' module Drop 'u"' prefixes for text Remove other Python 2.7 workarounds Drop use of 'pytz' Dxpand range to allow 'google-auth' 2.x versions Remove 'general_helpers.wraps': except for a backward-compatibility import, 'functools.wraps' does everything wee need on Python >= 3.6. Remove 'packaging' dependency Release-As: 2.0.0b1 Closes googleapis#74. Closes googleapis#215.
1 parent ff6ef1b commit a30f004

35 files changed

+191
-349
lines changed

CONTRIBUTING.rst

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.. Generated by synthtool. DO NOT EDIT!
21
############
32
Contributing
43
############
@@ -22,7 +21,7 @@ In order to add a feature:
2221
documentation.
2322

2423
- The feature must work fully on the following CPython versions:
25-
2.7, 3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows.
24+
3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows.
2625

2726
- The feature must not add unnecessary dependencies (where
2827
"unnecessary" is of course subjective, but new dependencies should
@@ -77,8 +76,8 @@ We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.
7776

7877
.. note::
7978

80-
The unit tests and system tests are described in the
81-
``noxfile.py`` files in each directory.
79+
The unit tests tests are described in the ``noxfile.py`` files
80+
in each directory.
8281

8382
.. nox: https://pypi.org/project/nox/
8483
@@ -133,29 +132,6 @@ Exceptions to PEP8:
133132
"Function-Under-Test"), which is PEP8-incompliant, but more readable.
134133
Some also use a local variable, ``MUT`` (short for "Module-Under-Test").
135134

136-
********************
137-
Running System Tests
138-
********************
139-
140-
- To run system tests, you can execute::
141-
142-
# Run all system tests
143-
$ nox -s system
144-
145-
# Run a single system test
146-
$ nox -s system-3.8 -- -k <name of test>
147-
148-
149-
.. note::
150-
151-
System tests are only configured to run under Python 2.7 and 3.8.
152-
For expediency, we do not run them in older versions of Python 3.
153-
154-
This alone will not run the tests. You'll need to change some local
155-
auth settings and change some configuration in your project to
156-
run all the tests.
157-
158-
- System tests will be run against an actual project. You should use local credentials from gcloud when possible. See `Best practices for application authentication <https://cloud.google.com/docs/authentication/best-practices-applications#local_development_and_testing_with_the>`__. Some tests require a service account. For those tests see `Authenticating as a service account <https://cloud.google.com/docs/authentication/production>`__.
159135

160136
*************
161137
Test Coverage
@@ -221,13 +197,11 @@ Supported Python Versions
221197

222198
We support:
223199

224-
- `Python 2.7`_
225200
- `Python 3.6`_
226201
- `Python 3.7`_
227202
- `Python 3.8`_
228203
- `Python 3.9`_
229204

230-
.. _Python 2.7: https://docs.python.org/2.7/
231205
.. _Python 3.6: https://docs.python.org/3.6/
232206
.. _Python 3.7: https://docs.python.org/3.7/
233207
.. _Python 3.8: https://docs.python.org/3.8/
@@ -239,7 +213,7 @@ Supported versions can be found in our ``noxfile.py`` `config`_.
239213
.. _config: https://github.com/googleapis/python-api-core/blob/master/noxfile.py
240214

241215

242-
We also explicitly decided to support Python 3 beginning with version 2.7.
216+
We also explicitly decided to support Python 3 beginning with version 3.6.
243217
Reasons for this include:
244218

245219
- Encouraging use of newest versions of Python 3

README.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Core Library for Google Client Libraries
22
========================================
33

4-
|pypi| |versions|
4+
|pypi| |versions|
55

66
This library is not meant to stand-alone. Instead it defines
77
common helpers used by all Google API clients. For more information, see the
@@ -16,8 +16,13 @@ common helpers used by all Google API clients. For more information, see the
1616

1717
Supported Python Versions
1818
-------------------------
19-
Python >= 3.5
19+
Python >= 3.6
2020

21-
Deprecated Python Versions
22-
--------------------------
23-
Python == 2.7. Python 2.7 support will be removed on January 1, 2020.
21+
22+
Unsupported Python Versions
23+
---------------------------
24+
25+
Python == 2.7, Python == 3.5.
26+
27+
The last version of this library compatible with Python 2.7 and 3.5 is
28+
`google-api_core==1.31.1`.

docs/auth.rst

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,6 @@ After creation, you can pass it directly to a :class:`Client <google.cloud.clien
103103

104104
.. _google-auth-guide: https://googleapis.dev/python/google-auth/latest/user-guide.html#service-account-private-key-files
105105

106-
107-
Google App Engine Standard First Generation Environment
108-
-------------------------------------------------------
109-
110-
These credentials are used only in the legacy Python 2.7
111-
`First Generation Standard Environment`_. All other App Engine
112-
runtimes use Compute Engine credentials.
113-
114-
.. _First Generation Standard Environment: https://cloud.google.com/appengine/docs/standard/runtimes
115-
116-
To create
117-
:class:`credentials <google.auth.app_engine.Credentials>`
118-
just for Google App Engine:
119-
120-
.. code:: python
121-
122-
from google.auth import app_engine
123-
credentials = app_engine.Credentials()
124-
125106
Google Compute Engine Environment
126107
---------------------------------
127108

google/api_core/bidi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
import collections
1818
import datetime
1919
import logging
20+
import queue as queue_module
2021
import threading
2122
import time
2223

23-
from six.moves import queue
24-
2524
from google.api_core import exceptions
2625

2726
_LOGGER = logging.getLogger(__name__)
@@ -71,7 +70,7 @@ class _RequestQueueGenerator(object):
7170
CPU consumed by spinning is pretty minuscule.
7271
7372
Args:
74-
queue (queue.Queue): The request queue.
73+
queue (queue_module.Queue): The request queue.
7574
period (float): The number of seconds to wait for items from the queue
7675
before checking if the RPC is cancelled. In practice, this
7776
determines the maximum amount of time the request consumption
@@ -108,7 +107,7 @@ def __iter__(self):
108107
while True:
109108
try:
110109
item = self._queue.get(timeout=self._period)
111-
except queue.Empty:
110+
except queue_module.Empty:
112111
if not self._is_active():
113112
_LOGGER.debug(
114113
"Empty queue and inactive call, exiting request " "generator."
@@ -247,7 +246,7 @@ def __init__(self, start_rpc, initial_request=None, metadata=None):
247246
self._start_rpc = start_rpc
248247
self._initial_request = initial_request
249248
self._rpc_metadata = metadata
250-
self._request_queue = queue.Queue()
249+
self._request_queue = queue_module.Queue()
251250
self._request_generator = None
252251
self._is_active = False
253252
self._callbacks = []
@@ -645,6 +644,7 @@ def _thread_main(self, ready):
645644
# Keeping the lock throughout avoids that.
646645
# In the future, we could use `Condition.wait_for` if we drop
647646
# Python 2.7.
647+
# See: https://github.com/googleapis/python-api-core/issues/211
648648
with self._wake:
649649
while self._paused:
650650
_LOGGER.debug("paused, waiting for waking.")

google/api_core/client_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ClientInfo(object):
4242
4343
Args:
4444
python_version (str): The Python interpreter version, for example,
45-
``'2.7.13'``.
45+
``'3.9.6'``.
4646
grpc_version (Optional[str]): The gRPC library version.
4747
api_core_version (str): The google-api-core library version.
4848
gapic_version (Optional[str]): The sversion of gapic-generated client

google/api_core/client_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def from_dict(options):
101101
"""Construct a client options object from a mapping object.
102102
103103
Args:
104-
options (six.moves.collections_abc.Mapping): A mapping object with client options.
104+
options (collections.abc.Mapping): A mapping object with client options.
105105
See the docstring for ClientOptions for details on valid arguments.
106106
"""
107107

google/api_core/datetime_helpers.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import datetime
1919
import re
2020

21-
import pytz
22-
2321
from google.protobuf import timestamp_pb2
2422

2523

26-
_UTC_EPOCH = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc)
24+
_UTC_EPOCH = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
2725
_RFC3339_MICROS = "%Y-%m-%dT%H:%M:%S.%fZ"
2826
_RFC3339_NO_FRACTION = "%Y-%m-%dT%H:%M:%S"
2927
# datetime.strptime cannot handle nanosecond precision: parse w/ regex
@@ -83,9 +81,9 @@ def to_microseconds(value):
8381
int: Microseconds since the unix epoch.
8482
"""
8583
if not value.tzinfo:
86-
value = value.replace(tzinfo=pytz.utc)
84+
value = value.replace(tzinfo=datetime.timezone.utc)
8785
# Regardless of what timezone is on the value, convert it to UTC.
88-
value = value.astimezone(pytz.utc)
86+
value = value.astimezone(datetime.timezone.utc)
8987
# Convert the datetime to a microsecond timestamp.
9088
return int(calendar.timegm(value.timetuple()) * 1e6) + value.microsecond
9189

@@ -156,7 +154,7 @@ def from_rfc3339(value):
156154
nanos = int(fraction) * (10 ** scale)
157155
micros = nanos // 1000
158156

159-
return bare_seconds.replace(microsecond=micros, tzinfo=pytz.utc)
157+
return bare_seconds.replace(microsecond=micros, tzinfo=datetime.timezone.utc)
160158

161159

162160
from_rfc3339_nanos = from_rfc3339 # from_rfc3339_nanos method was deprecated.
@@ -256,7 +254,7 @@ def from_rfc3339(cls, stamp):
256254
bare.minute,
257255
bare.second,
258256
nanosecond=nanos,
259-
tzinfo=pytz.UTC,
257+
tzinfo=datetime.timezone.utc,
260258
)
261259

262260
def timestamp_pb(self):
@@ -265,7 +263,11 @@ def timestamp_pb(self):
265263
Returns:
266264
(:class:`~google.protobuf.timestamp_pb2.Timestamp`): Timestamp message
267265
"""
268-
inst = self if self.tzinfo is not None else self.replace(tzinfo=pytz.UTC)
266+
inst = (
267+
self
268+
if self.tzinfo is not None
269+
else self.replace(tzinfo=datetime.timezone.utc)
270+
)
269271
delta = inst - _UTC_EPOCH
270272
seconds = int(delta.total_seconds())
271273
nanos = self._nanosecond or self.microsecond * 1000
@@ -292,5 +294,5 @@ def from_timestamp_pb(cls, stamp):
292294
bare.minute,
293295
bare.second,
294296
nanosecond=stamp.nanos,
295-
tzinfo=pytz.UTC,
297+
tzinfo=datetime.timezone.utc,
296298
)

0 commit comments

Comments
 (0)