Skip to content

Commit feb4548

Browse files
authored
Add GitHub actions (anvilco#46)
* Add actions * Fix lint * Name change * Fix mypy type linting * Fix tests
1 parent 7a351ca commit feb4548

File tree

7 files changed

+81
-37
lines changed

7 files changed

+81
-37
lines changed

.github/workflows/main.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Run linters and tests
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.7]
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install Poetry
17+
uses: snok/install-poetry@v1
18+
with:
19+
virtualenvs-create: true
20+
virtualenvs-in-project: true
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
cache: 'poetry'
27+
28+
- name: Install poetry dependencies
29+
run: poetry install
30+
31+
- name: Check dependencies
32+
run: make doctor
33+
34+
- name: Install dependencies
35+
run: make install
36+
37+
- name: Check code
38+
run: make check
39+
40+
- name: Test code
41+
run: make test
42+
43+
# - name: Upload coverage
44+
# uses: codecov/codecov-action@v1
45+
# with:
46+
# fail_ci_if_error: true

examples/forge_submit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from python_anvil.api import Anvil
44
from python_anvil.api_resources.payload import ForgeSubmitPayload
55

6+
67
API_KEY = os.environ.get("ANVIL_API_KEY")
78
# or set your own key here
89
# API_KEY = 'my-api-key'

python_anvil/api.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,18 @@ def get_cast(
151151
eid: str,
152152
fields: Optional[List[str]] = None,
153153
version_number: Optional[int] = None,
154-
cast_args: Optional[List[str]] = None,
154+
cast_args: Optional[List[Tuple[str, str]]] = None,
155155
**kwargs,
156-
):
156+
) -> Dict[str, Any]:
157157

158158
if not fields:
159159
# Use default fields
160-
fields = ['eid', 'title', 'fieldInfo']
160+
fields = ["eid", "title", "fieldInfo"]
161161

162162
if not cast_args:
163163
cast_args = []
164164

165-
cast_args.append(('eid', f'"{eid}"'))
165+
cast_args.append(("eid", f'"{eid}"'))
166166

167167
# If `version_number` isn't provided, the API will default to the
168168
# latest published version.
@@ -183,14 +183,12 @@ def get_cast(
183183
**kwargs,
184184
)
185185

186-
def get_data(r):
186+
def get_data(r) -> Dict[str, Any]:
187187
return r["data"]["cast"]
188188

189189
return _get_return(res, get_data=get_data)
190190

191-
def get_casts(
192-
self, fields=None, show_all=False, **kwargs
193-
) -> Union[List, Tuple[List, Dict]]:
191+
def get_casts(self, fields=None, show_all=False, **kwargs) -> List[Dict[str, Any]]:
194192
if not fields:
195193
# Use default fields
196194
fields = ["eid", "title", "fieldInfo"]

python_anvil/api_resources/requests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, Dict
2+
13
from python_anvil.http import HTTPClient
24

35

@@ -97,14 +99,14 @@ def run_query(
9799
raise AssertionError(
98100
"Either `query` or `files` must be passed in " "to this method."
99101
)
100-
data = {}
102+
data: Dict[str, Any] = {}
101103

102104
if query:
103105
data["query"] = query
104106

105107
if files and is_multipart:
106108
# Make sure `data` is nothing when we're doing a multipart request.
107-
data = None
109+
data = {}
108110
elif variables:
109111
data["variables"] = variables
110112

python_anvil/cli.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from logging import getLogger
66
from tabulate import tabulate
77
from time import sleep
8-
from typing import List
8+
from typing import Any, Dict, List
99

1010
from python_anvil import utils
1111

@@ -150,22 +150,22 @@ def cast(ctx, eid, version_number, list_all, list_templates):
150150

151151
if eid:
152152
click.echo(f"Getting cast with eid '{eid}' \n")
153-
res = anvil.get_cast(eid, version_number=version_number, debug=debug)
153+
_res = anvil.get_cast(eid, version_number=version_number, debug=debug)
154154

155-
if contains_headers(res):
155+
if contains_headers(_res):
156156
res, headers = process_response(res)
157157
if debug:
158158
click.echo(headers)
159159

160160
def get_field_info(cc):
161161
return tabulate(cc.get("fields", []))
162162

163-
if not res:
163+
if not _res:
164164
click.echo(f"Cast with eid: {eid} not found")
165165
return
166166

167-
table_data = [[res["eid"], res["title"], get_field_info(res["fieldInfo"])]]
168-
click.echo(tabulate(table_data, tablefmt="pretty", headers=res.keys()))
167+
table_data = [[_res["eid"], _res["title"], get_field_info(_res["fieldInfo"])]]
168+
click.echo(tabulate(table_data, tablefmt="pretty", headers=list(_res.keys())))
169169

170170

171171
@cli.command("fill-pdf")

python_anvil/multipart_helpers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import mimetypes
44
from io import BufferedIOBase
55
from pathlib import Path
6-
from typing import Any, Callable, List, Optional, Tuple, Union
6+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
77

88
from python_anvil.api_resources.mutations import BaseQuery
99

@@ -95,7 +95,10 @@ def is_match(item):
9595
for idx, filepath in enumerate(multipart_map):
9696
filemap[idx] = [filepath[0]]
9797

98-
files = {"operations": (None, operations), "map": (None, json.dumps(filemap))}
98+
files = {
99+
"operations": (None, operations),
100+
"map": (None, json.dumps(filemap)),
101+
} # type: Dict[str, Union[Tuple[None, str], Tuple[Any, Any, Optional[str]]]]
99102

100103
for idx, file_or_path in enumerate(to_upload):
101104
# `key` here is most likely going to be a list index (int), but
@@ -104,7 +107,7 @@ def is_match(item):
104107
actual_key = str(idx)
105108

106109
# This is already a file-like object, pass it directly to `requests`.
107-
if isinstance(file_or_path, Callable):
110+
if isinstance(file_or_path, Callable): # type: ignore
108111
# If you have a `ValueError` here, make sure your callable returns
109112
# a tuple of the file and filename:
110113
# Example: (open(file, "rb"), "file.pdf"))

python_anvil/tests/test_api.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,8 @@ def test_create_etch_packet_valid_payload_type(m_request_post, anvil):
244244
anvil.create_etch_packet(payload=payload)
245245
assert m_request_post.call_count == 1
246246

247-
files_payload = json.loads(
248-
m_request_post.call_args.kwargs["files"]["operations"][1]
249-
)
247+
files = m_request_post.call_args[1]["files"]
248+
files_payload = json.loads(files["operations"][1])
250249
variables = files_payload["variables"]
251250
assert expected_data == variables
252251

@@ -264,9 +263,8 @@ def test_create_etch_packet_passes_options(m_request_post, anvil):
264263
anvil.create_etch_packet(payload)
265264

266265
assert m_request_post.call_count == 1
267-
files_payload = json.loads(
268-
m_request_post.call_args.kwargs["files"]["operations"][1]
269-
)
266+
files = m_request_post.call_args[1]["files"]
267+
files_payload = json.loads(files["operations"][1])
270268
variables = files_payload["variables"]
271269
assert new_expected == variables
272270

@@ -276,9 +274,8 @@ def test_create_etch_packet_valid_dict_type(m_request_post, anvil):
276274
dict(name="Packet name", signature_email_subject="The subject")
277275
)
278276
assert m_request_post.call_count == 1
279-
files_payload = json.loads(
280-
m_request_post.call_args.kwargs["files"]["operations"][1]
281-
)
277+
files = m_request_post.call_args[1]["files"]
278+
files_payload = json.loads(files["operations"][1])
282279
variables = files_payload["variables"]
283280
assert expected_data == variables
284281

@@ -292,9 +289,8 @@ def test_create_etch_packet_dict_with_signer(
292289
m_create_unique.return_value = "signer-mock-generated"
293290
anvil.create_etch_packet(payload=payloads.ETCH_TEST_PAYLOAD)
294291
assert m_request_post.call_count == 1
295-
files_payload = json.loads(
296-
m_request_post.call_args.kwargs["files"]["operations"][1]
297-
)
292+
files = m_request_post.call_args[1]["files"]
293+
files_payload = json.loads(files["operations"][1])
298294
variables = files_payload["variables"]
299295
assert payloads.EXPECTED_ETCH_TEST_PAYLOAD == variables
300296

@@ -313,9 +309,8 @@ def test_create_etch_packet_json(m_request_post, m_create_unique, anvil):
313309
anvil.create_etch_packet(json=json.dumps(payload))
314310
assert m_request_post.call_count == 1
315311

316-
files_payload = json.loads(
317-
m_request_post.call_args.kwargs["files"]["operations"][1]
318-
)
312+
files = m_request_post.call_args[1]["files"]
313+
files_payload = json.loads(files["operations"][1])
319314
variables = files_payload["variables"]
320315
assert payload == variables
321316

@@ -336,9 +331,8 @@ def test_adding_unsupported_fields(m_request_post, m_create_unique, anvil):
336331
anvil.create_etch_packet(payload=cep)
337332
assert m_request_post.call_count == 1
338333

339-
files_payload = json.loads(
340-
m_request_post.call_args.kwargs["files"]["operations"][1]
341-
)
334+
files = m_request_post.call_args[1]["files"]
335+
files_payload = json.loads(files["operations"][1])
342336
variables = files_payload["variables"]
343337
assert cep.dict(by_alias=True, exclude_none=True) == variables
344338
assert "newFeature" in variables

0 commit comments

Comments
 (0)