Skip to content

Commit 0cf1f10

Browse files
committed
Update dependencies, eliminating warnings
1 parent c4d3625 commit 0cf1f10

File tree

8 files changed

+41
-32
lines changed

8 files changed

+41
-32
lines changed

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
arrow==1.3.0
22
boto3==1.34.35
33
deprecation==2.1.0
4-
gemd==2.1.8
4+
gemd==2.1.9
55
pyjwt==2.8.0
6-
requests==2.32.0
6+
pytz==2024.1; python_version < "3.9"
7+
requests==2.32.2
78
tqdm==4.66.3
89

910
# boto3 (through botocore) depends on urllib3. Version 1.34.35 requires

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,22 @@
2222
package_dir={'': 'src'},
2323
packages=find_packages(where='src'),
2424
install_requires=[
25-
"requests>=2.31.0,<3",
25+
"requests>=2.32.2,<3",
2626
"pyjwt>=2,<3",
2727
"arrow>=1.0.0,<2",
28-
"gemd>=2.1.8,<3",
28+
"gemd>=2.1.9,<3",
2929
"boto3>=1.34.35,<2",
3030
"deprecation>=2.1.0,<3",
3131
"urllib3>=1.26.18,<3",
3232
"tqdm>=4.27.0,<5",
33-
"pint>=0.21,<0.24"
33+
"pytz>=2024.1; python_version<'3.9'",
3434
],
3535
extras_require={
3636
"tests": [
3737
"factory-boy>=3.3.0,<4",
3838
"mock>=5.1.0,<6",
3939
"pandas>=2.0.3,<3",
4040
"pytest>=8.0.0,<9",
41-
"pytz>=2024.1",
4241
"requests-mock>=1.11.0,<2",
4342
]
4443
},

src/citrine/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.5.0"
1+
__version__ = "3.5.1"

src/citrine/_session.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import platform
22
from datetime import datetime, timedelta
3+
try: # Only available starting Python 3.9
4+
from datetime import UTC
5+
except ImportError: # pragma: no cover
6+
from pytz import utc as UTC
37
from json.decoder import JSONDecodeError
48
from logging import getLogger
59
from os import environ
@@ -53,7 +57,7 @@ def __init__(self,
5357
self.authority = ':'.join(([host] if host else []) + ([port] if port else []))
5458
self.refresh_token: str = refresh_token
5559
self.access_token: Optional[str] = None
56-
self.access_token_expiration: datetime = datetime.utcnow()
60+
self.access_token_expiration: datetime = datetime.now(UTC)
5761

5862
agent = "{}/{} python-requests/{} citrine-python/{}".format(
5963
platform.python_implementation(),
@@ -106,7 +110,7 @@ def _versioned_base_url(self, version: str = 'v1'):
106110
))
107111

108112
def _is_access_token_expired(self):
109-
return self.access_token_expiration - EXPIRATION_BUFFER_MILLIS <= datetime.utcnow()
113+
return self.access_token_expiration - EXPIRATION_BUFFER_MILLIS <= datetime.now(UTC)
110114

111115
def _refresh_access_token(self) -> None:
112116
"""Optionally refresh our access token (if the previous one is about to expire)."""
@@ -118,10 +122,13 @@ def _refresh_access_token(self) -> None:
118122
if response.status_code != 200:
119123
raise UnauthorizedRefreshToken()
120124
self.access_token = response.json()['access_token']
121-
self.access_token_expiration = datetime.utcfromtimestamp(
122-
jwt.decode(self.access_token,
123-
options={"verify_signature": False},
124-
algorithms=["HS256"])['exp']
125+
self.access_token_expiration = datetime.fromtimestamp(
126+
jwt.decode(
127+
self.access_token,
128+
options={"verify_signature": False},
129+
algorithms=["HS256"]
130+
)['exp'],
131+
UTC
125132
)
126133

127134
# Explicitly set an updated 'auth', so as to not rely on implicit cookie handling.

src/citrine/resources/data_concepts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ def _path_template(self):
248248
@property
249249
def _dataset_agnostic_path_template(self):
250250
if self.project_id is None:
251-
return f'teams/{self.team_id}/{self._collection_key.replace("_","-")}'
251+
return f'teams/{self.team_id}/{self._collection_key.replace("_", "-")}'
252252
else:
253-
return f'projects/{self.project_id}/{self._collection_key.replace("_","-")}'
253+
return f'projects/{self.project_id}/{self._collection_key.replace("_", "-")}'
254254

255255
def build(self, data: dict) -> ResourceType:
256256
"""

test_requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ flake8-docstrings==1.7.0
55
mock==5.1.0
66
pytest==8.0.0
77
pytest-cov==4.1.0
8-
pytz==2024.1
98
requests-mock==1.11.0
109

1110
# faker is a dependency of factory-boy, but factory-boy sets a very low floor

tests/test_citrine.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import platform
22
from datetime import datetime
3+
try:
4+
from datetime import UTC
5+
except ImportError: # Only available starting Python 3.9
6+
from pytz import utc as UTC
37

48
import jwt
59
import pytest
6-
import pytz
710
import requests_mock
811

912
from citrine import Citrine
@@ -17,7 +20,7 @@ def refresh_token(expiration: datetime = None) -> dict:
1720
return {'access_token': token}
1821

1922

20-
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=pytz.utc))
23+
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=UTC))
2124

2225

2326
def test_citrine_creation():

tests/test_session.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import json
2-
31
import jwt
42
import pytest
5-
import unittest
63

74
from citrine.exceptions import (
85
BadRequest,
9-
CitrineException,
106
Conflict,
117
NonRetryableException,
128
WorkflowNotReadyException,
139
RetryableException)
1410

1511
from datetime import datetime, timedelta
16-
import pytz
12+
try:
13+
from datetime import UTC
14+
except ImportError: # Only available starting Python 3.9
15+
from pytz import utc as UTC
16+
1717
import mock
1818
import requests
1919
import requests_mock
@@ -32,7 +32,7 @@ def refresh_token(expiration: datetime = None) -> dict:
3232

3333
@pytest.fixture
3434
def session():
35-
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=pytz.utc))
35+
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=UTC))
3636
with requests_mock.Mocker() as m:
3737
m.post('http://citrine-testing.fake/api/v1/tokens/refresh', json=token_refresh_response)
3838
session = Session(
@@ -43,13 +43,13 @@ def session():
4343
# Default behavior is to *not* require a refresh - those tests can clear this out
4444
# As rule of thumb, we should be using freezegun or similar to never rely on the system clock
4545
# for these scenarios, but I thought this is light enough to postpone that for the time being
46-
session.access_token_expiration = datetime.utcnow() + timedelta(minutes=3)
46+
session.access_token_expiration = datetime.now(UTC) + timedelta(minutes=3)
4747

4848
return session
4949

5050

5151
def test_session_signature(monkeypatch):
52-
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=pytz.utc))
52+
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=UTC))
5353
with requests_mock.Mocker() as m:
5454
m.post('ftp://citrine-testing.fake:8080/api/v1/tokens/refresh', json=token_refresh_response)
5555

@@ -77,8 +77,8 @@ def test_session_signature(monkeypatch):
7777

7878

7979
def test_get_refreshes_token(session: Session):
80-
session.access_token_expiration = datetime.utcnow() - timedelta(minutes=1)
81-
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=pytz.utc))
80+
session.access_token_expiration = datetime.now(UTC) - timedelta(minutes=1)
81+
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=UTC))
8282

8383
with requests_mock.Mocker() as m:
8484
m.post('http://citrine-testing.fake/api/v1/tokens/refresh', json=token_refresh_response)
@@ -89,11 +89,11 @@ def test_get_refreshes_token(session: Session):
8989
resp = session.get_resource('/foo')
9090

9191
assert {'foo': 'bar'} == resp
92-
assert datetime(2019, 3, 14) == session.access_token_expiration
92+
assert datetime(2019, 3, 14, tzinfo=UTC) == session.access_token_expiration
9393

9494

9595
def test_get_refresh_token_failure(session: Session):
96-
session.access_token_expiration = datetime.utcnow() - timedelta(minutes=1)
96+
session.access_token_expiration = datetime.now(UTC) - timedelta(minutes=1)
9797

9898
with requests_mock.Mocker() as m:
9999
m.post('http://citrine-testing.fake/api/v1/tokens/refresh', status_code=401)
@@ -197,7 +197,7 @@ def test_connection_error(session: Session):
197197

198198

199199
def test_post_refreshes_token_when_denied(session: Session):
200-
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=pytz.utc))
200+
token_refresh_response = refresh_token(datetime(2019, 3, 14, tzinfo=UTC))
201201

202202
with requests_mock.Mocker() as m:
203203
m.post('http://citrine-testing.fake/api/v1/tokens/refresh', json=token_refresh_response)
@@ -209,7 +209,7 @@ def test_post_refreshes_token_when_denied(session: Session):
209209
resp = session.post_resource('/foo', json={'data': 'hi'})
210210

211211
assert {'foo': 'bar'} == resp
212-
assert datetime(2019, 3, 14) == session.access_token_expiration
212+
assert datetime(2019, 3, 14, tzinfo=UTC) == session.access_token_expiration
213213

214214

215215
# this test exists to provide 100% coverage for the legacy 401 status on Unauthorized responses

0 commit comments

Comments
 (0)