Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit a17ae47

Browse files
authored
Merge pull request #13 from CSCfi/devel
bump to 0.1.5
2 parents 3d225fd + 4e0be74 commit a17ae47

File tree

9 files changed

+83
-62
lines changed

9 files changed

+83
-62
lines changed

Diff for: .github/workflows/style.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
max-parallel: 4
99
matrix:
1010
os: [ubuntu-latest]
11-
python-version: [3.7]
11+
python-version: [3.7, 3.8]
1212

1313
runs-on: ${{ matrix.os }}
1414

@@ -24,5 +24,7 @@ jobs:
2424
pip install tox tox-gh-actions
2525
- name: Test flake8 syntax with tox
2626
run: tox -e flake8
27+
- name: Test mypy typing with tox
28+
run: tox -e mypy
2729
- name: bandit static check
2830
run: tox -e bandit

Diff for: swift_upload_runner/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Runner for swift-browser-ui upload and replication operations."""
22

33
__name__ = "swift_upload_runner"
4-
__version__ = "0.1.4"
4+
__version__ = "0.1.5"
55
__author__ = "CSC Developers"
66
__license__ = "MIT License"

Diff for: swift_upload_runner/auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def handle_login(
5757

5858
async def read_in_keys(
5959
app: aiohttp.web.Application
60-
):
60+
) -> None:
6161
"""Read in keys to the application."""
6262
keys = os.environ.get("SWIFT_UI_API_AUTH_TOKENS", None)
6363
app["tokens"] = keys.split(",") if keys is not None else []

Diff for: swift_upload_runner/common.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313

1414
def generate_download_url(
15-
host,
16-
container=None,
17-
object_name=None,
15+
host: str,
16+
container: typing.Union[str, None] = None,
17+
object_name: typing.Union[str, None] = None,
1818
) -> str:
1919
"""Generate the download URL to use."""
2020
if not container and not object_name:
@@ -94,7 +94,7 @@ async def get_upload_instance(
9494
if p_query:
9595
query: dict = p_query
9696
else:
97-
query = request.query
97+
query = request.query # type: ignore
9898

9999
# Check the existence of the dictionary structure
100100
try:
@@ -142,7 +142,9 @@ def get_path_from_list(
142142
return ret.lstrip("/").rstrip("/")
143143

144144

145-
async def handle_delete_preflight(_) -> aiohttp.web.Response:
145+
async def handle_delete_preflight(
146+
_: typing.Union[aiohttp.web.Request, None]
147+
) -> aiohttp.web.Response:
146148
"""Serve correct response headers to allowed DELETE preflight query."""
147149
resp = aiohttp.web.Response(
148150
headers={

Diff for: swift_upload_runner/download.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class FileDownloadProxy:
3434
def __init__(
3535
self,
3636
auth: keystoneauth1.session.Session,
37-
chunk_size=128 * 1024
38-
):
37+
chunk_size: int = 128 * 1024
38+
) -> None:
3939
"""."""
4040
# Establish a queue for the proxied file parts
4141
# Total queue size 128 * 256 * 1024 = 32MiB for now
@@ -103,7 +103,7 @@ def download_into_queue(
103103
project: str,
104104
container: str,
105105
object_name: str
106-
):
106+
) -> None:
107107
"""Download object chunks from stream into the queue."""
108108
print(f"""
109109
Downloading from project {project},
@@ -159,7 +159,7 @@ async def a_begin_download(
159159
project: str,
160160
container: str,
161161
object_name: str
162-
):
162+
) -> None:
163163
"""Begin the download process."""
164164
self.begin_download(
165165
project,
@@ -172,7 +172,7 @@ def begin_download(
172172
project: str,
173173
container: str,
174174
object_name: str
175-
):
175+
) -> None:
176176
"""Begin the download process."""
177177
self.t_dload = threading.Thread(
178178
target=self.download_into_queue,
@@ -188,7 +188,7 @@ def begin_download(
188188
async def a_write_to_response(
189189
self,
190190
resp: aiohttp.web.StreamResponse
191-
):
191+
) -> None:
192192
"""Get the response serving the file."""
193193
while True:
194194
chunk = await self.a_read()
@@ -207,7 +207,7 @@ def __init__(
207207
project: str,
208208
container: str,
209209
object_name: str
210-
):
210+
) -> None:
211211
"""."""
212212
# Initialize the download class
213213
self.dload = FileDownloadProxy(auth)
@@ -222,7 +222,7 @@ def get_dload(self) -> FileDownloadProxy:
222222
"""Return the specific download instance."""
223223
return self.dload
224224

225-
def begin_download(self):
225+
def begin_download(self) -> None:
226226
"""Begin download and block until received headers."""
227227
self.dload.begin_download(
228228
self.project,
@@ -258,7 +258,7 @@ class TarQueueWrapper:
258258

259259
def __init__(
260260
self
261-
):
261+
) -> None:
262262
"""."""
263263
self.q: queue.Queue = queue.Queue(
264264
maxsize=int(
@@ -269,13 +269,13 @@ def __init__(
269269
def write(
270270
self,
271271
payload: bytes = None
272-
):
272+
) -> None:
273273
"""Emulate BytesIO write function to be used with tarfile."""
274274
self.q.put(payload)
275275

276276
def read(
277277
self
278-
):
278+
) -> bytes:
279279
"""Read next chunk."""
280280
return self.q.get()
281281

@@ -287,7 +287,7 @@ def get_q(
287287

288288
async def a_read(
289289
self
290-
):
290+
) -> bytes:
291291
"""Asynchronously read next chunk."""
292292
while True:
293293
try:
@@ -304,8 +304,8 @@ def __init__(
304304
auth: keystoneauth1.session.Session,
305305
project: str,
306306
container: str,
307-
chunk_size=128 * 1024
308-
):
307+
chunk_size: int = 128 * 1024
308+
) -> None:
309309
"""."""
310310
self.auth = auth
311311
self.download_queue: queue.Queue = queue.Queue(
@@ -411,7 +411,7 @@ def _parse_archive_fs(
411411

412412
def get_object_listing(
413413
self,
414-
):
414+
) -> None:
415415
"""Synchronize the list of objects to download."""
416416
with requests.get(
417417
generate_download_url(
@@ -429,8 +429,8 @@ def get_object_listing(
429429

430430
def sync_folders(
431431
self,
432-
fs
433-
):
432+
fs: dict
433+
) -> None:
434434
"""Sycnhronize the folders into the tar archive."""
435435
if self.archive:
436436
for i in fs:
@@ -440,15 +440,15 @@ def sync_folders(
440440

441441
def download_init(
442442
self,
443-
):
443+
) -> None:
444444
"""Create download init."""
445445
self.download_init_loop(self.fs)
446446
self.download_queue.put(None)
447447

448448
def download_init_loop(
449449
self,
450-
fs
451-
):
450+
fs: dict
451+
) -> None:
452452
"""Loop to run for initializing downloads."""
453453
if self.archive:
454454
for i in fs:
@@ -472,7 +472,7 @@ def download_init_loop(
472472

473473
def tar_archiving_loop(
474474
self,
475-
):
475+
) -> None:
476476
"""Loop to run for initializing tarballing."""
477477
while True:
478478
next_file = self.download_queue.get()
@@ -502,20 +502,20 @@ def tar_archiving_loop(
502502

503503
async def a_begin_container_download(
504504
self,
505-
):
505+
) -> None:
506506
"""Begin the operation for downloading a whole container."""
507507
self.begin_container_download()
508508

509509
def begin_container_download(
510510
self,
511-
):
511+
) -> None:
512512
"""Begin the operation for downloading a whole container."""
513513
self.get_object_listing()
514514

515515
self.archive = tarfile.open(
516516
name=self.container + ".tar",
517517
mode="w|",
518-
fileobj=self.output_queue
518+
fileobj=self.output_queue # type:ignore
519519
)
520520

521521
self.sync_folders(self.fs)
@@ -535,7 +535,7 @@ def begin_container_download(
535535
async def a_write_to_response(
536536
self,
537537
response: aiohttp.web.StreamResponse
538-
):
538+
) -> None:
539539
"""Write the tarball into the response."""
540540
while True:
541541
chunk = await self.output_queue.a_read()

Diff for: swift_upload_runner/replicate.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
container: str,
3535
source_project: str,
3636
source_container: str,
37-
):
37+
) -> None:
3838
"""."""
3939
self.project = project
4040
self.container = container
@@ -54,7 +54,7 @@ def __init__(
5454
async def a_generate_object_from_reader(
5555
self,
5656
resp: aiohttp.client.ClientResponse
57-
):
57+
) -> typing.AsyncGenerator:
5858
"""Generate uploaded object chunks from a response."""
5959
number = 0
6060
while True:
@@ -67,8 +67,8 @@ async def a_generate_object_from_reader(
6767

6868
async def a_create_container(
6969
self,
70-
segmented=False
71-
):
70+
segmented: bool = False
71+
) -> None:
7272
"""Create the container required by the upload."""
7373
container = \
7474
f"{self.container}_segments" if segmented else self.container
@@ -91,8 +91,8 @@ async def a_create_container(
9191

9292
async def a_sync_object_segments(
9393
self,
94-
manifest
95-
) -> typing.List[str]:
94+
manifest: str
95+
) -> str:
9696
"""Get object segments."""
9797
async with self.client.get(
9898
common.generate_download_url(
@@ -183,8 +183,8 @@ async def a_sync_object_segments(
183183

184184
async def a_copy_object(
185185
self,
186-
object_name
187-
):
186+
object_name: str
187+
) -> None:
188188
"""Copy an object from a location."""
189189
# Get the object stream handle
190190
async with self.client.get(
@@ -275,7 +275,7 @@ async def a_copy_object(
275275
)
276276
LOGGER.debug(f"Uploaded manifest for {object_name}")
277277

278-
async def a_copy_from_container(self):
278+
async def a_copy_from_container(self) -> None:
279279
"""Copy objects from a source container."""
280280
LOGGER.debug(
281281
f"Fetching objects from container {self.source_container}"
@@ -285,6 +285,7 @@ async def a_copy_from_container(self):
285285
container=self.source_container
286286
)
287287
LOGGER.debug(f"Container url: {container_url}")
288+
objects: typing.Union[typing.List, str]
288289
async with self.client.get(
289290
common.generate_download_url(
290291
self.source_host,

Diff for: swift_upload_runner/server.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ async def servinit() -> aiohttp.web.Application:
7070

7171
async def kill_client(
7272
app: aiohttp.web.Application
73-
):
73+
) -> None:
7474
"""Kill the app client session."""
7575
await app["client"].close()
7676

7777

7878
def run_server(
7979
app: typing.Union[typing.Coroutine, aiohttp.web.Application]
80-
):
80+
) -> None:
8181
"""Run the server."""
8282
aiohttp.web.run_app(
8383
app,
@@ -86,7 +86,7 @@ def run_server(
8686
)
8787

8888

89-
def main():
89+
def main() -> None:
9090
"""."""
9191
run_server(servinit())
9292

0 commit comments

Comments
 (0)