Skip to content

Commit 46f146d

Browse files
authored
Merge pull request #117 from cuenca-mx/update-deps
Update deps
2 parents a2eb83c + 0fd54df commit 46f146d

File tree

19 files changed

+167
-177
lines changed

19 files changed

+167
-177
lines changed

.github/workflows/auto_merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
auto-merge:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v4
1111
- uses: ahmadnassri/action-dependabot-auto-merge@v2
1212
with:
1313
github-token: ${{ secrets.DEPENDABOT_AUTOMERGE }}

.github/workflows/docs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@master
12-
- name: Set up Python 3.8
13-
uses: actions/setup-python@v2.2.2
11+
- uses: actions/checkout@v4
12+
- name: Set up Python 3.13
13+
uses: actions/setup-python@v5
1414
with:
15-
python-version: 3.8
15+
python-version: 3.13
1616
- name: Install dependencies
1717
run: make install-test
1818
- name: Install mkdocs

.github/workflows/release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: release
22

3-
on: push
3+
on:
4+
release:
5+
types: [published]
46

57
jobs:
68
publish-pypi:
@@ -16,8 +18,7 @@ jobs:
1618
- name: Generating distribution archives
1719
run: python setup.py sdist bdist_wheel
1820
- name: Publish distribution 📦 to PyPI
19-
if: startsWith(github.event.ref, 'refs/tags')
20-
uses: pypa/gh-action-pypi-publish@master
21+
uses: pypa/gh-action-pypi-publish@release/v1
2122
with:
2223
user: __token__
2324
password: ${{ secrets.pypi_password }}

.github/workflows/test.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name: test
22

3-
on: [push, pull_request]
3+
on: push
44

55
jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v4
1010
- name: Set up Python
11-
uses: actions/setup-python@v2.2.2
11+
uses: actions/setup-python@v5
1212
with:
13-
python-version: 3.8
13+
python-version: 3.13
1414
- name: Install dependencies
1515
run: make install-test
1616
- name: Lint
@@ -20,11 +20,11 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
python-version: [3.7, 3.8, 3.9, '3.10']
23+
python-version: ['3.10', '3.11', '3.12', '3.13']
2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v4
2626
- name: Set up Python ${{ matrix.python-version }}
27-
uses: actions/setup-python@v2.2.2
27+
uses: actions/setup-python@v5
2828
with:
2929
python-version: ${{ matrix.python-version }}
3030
- name: Install dependencies
@@ -35,18 +35,19 @@ jobs:
3535
coverage:
3636
runs-on: ubuntu-latest
3737
steps:
38-
- uses: actions/checkout@master
38+
- uses: actions/checkout@v4
3939
- name: Setup Python
40-
uses: actions/setup-python@v2.2.2
40+
uses: actions/setup-python@v5
4141
with:
42-
python-version: 3.8
42+
python-version: 3.13
4343
- name: Install dependencies
4444
run: make install-test
4545
- name: Generate coverage report
4646
run: pytest --cov-report=xml
4747
- name: Upload coverage to Codecov
48-
uses: codecov/codecov-action@v1.5.0
48+
uses: codecov/codecov-action@v5
4949
with:
50+
token: ${{ secrets.CODECOV_TOKEN }}
5051
file: ./coverage.xml
5152
flags: unittests
5253
name: codecov-umbrella

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
SHELL := bash
22
PATH := ./venv/bin:${PATH}
3-
PYTHON = python3.9
3+
PYTHON = python3.13
44
PROJECT = facturapi
55
isort = isort $(PROJECT) tests setup.py examples
6-
black = black -S -l 79 --target-version py38 $(PROJECT) tests setup.py examples
6+
black = black -S -l 79 --target-version py313 $(PROJECT) tests setup.py examples
77

88

99
all: test

facturapi/http/client.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
2-
from typing import Any, Dict, MutableMapping, Optional, Union
2+
from typing import Any, MutableMapping
33
from urllib.parse import urljoin
44

5-
import requests
6-
from requests import Response
5+
import httpx
6+
from httpx import Response
77

88
from ..types.exc import FacturapiResponseException
99
from ..version import CLIENT_VERSION
@@ -21,18 +21,18 @@ class Client:
2121
2222
Attributes:
2323
host (str): Base URL to perform requests.
24-
session (requests.Session): The requests session used
24+
client (httpx.Client): The httpx client used
2525
to perform requests.
2626
api_key (str): API KEY for Facturapi
2727
2828
"""
2929

3030
host: str = API_HOST
31-
session: requests.Session
31+
client: httpx.Client
3232

33-
def __init__(self):
34-
self.session = requests.Session()
35-
self.session.headers.update(
33+
def __init__(self) -> None:
34+
self.client = httpx.Client()
35+
self.client.headers.update(
3636
{
3737
'User-Agent': f'facturapi-python/{CLIENT_VERSION}',
3838
'Content-Type': 'application/json',
@@ -41,9 +41,9 @@ def __init__(self):
4141

4242
# Auth
4343
self.api_key = os.getenv('FACTURAPI_KEY', '')
44-
self.session.auth = (self.api_key, '')
44+
self.client.auth = httpx.BasicAuth(self.api_key, '')
4545

46-
def configure(self, api_key: str):
46+
def configure(self, api_key: str) -> None:
4747
"""Configure the http client.
4848
4949
Import the client and configure it passing the `API_KEY`
@@ -54,36 +54,36 @@ def configure(self, api_key: str):
5454
5555
"""
5656
self.api_key = api_key
57-
self.session.auth = (self.api_key, '')
57+
self.client.auth = httpx.BasicAuth(self.api_key, '')
5858

5959
def get(
6060
self,
6161
endpoint: str,
62-
params: Union[None, bytes, MutableMapping[str, str]] = None,
63-
) -> Dict[str, Any]:
62+
params: bytes | MutableMapping[str, str] | None = None,
63+
) -> dict[str, Any]:
6464
"""Performs GET request to Facturapi."""
6565
return self.request('get', endpoint, params=params)
6666

67-
def post(self, endpoint: str, data: Dict[str, Any]) -> Dict[str, Any]:
67+
def post(self, endpoint: str, data: dict[str, Any]) -> dict[str, Any]:
6868
"""Performs POST request to Facturapi."""
6969
return self.request('post', endpoint, data=data)
7070

71-
def put(self, endpoint: str, data: Dict[str, Any]) -> Dict[str, Any]:
71+
def put(self, endpoint: str, data: dict[str, Any]) -> dict[str, Any]:
7272
"""Performs PUT request to Facturapi."""
7373
return self.request('put', endpoint, data=data)
7474

75-
def delete(self, endpoint: str) -> Dict[str, Any]:
75+
def delete(self, endpoint: str) -> dict[str, Any]:
7676
"""Performs DELETE request to Facturapi."""
7777
return self.request('delete', endpoint)
7878

7979
def request(
8080
self,
8181
method: str,
8282
endpoint: str,
83-
params: Union[None, bytes, MutableMapping[str, str]] = None,
84-
data: Optional[Dict[str, Union[int, str]]] = None,
83+
params: bytes | MutableMapping[str, str] | None = None,
84+
data: dict[str, int | str] | None = None,
8585
**kwargs,
86-
) -> Dict[str, Any]:
86+
) -> dict[str, Any]:
8787
"""Performs a request to Facturapi.
8888
8989
Given a `method` and `endpoint`, perform a request to
@@ -97,14 +97,14 @@ def request(
9797
**kwargs: Arbitrary keyword arguments.
9898
9999
Returns:
100-
Dict[str, Any]: JSON of the request's response.
100+
dict[str, Any]: JSON of the request's response.
101101
102102
Raises:
103103
FacturapiResponseException: If response is not
104104
successful.
105105
106106
"""
107-
response = self.session.request(
107+
response = self.client.request(
108108
method=method,
109109
url=('https://' + self.host + urljoin('/', endpoint)),
110110
json=data,
@@ -133,7 +133,7 @@ def download_request(
133133
successful.
134134
135135
"""
136-
response = self.session.request(
136+
response = self.client.request(
137137
method='GET',
138138
url=('https://' + self.host + urljoin('/', endpoint)),
139139
**kwargs,
@@ -142,8 +142,8 @@ def download_request(
142142
return response.content
143143

144144
@staticmethod
145-
def _check_response(response: Response):
146-
if not response.ok:
145+
def _check_response(response: Response) -> None:
146+
if not response.is_success:
147147
raise FacturapiResponseException(
148148
json=response.json(),
149149
status_code=response.status_code,

facturapi/resources/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from dataclasses import asdict, fields
9-
from typing import Any, ClassVar, Dict, Generator, List, Optional
9+
from typing import Any, ClassVar, Generator
1010
from urllib.parse import urlencode
1111

1212
from pydantic.dataclasses import dataclass
@@ -31,7 +31,7 @@ class corresponds to.
3131
"""
3232

3333
_resource: ClassVar[str]
34-
_relations: ClassVar[List[str]] = []
34+
_relations: ClassVar[list[str]] = []
3535

3636
id: str
3737

@@ -40,12 +40,12 @@ def __init__(self, **_): # pragma: no cover
4040
...
4141

4242
@classmethod
43-
def _from_dict(cls, obj_dict: Dict[str, Any]) -> 'Resource':
43+
def _from_dict(cls, obj_dict: dict[str, Any]) -> 'Resource':
4444
cls._filter_excess_fields(obj_dict)
4545
return cls(**obj_dict)
4646

4747
@classmethod
48-
def _filter_excess_fields(cls, obj_dict: Dict[str, Any]) -> None:
48+
def _filter_excess_fields(cls, obj_dict: dict[str, Any]) -> None:
4949
"""
5050
dataclasses don't allow __init__ to be called with excess fields.
5151
This method allows the API to add fields in the response body without
@@ -62,7 +62,7 @@ def _filter_excess_fields(cls, obj_dict: Dict[str, Any]) -> None:
6262
obj_dict[f'{f}_info'] = obj_dict[f]
6363
del obj_dict[f]
6464

65-
def to_dict(self) -> Dict:
65+
def to_dict(self) -> dict:
6666
return asdict(self, dict_factory=SanitizedDict)
6767

6868

@@ -90,7 +90,7 @@ def retrieve(cls, id: str) -> Resource:
9090
response = client.get(f'/{cls._resource}/{id}')
9191
return cls._from_dict(response)
9292

93-
def refresh(self):
93+
def refresh(self) -> None:
9494
"""Refresh a resource
9595
9696
Refresh resource's data to be sure its the latest. It
@@ -256,7 +256,7 @@ def one(cls, **query_params) -> Resource:
256256
return cls._from_dict(items[0])
257257

258258
@classmethod
259-
def first(cls, **query_params) -> Optional[Resource]:
259+
def first(cls, **query_params) -> Resource | None:
260260
"""Retrieve the first resource found given a query or none.
261261
262262
Args:

facturapi/resources/customers.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import datetime as dt
8-
from typing import ClassVar, Optional, cast
8+
from typing import ClassVar, cast
99

1010
from pydantic import BaseModel
1111
from pydantic.dataclasses import dataclass
@@ -34,7 +34,7 @@ class CustomerRequest(BaseModel):
3434
tax_id: str
3535
tax_system: TaxSystemType
3636
email: str
37-
phone: Optional[str]
37+
phone: str | None = None
3838
address: CustomerAddress
3939

4040

@@ -53,12 +53,12 @@ class CustomerUpdateRequest(BaseModel):
5353
5454
"""
5555

56-
legal_name: Optional[str]
57-
tax_id: Optional[str]
58-
tax_system: Optional[TaxSystemType]
59-
email: Optional[str]
60-
phone: Optional[str]
61-
address: Optional[CustomerAddress]
56+
legal_name: str | None = None
57+
tax_id: str | None = None
58+
tax_system: TaxSystemType | None = None
59+
email: str | None = None
60+
phone: str | None = None
61+
address: CustomerAddress | None = None
6262

6363

6464
@dataclass
@@ -89,8 +89,8 @@ class Customer(Creatable, Queryable, Retrievable, Updatable):
8989
tax_id: str
9090
email: str
9191
address: CustomerAddress
92-
tax_system: Optional[TaxSystemType] = None
93-
phone: Optional[str] = None
92+
tax_system: TaxSystemType | None = None
93+
phone: str | None = None
9494

9595
@classmethod
9696
def create(cls, data: CustomerRequest) -> 'Customer':
@@ -103,7 +103,7 @@ def create(cls, data: CustomerRequest) -> 'Customer':
103103
Customer: The created customer resource.
104104
105105
"""
106-
cleaned_data = data.dict(exclude_unset=True, exclude_none=True)
106+
cleaned_data = data.model_dump(exclude_unset=True, exclude_none=True)
107107
return cast('Customer', cls._create(**cleaned_data))
108108

109109
@classmethod
@@ -118,5 +118,5 @@ def update(cls, id: str, data: CustomerUpdateRequest) -> 'Customer':
118118
Customer: The udpated customer resource.
119119
120120
"""
121-
cleaned_data = data.dict(exclude_unset=True, exclude_none=True)
121+
cleaned_data = data.model_dump(exclude_unset=True, exclude_none=True)
122122
return cast('Customer', cls._update(id=id, **cleaned_data))

0 commit comments

Comments
 (0)