Skip to content

Commit f48d422

Browse files
authored
Upgrade to python3.11 (#16)
* Update requirements versions * remove stale circle ci conf * Update Makefile * Remove flexisettings * Add prefix to settings * Update typing * remove mypy_extensions
1 parent d0ca815 commit f48d422

18 files changed

+124
-241
lines changed

.circleci/config.yml

-60
This file was deleted.

Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ tag:
1111
git push --tags
1212

1313
mypy:
14-
mypy --py2 --ignore-missing-imports popget
14+
mypy --ignore-missing-imports popget
1515

1616
pytest:
1717
py.test -v -s tests/
1818

19-
pytest-pdb:
20-
py.test -v -s --ipdb tests/
21-
2219
test:
2320
$(MAKE) mypy
2421
$(MAKE) pytest

README.rst

+6-33
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,14 @@ as your existing Django ``settings.py``.
3131
To bootstrap this, there are a couple of env vars to control how config
3232
is loaded:
3333

34-
- ``POPGET_APP_CONFIG``
35-
should be an import path to a python module, for example:
36-
``POPGET_APP_CONFIG=django.conf.settings``
37-
- ``POPGET_CONFIG_NAMESPACE``
38-
Sets the prefix used for loading further config values from env and
39-
config file. Defaults to ``POPGET``.
40-
41-
See source of ``popget/conf/defaults.py`` for more details.
34+
See source of ``popget/conf/settings.py`` for more details.
4235

4336
Some useful config keys (all of which are prefixed with
4437
``POPGET_`` by default):
4538

46-
- ``<namespace>_CLIENT_DEFAULT_USER_AGENT`` when making requests, popget will use this
39+
- ``POPGET_CLIENT_DEFAULT_USER_AGENT`` when making requests, popget will use this
4740
string as the user agent.
48-
- ``<namespace>_CLIENT_TIMEOUT`` if ``None`` then no timeout, otherwise this timeout
41+
- ``POPGET_CLIENT_TIMEOUT`` if ``None`` then no timeout, otherwise this timeout
4942
(in seconds) will be applied to all requests. Requests which timeout will
5043
return a 504 response, which will be raised as an ``HTTPError``.
5144

@@ -313,32 +306,12 @@ Compatibility
313306
This project is tested against:
314307

315308
=========== ===
316-
Python 2.7 *
317-
Python 3.7 *
309+
Python 3.11 *
318310
=========== ===
319311

320312
Running the tests
321313
-----------------
322314

323-
CircleCI
324-
~~~~~~~~
325-
326-
| The easiest way to test the full version matrix is to install the
327-
CircleCI command line app:
328-
| https://circleci.com/docs/2.0/local-jobs/
329-
| (requires Docker)
330-
331-
The cli does not support 'workflows' at the moment so you have to run
332-
the two Python version jobs separately:
333-
334-
.. code:: bash
335-
336-
circleci build --job python-2.7
337-
338-
.. code:: bash
339-
340-
circleci build --job python-3.7
341-
342315
py.test (single python version)
343316
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
344317

@@ -349,6 +322,6 @@ Decide which Python version you want to test and create a virtualenv:
349322

350323
.. code:: bash
351324
352-
pyenv virtualenv 3.7.4 popget
325+
python -m virtualenv .venv -p python3.11
353326
pip install -r requirements-test.txt
354-
py.test -v -s --ipdb tests/
327+
py.test -v -s tests/

popget/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.8.3'
1+
__version__ = '2.0.0'

popget/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from popget.client import APIClient # noqa
2-
from popget.endpoint import ( # noqa
1+
from popget.client import APIClient
2+
from popget.endpoint import (
33
Arg,
44
BodyType,
55
DeleteEndpoint,

popget/client.py

+28-42
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
from functools import partial
22
from six import add_metaclass
3-
from typing import Any, Callable, Dict, Optional, Set, Tuple, Type, TypeVar, Union # noqa
3+
from typing import Any, Callable, Type
44

5-
from mypy_extensions import Arg, DefaultArg, KwArg
65
import requests
76
from requests.exceptions import Timeout
87

98
from popget.conf import settings
109
from popget.endpoint import APIEndpoint, BodyType, BODY_CONTENT_TYPES, NO_DEFAULT
1110
from popget.errors import MissingRequiredArg
12-
from popget.extratypes import ResponseTypes # noqa
11+
from popget.extratypes import ResponseTypes
1312
from popget.utils import get_base_attr, update_nested
1413

1514

16-
ClientMethod = Callable[
17-
[
18-
Arg(Type['APIClient'], 'cls'),
19-
DefaultArg(Optional[Dict[Any, Any]], '_request_kwargs'),
20-
DefaultArg(Optional[requests.Session], '_session'),
21-
KwArg(object),
22-
],
23-
Union[ResponseTypes, object]
24-
]
25-
26-
27-
def method_factory(endpoint, client_method_name):
28-
# type: (APIEndpoint, str) -> ClientMethod
15+
def method_factory(endpoint: APIEndpoint, client_method_name: str):
2916
"""
3017
Kwargs:
3118
endpoint: the endpoint to generate a callable method for
@@ -36,8 +23,9 @@ def method_factory(endpoint, client_method_name):
3623
In turn the method returns response content, either string or
3724
deserialized JSON data.
3825
"""
39-
def _prepare_request(base_url, _request_kwargs=None, **call_kwargs):
40-
# type: (str, Optional[Dict], **Any) -> Tuple[str, Dict[str, Dict]]
26+
def _prepare_request(
27+
base_url: str, _request_kwargs: dict | None = None, **call_kwargs
28+
) -> tuple[str, dict[str, dict]]:
4129
"""
4230
Kwargs:
4331
base_url: base url of API
@@ -100,12 +88,12 @@ def _prepare_request(base_url, _request_kwargs=None, **call_kwargs):
10088

10189
return url, request_kwargs
10290

103-
def client_method(cls, # type: Type[APIClient]
104-
_request_kwargs=None, # type: Optional[Dict]
105-
_session=None, # type: requests.Session
106-
**call_kwargs
107-
):
108-
# type: (...) -> Union[ResponseTypes, object]
91+
def client_method(
92+
cls,
93+
_request_kwargs: dict | None = None,
94+
_session: requests.Session | None = None,
95+
**call_kwargs
96+
) -> ResponseTypes | object:
10997
"""
11098
Returns:
11199
Response... for non-async clients this will be response content,
@@ -126,17 +114,16 @@ def client_method(cls, # type: Type[APIClient]
126114

127115
class ConfigClass(object):
128116

129-
base_url = None # type: str
130-
session_cls = None # type: Type[requests.Session]
131-
_session = None # type: requests.Session
117+
base_url: str
118+
session_cls: Type[requests.Session]
119+
_session: requests.Session | None = None
132120

133121
def __init__(self, config):
134122
self.base_url = getattr(config, 'base_url', '')
135123
self.session_cls = getattr(config, 'session_cls', requests.Session)
136124

137125
@property
138-
def session(self):
139-
# type: () -> requests.Session
126+
def session(self) -> requests.Session:
140127
if not self._session:
141128
session = self.session_cls()
142129
session.headers['User-Agent'] = settings.CLIENT_DEFAULT_USER_AGENT
@@ -179,8 +166,9 @@ class Config:
179166
config_class = ConfigClass
180167

181168
@staticmethod
182-
def add_methods_for_endpoint(methods, name, endpoint, config):
183-
# type: (Dict[str, classmethod], str, APIEndpoint, Any) -> None
169+
def add_methods_for_endpoint(
170+
methods: dict[str, classmethod], name: str, endpoint: APIEndpoint, config: Any
171+
) -> None:
184172
methods[name] = classmethod(method_factory(endpoint, '_make_request'))
185173

186174
def __new__(cls, name, bases, attrs):
@@ -198,8 +186,7 @@ def __new__(cls, name, bases, attrs):
198186
return type.__new__(cls, name, bases, attrs)
199187

200188

201-
def get_response_body(response):
202-
# type: (requests.Response) -> ResponseTypes
189+
def get_response_body(response: requests.Response) -> ResponseTypes:
203190
"""
204191
Kwargs:
205192
response: from requests lib
@@ -231,12 +218,12 @@ def get_response_body(response):
231218
@add_metaclass(APIClientMetaclass)
232219
class APIClient(object):
233220

234-
_config = None # type: ConfigClass
221+
_config: ConfigClass
235222

236223
@staticmethod
237-
def _request_kwargs(method, url, args, kwargs):
238-
# type: (str, str, Tuple[Any, ...], Dict[str, Any]) -> None
239-
224+
def _request_kwargs(
225+
method: str, url: str, args: tuple[Any, ...], kwargs: dict[str, Any]
226+
) -> None:
240227
if settings.CLIENT_DISABLE_VERIFY_SSL:
241228
kwargs['verify'] = False
242229

@@ -245,9 +232,7 @@ def _request_kwargs(method, url, args, kwargs):
245232
kwargs['timeout'] = settings.CLIENT_TIMEOUT
246233

247234
@staticmethod
248-
def handle(call, request_url):
249-
# type: (Callable[[], requests.Response], str) -> ResponseTypes
250-
235+
def handle(call: Callable[[], requests.Response], request_url: str) -> ResponseTypes:
251236
try:
252237
res = call()
253238
except Timeout as e:
@@ -262,8 +247,9 @@ def handle(call, request_url):
262247
return get_response_body(res)
263248

264249
@classmethod
265-
def _make_request(cls, method, url, session=None, *args, **kwargs):
266-
# type: (str, str, Optional[requests.Session], *Any, **Any) -> ResponseTypes
250+
def _make_request(
251+
cls, method: str, url: str, session: requests.Session | None = None, *args, **kwargs
252+
) -> ResponseTypes:
267253
"""
268254
Don't call this directly. Instead, add APIEndpoint instances to your
269255
APIClient sub-class definition. Accessor methods will be generated by

popget/conf/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
from flexisettings import Settings
2-
3-
4-
settings = Settings('POPGET', 'popget.conf.defaults')

popget/conf/defaults.py

-18
This file was deleted.

popget/conf/settings.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from popget.__about__ import __version__
2+
3+
try:
4+
from django.conf import settings
5+
except ImportError:
6+
settings = None
7+
8+
CLIENT_DEFAULT_USER_AGENT: str = getattr(
9+
settings, 'POPGET_CLIENT_DEFAULT_USER_AGENT', 'popget/{}'.format(__version__)
10+
)
11+
12+
CLIENT_TIMEOUT: float = getattr(settings, 'POPGET_CLIENT_TIMEOUT', 3.0)
13+
14+
CLIENT_DISABLE_VERIFY_SSL: bool = getattr(settings, 'POPGET_CLIENT_DISABLE_VERIFY_SSL', False)

0 commit comments

Comments
 (0)