Skip to content

Commit cd4ab52

Browse files
HongyuLiiHongyu Li
andauthored
Dev/hongyu/3442 formatting black (#9)
* add black formatting * reformatted python code Co-authored-by: Hongyu Li <hongyu.li@jitsuin.com>
1 parent 1672700 commit cd4ab52

28 files changed

Lines changed: 1072 additions & 1082 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist/
77
*.xml
88
htmlcov/
99
.pylint.d/
10+
.cache/

Taskfile.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ tasks:
3636
- rm -rf build
3737
- rm -f dist/*
3838
- python3 setup.py bdist_wheel
39+
40+
format:
41+
desc: Format code using black
42+
cmds:
43+
- ./scripts/builder.sh black archivist examples unittests

archivist/access_policies.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,119 +10,119 @@
1010
ASSETS_LABEL,
1111
)
1212

13-
DEFAULT_PAGE_SIZE=500
13+
DEFAULT_PAGE_SIZE = 500
1414

1515

1616
class _AccessPoliciesClient:
17-
"""docstring
18-
"""
17+
"""docstring"""
18+
1919
def __init__(self, archivist):
20-
"""docstring
21-
"""
20+
"""docstring"""
2221
self._archivist = archivist
2322

2423
def create(self, request):
25-
"""docstring
26-
"""
24+
"""docstring"""
2725

28-
return AccessPolicy(**self._archivist.post(
29-
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
30-
request,
31-
))
26+
return AccessPolicy(
27+
**self._archivist.post(
28+
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
29+
request,
30+
)
31+
)
3232

3333
def read(self, identity):
34-
"""docstring
35-
"""
36-
return AccessPolicy(**self._archivist.get(
37-
ACCESS_POLICIES_SUBPATH,
38-
identity,
39-
))
34+
"""docstring"""
35+
return AccessPolicy(
36+
**self._archivist.get(
37+
ACCESS_POLICIES_SUBPATH,
38+
identity,
39+
)
40+
)
4041

4142
def update(self, identity, request):
42-
"""docstring
43-
"""
44-
return AccessPolicy(**self._archivist.patch(
45-
ACCESS_POLICIES_SUBPATH,
46-
identity,
47-
request,
48-
))
43+
"""docstring"""
44+
return AccessPolicy(
45+
**self._archivist.patch(
46+
ACCESS_POLICIES_SUBPATH,
47+
identity,
48+
request,
49+
)
50+
)
4951

5052
def delete(self, identity):
51-
"""docstring
52-
"""
53+
"""docstring"""
5354
return self._archivist.delete(ACCESS_POLICIES_SUBPATH, identity)
5455

5556
@staticmethod
5657
def __query(props):
57-
"""docstring
58-
"""
58+
"""docstring"""
5959
query = props or {}
6060
return query
6161

6262
def count(self, *, query=None):
63-
"""docstring
64-
"""
63+
"""docstring"""
6564
return self._archivist.count(
6665
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
67-
query=self.__query(query)
66+
query=self.__query(query),
6867
)
6968

7069
def list(self, *, page_size=DEFAULT_PAGE_SIZE, query=None):
71-
"""docstring
72-
"""
70+
"""docstring"""
7371
return (
74-
AccessPolicy(**a) for a in self._archivist.list(
72+
AccessPolicy(**a)
73+
for a in self._archivist.list(
7574
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
7675
ACCESS_POLICIES_LABEL,
7776
page_size=page_size,
78-
query=self.__query(query)
77+
query=self.__query(query),
7978
)
8079
)
8180

8281
# additional queries on different endpoints
8382
def count_matching_assets(self, access_policy_id, *, query=None):
84-
"""docstring
85-
"""
83+
"""docstring"""
8684
return self._archivist.count(
8785
SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)),
8886
ASSETS_LABEL,
89-
query=self.__query(query)
87+
query=self.__query(query),
9088
)
9189

92-
def list_matching_assets(self, access_policy_id, *, page_size=DEFAULT_PAGE_SIZE, query=None):
93-
"""docstring
94-
"""
90+
def list_matching_assets(
91+
self, access_policy_id, *, page_size=DEFAULT_PAGE_SIZE, query=None
92+
):
93+
"""docstring"""
9594
return (
96-
AccessPolicy(**a) for a in self._archivist.list(
95+
AccessPolicy(**a)
96+
for a in self._archivist.list(
9797
SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)),
9898
ASSETS_LABEL,
9999
page_size=page_size,
100-
query=self.__query(query)
100+
query=self.__query(query),
101101
)
102102
)
103103

104104
def count_matching_access_policies(self, asset_id, *, query=None):
105-
"""docstring
106-
"""
105+
"""docstring"""
107106
return self._archivist.count(
108107
SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ACCESS_POLICIES_LABEL)),
109108
ACCESS_POLICIES_LABEL,
110-
query=self.__query(query)
109+
query=self.__query(query),
111110
)
112111

113-
def list_matching_access_policies(self, asset_id, *, page_size=DEFAULT_PAGE_SIZE, query=None):
114-
"""docstring
115-
"""
112+
def list_matching_access_policies(
113+
self, asset_id, *, page_size=DEFAULT_PAGE_SIZE, query=None
114+
):
115+
"""docstring"""
116116
return (
117-
AccessPolicy(**a) for a in self._archivist.list(
117+
AccessPolicy(**a)
118+
for a in self._archivist.list(
118119
SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ASSETS_LABEL)),
119120
ACCESS_POLICIES_LABEL,
120121
page_size=page_size,
121-
query=self.__query(query)
122+
query=self.__query(query),
122123
)
123124
)
124125

125126

126127
class AccessPolicy(dict):
127-
"""AccessPolicy object
128-
"""
128+
"""AccessPolicy object"""

archivist/archivist.py

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,17 @@ class Archivist: # pylint: disable=too-many-instance-attributes
4444
4545
Either auth or cert must be specified
4646
"""
47+
4748
def __init__(self, url, *, auth=None, cert=None, verify=True):
48-
"""docstring
49-
"""
50-
self._headers = {'content-type': 'application/json'}
49+
"""docstring"""
50+
self._headers = {"content-type": "application/json"}
5151
if auth is not None:
52-
self._headers['authorization'] = 'Bearer ' + auth.strip()
52+
self._headers["authorization"] = "Bearer " + auth.strip()
5353

5454
self._url = url
5555
self._verify = verify
5656
if not cert and not auth:
57-
raise ArchivistIllegalArgumentError(
58-
"Either auth or cert must be specified"
59-
)
57+
raise ArchivistIllegalArgumentError("Either auth or cert must be specified")
6058

6159
if cert and auth:
6260
raise ArchivistIllegalArgumentError(
@@ -65,9 +63,7 @@ def __init__(self, url, *, auth=None, cert=None, verify=True):
6563

6664
if cert:
6765
if not os_path_isfile(cert):
68-
raise ArchivistNotFoundError(
69-
f"Cert file {cert} does not exist"
70-
)
66+
raise ArchivistNotFoundError(f"Cert file {cert} does not exist")
7167

7268
self._cert = cert
7369

@@ -78,31 +74,26 @@ def __init__(self, url, *, auth=None, cert=None, verify=True):
7874

7975
@property
8076
def headers(self):
81-
"""docstring
82-
"""
77+
"""docstring"""
8378
return self._headers
8479

8580
@property
8681
def url(self):
87-
"""docstring
88-
"""
82+
"""docstring"""
8983
return self._url
9084

9185
@property
9286
def verify(self):
93-
"""docstring
94-
"""
87+
"""docstring"""
9588
return self._verify
9689

9790
@property
9891
def cert(self):
99-
"""docstring
100-
"""
92+
"""docstring"""
10193
return self._cert
10294

10395
def __add_headers(self, headers):
104-
"""docstring
105-
"""
96+
"""docstring"""
10697
if headers is not None:
10798
newheaders = {**self.headers, **headers}
10899
else:
@@ -182,11 +173,11 @@ def post_file(self, path, fd, mtype):
182173

183174
multipart = MultipartEncoder(
184175
fields={
185-
'file': ('filename', fd, mtype),
176+
"file": ("filename", fd, mtype),
186177
}
187178
)
188179
headers = {
189-
'content-type': multipart.content_type,
180+
"content-type": multipart.content_type,
190181
}
191182
response = requests.post(
192183
SEP.join((self.url, ROOT, path)),
@@ -242,7 +233,7 @@ def patch(self, subpath, identity, request, *, headers=None):
242233

243234
def __list(self, path, args, *, headers=None):
244235
if args:
245-
path = '?'.join((path, args))
236+
path = "?".join((path, args))
246237

247238
response = requests.get(
248239
SEP.join((self.url, ROOT, path)),
@@ -258,10 +249,8 @@ def __list(self, path, args, *, headers=None):
258249

259250
@staticmethod
260251
def __query(query):
261-
return query and '&'.join(
262-
sorted(
263-
f"{k}={v}" for k, v in flatten(query, reducer='dot').items()
264-
)
252+
return query and "&".join(
253+
sorted(f"{k}={v}" for k, v in flatten(query, reducer="dot").items())
265254
)
266255

267256
def get_by_signature(self, path, field, query, *, headers=None):
@@ -281,9 +270,7 @@ def get_by_signature(self, path, field, query, *, headers=None):
281270

282271
response = self.__list(
283272
path,
284-
'&'.join(
285-
(a for a in (paging, qry) if a)
286-
),
273+
"&".join((a for a in (paging, qry) if a)),
287274
headers=headers,
288275
)
289276

@@ -311,15 +298,13 @@ def count(self, path, *, query=None):
311298

312299
paging = "page_size=1"
313300
qry = self.__query(query)
314-
headers = {HEADERS_REQUEST_TOTAL_COUNT: 'true'}
301+
headers = {HEADERS_REQUEST_TOTAL_COUNT: "true"}
315302

316303
# v2/assets?page_size=10&something=something...
317304

318305
response = self.__list(
319306
path,
320-
'&'.join(
321-
(a for a in (paging, qry) if a)
322-
),
307+
"&".join((a for a in (paging, qry) if a)),
323308
headers=headers,
324309
)
325310

@@ -348,9 +333,7 @@ def list(self, path, field, *, page_size=None, query=None, headers=None):
348333
while True:
349334
response = self.__list(
350335
path,
351-
'&'.join(
352-
(a for a in (paging, qry) if a)
353-
),
336+
"&".join((a for a in (paging, qry) if a)),
354337
headers=headers,
355338
)
356339
data = response.json()

0 commit comments

Comments
 (0)