Skip to content

Commit 87317f7

Browse files
committed
Replace deprecated distutils package
The package `distutils` is deprecated since python 3.10 and it is scheduled to be removed with python 3.12, see: https://docs.python.org/3.12/whatsnew/3.12.html python/cpython#92584 `shutil.copytree()` is able to copy the source directory tree to an existing destination directory only from python 3.8 (parameter `dirs_exist_ok=True`), for python < 3.8 still use `distutils.dir_util.copy_tree()` While here: - create in a safe way the temporary directory used for the update - deal with possible download problems Raise worker version to 214 (also server side)
1 parent ca6c2d5 commit 87317f7

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

server/fishtest/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
on how frequently the main instance flushes its run cache.
2626
"""
2727

28-
WORKER_VERSION = 213
28+
WORKER_VERSION = 214
2929

3030

3131
def validate_request(request):

worker/sri.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"__version": 213, "updater.py": "GEDqwD5F16roa/hRFbTNbbUqW/smvbe/4Rcf09O5BIJOAI63wsAVgLEnMtQp1naZ", "worker.py": "dT4tz1DqISrMUZhqlQNV94nvpf6EPVg0ebs118cSJ8gC7C22PetaQjQgA1Ciupm4", "games.py": "LyUiwCAMXllQWLIHsWGZpQpziYGO6dK3jDXzimEFd2ehLLrp5nsSGbl7+AUQTnAa"}
1+
{"__version": 214, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "DAMoJ5Rh2a7U8hqA9LX1zba0o8uvrGQVfF+6vcs32SnUDhYen9VYajljx6mzFhAn", "games.py": "LyUiwCAMXllQWLIHsWGZpQpziYGO6dK3jDXzimEFd2ehLLrp5nsSGbl7+AUQTnAa"}

worker/updater.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22
import shutil
33
import sys
4+
import tempfile
45
from datetime import datetime, timezone
5-
from distutils.dir_util import copy_tree
66
from pathlib import Path
77
from zipfile import ZipFile
88

@@ -26,12 +26,24 @@ def do_restart():
2626

2727
def update(restart=True, test=False):
2828
worker_dir = Path(__file__).resolve().parent
29-
update_dir = worker_dir / "update"
30-
update_dir.mkdir(exist_ok=True)
31-
29+
update_dir = Path(tempfile.mkdtemp(dir=worker_dir))
3230
worker_zip = update_dir / "wk.zip"
33-
with open(worker_zip, "wb+") as f:
34-
f.write(requests.get(WORKER_URL).content)
31+
32+
try:
33+
response = requests.get(WORKER_URL)
34+
response.raise_for_status()
35+
except Exception as e:
36+
print(
37+
"Failed to download {}:\n".format(WORKER_URL),
38+
e,
39+
sep="",
40+
file=sys.stderr,
41+
)
42+
shutil.rmtree(update_dir)
43+
return None
44+
else:
45+
with open(worker_zip, "wb+") as f:
46+
f.write(response.content)
3547

3648
with ZipFile(worker_zip) as zip_file:
3749
zip_file.extractall(update_dir)
@@ -57,7 +69,13 @@ def update(restart=True, test=False):
5769
sep="",
5870
file=sys.stderr,
5971
)
60-
copy_tree(str(worker_src), str(worker_dir))
72+
if sys.version_info < (3, 8):
73+
from distutils.dir_util import copy_tree
74+
75+
copy_tree(str(worker_src), str(worker_dir))
76+
else:
77+
shutil.copytree(worker_src, worker_dir, dirs_exist_ok=True)
78+
6179
else:
6280
file_list = os.listdir(worker_src)
6381
shutil.rmtree(update_dir)

worker/worker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# Several packages are called "expression".
5555
# So we make sure to use the locally installed one.
5656

57-
WORKER_VERSION = 213
57+
WORKER_VERSION = 214
5858
FILE_LIST = ["updater.py", "worker.py", "games.py"]
5959
HTTP_TIMEOUT = 30.0
6060
INITIAL_RETRY_TIME = 15.0

0 commit comments

Comments
 (0)