Skip to content

Commit 962c35f

Browse files
authored
Adjusting config (#8)
* Adjusting documentation * RTD theme version * Adding circle ci config * Install rtd requirements * requirements.txt no longer needed
1 parent 318bd83 commit 962c35f

File tree

13 files changed

+207
-162
lines changed

13 files changed

+207
-162
lines changed

.circleci/config.yml

+69-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
version: 2.1
22

3+
executors:
4+
python-container:
5+
docker:
6+
- image: cimg/python:3.12
7+
python-vm:
8+
machine:
9+
- image: ubuntu-2204:current
10+
311
workflows:
412
ci:
513
jobs:
614
- lint
15+
- test:
16+
name: Python (<< matrix.python_version >>) - ArangoDB (<< matrix.arangodb_license >>, << matrix.arangodb_version >> << matrix.arangodb_config >>)
17+
matrix:
18+
parameters:
19+
python_version: ["3.10"]
20+
arangodb_config: ["single"]
21+
arangodb_license: ["community"]
22+
arangodb_version: ["3.12"]
723

824
jobs:
925
lint:
10-
docker:
11-
- image: python:latest
26+
executor: python-container
27+
resource_class: small
1228
steps:
1329
- checkout
1430
- run:
@@ -26,3 +42,54 @@ jobs:
2642
- run:
2743
name: Run mypy
2844
command: mypy ./arangoasync
45+
test:
46+
parameters:
47+
python_version:
48+
type: string
49+
arangodb_config:
50+
type: string
51+
arangodb_license:
52+
type: string
53+
arangodb_version:
54+
type: string
55+
executor: python-vm
56+
steps:
57+
- checkout
58+
- run:
59+
name: Setup ArangoDB
60+
command: |
61+
chmod +x starter.sh
62+
./starter.sh ${{ matrix.arangodb_config }} ${{ matrix.arangodb_license }} ${{ matrix.arangodb_version }}
63+
- restore_cache:
64+
key: pip-and-local-cache
65+
- run:
66+
name: Setup Python
67+
command: |
68+
pyenv --version
69+
pyenv install -f << parameters.python_version >>
70+
pyenv global << parameters.python_version >>
71+
- run:
72+
name: Install Dependencies
73+
command: pip install -e .[dev]
74+
- run: docker ps -a
75+
- run: docker logs arango
76+
- run:
77+
name: Run pytest
78+
command: |
79+
mkdir test-results
80+
81+
args=("--junitxml=test-results/junit.xml" "--log-cli-level=DEBUG" "--host" "localhost" "--port=8529")
82+
if [ << parameters.arangodb_config >> = "cluster" ]; then
83+
args+=("--cluster" "--port=8539" "--port=8549")
84+
fi
85+
86+
if [ << parameters.arangodb_license >> = "enterprise" ]; then
87+
args+=("--enterprise")
88+
fi
89+
90+
echo "Running pytest with args: ${args[@]}"
91+
pytest --cov=arango --cov-report=xml --cov-report term-missing --color=yes --code-highlight=yes "${args[@]}"
92+
- store_artifacts:
93+
path: test-results
94+
- store_test_results:
95+
path: test-results

.github/workflows/docs.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
- name: Install dependencies
2525
run: pip install .[dev]
2626

27-
- name: Generate Sphinx HTML
28-
run: python -m sphinx -b html -W docs docs/_build
27+
- name: Run Sphinx doctest
28+
run: python -m sphinx -b doctest docs docs/_build

.readthedocs.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ sphinx:
2020
# to build your documentation
2121
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
2222
python:
23-
install:
24-
- requirements: docs/requirements.txt
23+
install:
24+
- method: pip
25+
path: .[dev]

arangoasync/http.py

+53-41
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,31 @@
1515

1616
class HTTPClient(ABC): # pragma: no cover
1717
"""Abstract base class for HTTP clients.
18+
1819
Custom HTTP clients should inherit from this class.
20+
21+
Example:
22+
.. code-block:: python
23+
24+
class MyCustomHTTPClient(HTTPClient):
25+
def create_session(self, host):
26+
pass
27+
async def send_request(self, session, request):
28+
pass
1929
"""
2030

2131
@abstractmethod
2232
def create_session(self, host: str) -> Any:
2333
"""Return a new session given the base host URL.
2434
25-
This method must be overridden by the user.
35+
Note:
36+
This method must be overridden by the user.
37+
38+
Args:
39+
host (str): ArangoDB host URL.
2640
27-
:param host: ArangoDB host URL.
28-
:type host: str
29-
:returns: Requests session object.
30-
:rtype: Any
41+
Returns:
42+
Requests session object.
3143
"""
3244
raise NotImplementedError
3345

@@ -39,37 +51,36 @@ async def send_request(
3951
) -> Response:
4052
"""Send an HTTP request.
4153
42-
This method must be overridden by the user.
54+
Note:
55+
This method must be overridden by the user.
4356
44-
:param session: Session object.
45-
:type session: Any
46-
:param request: HTTP request.
47-
:type request: arangoasync.request.Request
48-
:returns: HTTP response.
49-
:rtype: arangoasync.response.Response
57+
Args:
58+
session (Any): Client session object.
59+
request (Request): HTTP request.
60+
61+
Returns:
62+
Response: HTTP response.
5063
"""
5164
raise NotImplementedError
5265

5366

5467
class AioHTTPClient(HTTPClient):
55-
"""HTTP client implemented on top of [aiohttp](https://docs.aiohttp.org/en/stable/).
56-
57-
:param connector: Supports connection pooling.
58-
By default, 100 simultaneous connections are supported, with a 60-second timeout
59-
for connection reusing after release.
60-
:type connector: aiohttp.BaseConnector | None
61-
:param timeout: Timeout settings.
62-
300s total timeout by default for a complete request/response operation.
63-
:type timeout: aiohttp.ClientTimeout | None
64-
:param read_bufsize: Size of read buffer (64KB default).
65-
:type read_bufsize: int
66-
:param auth: HTTP authentication helper.
67-
Should be used for specifying authorization data in client API.
68-
:type auth: aiohttp.BasicAuth | None
69-
:param compression_threshold: Will compress requests to the server if
70-
the size of the request body (in bytes) is at least the value of this
71-
option.
72-
:type compression_threshold: int
68+
"""HTTP client implemented on top of aiohttp_.
69+
70+
Args:
71+
connector (aiohttp.BaseConnector | None): Supports connection pooling.
72+
By default, 100 simultaneous connections are supported, with a 60-second
73+
timeout for connection reusing after release.
74+
timeout (aiohttp.ClientTimeout | None): Client timeout settings.
75+
300s total timeout by default for a complete request/response operation.
76+
read_bufsize (int): Size of read buffer (64KB default).
77+
auth (aiohttp.BasicAuth | None): HTTP authentication helper.
78+
Should be used for specifying authorization data in client API.
79+
compression_threshold (int): Will compress requests to the server if the size
80+
of the request body (in bytes) is at least the value of this option.
81+
82+
.. _aiohttp:
83+
https://docs.aiohttp.org/en/stable/
7384
"""
7485

7586
def __init__(
@@ -95,11 +106,12 @@ def __init__(
95106
def create_session(self, host: str) -> ClientSession:
96107
"""Return a new session given the base host URL.
97108
98-
:param host: ArangoDB host URL. Typically, the address and port of a coordinator
99-
(e.g. "http://127.0.0.1:8529").
100-
:type host: str
101-
:returns: Session object.
102-
:rtype: aiohttp.ClientSession
109+
Args:
110+
host (str): ArangoDB host URL. Must not include any paths. Typically, this
111+
is the address and port of a coordinator (e.g. "http://127.0.0.1:8529").
112+
113+
Returns:
114+
aiohttp.ClientSession: Session object, used to send future requests.
103115
"""
104116
return ClientSession(
105117
base_url=host,
@@ -116,12 +128,12 @@ async def send_request(
116128
) -> Response:
117129
"""Send an HTTP request.
118130
119-
:param session: Session object.
120-
:type session: aiohttp.ClientSession
121-
:param request: HTTP request.
122-
:type request: arangoasync.request.Request
123-
:returns: HTTP response.
124-
:rtype: arangoasync.response.Response
131+
Args:
132+
session (aiohttp.ClientSession): Session object used to make the request.
133+
request (Request): HTTP request.
134+
135+
Returns:
136+
Response: HTTP response.
125137
"""
126138
method = request.method
127139
endpoint = request.endpoint

arangoasync/request.py

+24-37
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class Method(Enum):
14-
"""HTTP methods."""
14+
"""HTTP methods enum: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS"""
1515

1616
GET = auto()
1717
POST = auto()
@@ -25,31 +25,19 @@ class Method(Enum):
2525
class Request:
2626
"""HTTP request.
2727
28-
:param method: HTTP method.
29-
:type method: request.Method
30-
:param endpoint: API endpoint.
31-
:type endpoint: str
32-
:param headers: Request headers.
33-
:type headers: dict | None
34-
:param params: URL parameters.
35-
:type params: dict | None
36-
:param data: Request payload.
37-
:type data: Any
38-
:param deserialize: Whether the response body should be deserialized.
39-
:type deserialize: bool
40-
41-
:ivar method: HTTP method.
42-
:vartype method: request.Method
43-
:ivar endpoint: API endpoint, for example "_api/version".
44-
:vartype endpoint: str
45-
:ivar headers: Request headers.
46-
:vartype headers: dict | None
47-
:ivar params: URL (query) parameters.
48-
:vartype params: dict | None
49-
:ivar data: Request payload.
50-
:vartype data: Any
51-
:ivar deserialize: Whether the response body should be deserialized.
52-
:vartype deserialize: bool
28+
Args:
29+
method (Method): HTTP method.
30+
endpoint (str): API endpoint.
31+
headers (dict | None): Request headers.
32+
params (dict | None): URL parameters.
33+
data (str | None): Request payload.
34+
35+
Attributes:
36+
method (Method): HTTP method.
37+
endpoint (str): API endpoint.
38+
headers (dict | None): Request headers.
39+
params (dict | None): URL parameters.
40+
data (str | None): Request payload.
5341
"""
5442

5543
__slots__ = (
@@ -58,7 +46,6 @@ class Request:
5846
"headers",
5947
"params",
6048
"data",
61-
"deserialize",
6249
)
6350

6451
def __init__(
@@ -68,23 +55,22 @@ def __init__(
6855
headers: Optional[Headers] = None,
6956
params: Optional[Params] = None,
7057
data: Optional[str] = None,
71-
deserialize: bool = True,
7258
) -> None:
7359
self.method: Method = method
7460
self.endpoint: str = endpoint
7561
self.headers: Headers = self._normalize_headers(headers)
7662
self.params: Params = self._normalize_params(params)
7763
self.data: Optional[str] = data
78-
self.deserialize: bool = deserialize
7964

8065
@staticmethod
8166
def _normalize_headers(headers: Optional[Headers]) -> Headers:
8267
"""Normalize request headers.
8368
84-
:param headers: Request headers.
85-
:type headers: dict | None
86-
:returns: Normalized request headers.
87-
:rtype: dict
69+
Parameters:
70+
headers (dict | None): Request headers.
71+
72+
Returns:
73+
dict: Normalized request headers.
8874
"""
8975
driver_header = f"arangoasync/{__version__}"
9076
normalized_headers: Headers = {
@@ -103,10 +89,11 @@ def _normalize_headers(headers: Optional[Headers]) -> Headers:
10389
def _normalize_params(params: Optional[Params]) -> Params:
10490
"""Normalize URL parameters.
10591
106-
:param params: URL parameters.
107-
:type params: dict | None
108-
:returns: Normalized URL parameters.
109-
:rtype: dict
92+
Parameters:
93+
params (dict | None): URL parameters.
94+
95+
Returns:
96+
dict: Normalized URL parameters.
11097
"""
11198
normalized_params: Params = {}
11299

0 commit comments

Comments
 (0)