Skip to content

Commit 834e52e

Browse files
Remove syntax used as a workaround while Python 3.7 was being supported
1 parent 2b7bebb commit 834e52e

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

pins/boards.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import shutil
44
import inspect
55
import re
6+
import functools
67

78
from io import IOBase
89
from pathlib import Path
910
from importlib_resources import files
1011
from datetime import datetime, timedelta
1112

12-
from typing import Sequence, Optional, Mapping
13+
from typing import Protocol, Sequence, Optional, Mapping
1314

1415
from .versions import VersionRaw, guess_version, version_setup
1516
from .meta import Meta, MetaRaw, MetaFactory
@@ -23,8 +24,7 @@
2324
_log = logging.getLogger(__name__)
2425

2526

26-
# Note that once we drop python 3.7, we can make this a Protocol
27-
class IFileSystem:
27+
class IFileSystem(Protocol):
2828

2929
protocol: "str | list"
3030

@@ -1075,18 +1075,9 @@ def path_to_deploy_version(self, name: str, version: str):
10751075
# to fs.put to the <user>/<content_name>.
10761076
return self.path_to_pin(name)
10771077

1078-
@property
1078+
@functools.cached_property
10791079
def user_name(self):
1080-
# note that this is essentially the manual version of functools.cached_property
1081-
# since we support python 3.7
1082-
name = getattr(self, "_user_name", None)
1083-
if name is not None:
1084-
return name
1085-
else:
1086-
user = self.fs.api.get_user()
1087-
self._user_name = user["username"]
1088-
1089-
return self._user_name
1080+
return self.fs.api.get_user()
10901081

10911082
def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwargs):
10921083
# TODO: should move board_deparse into utils, to avoid circular import
@@ -1112,8 +1103,7 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
11121103
)
11131104

11141105
# recursively copy all assets into prepped pin version dir
1115-
# shutil.copytree(self.html_assets_dir, pin_dir_path, dirs_exist_ok=True)
1116-
_copytree(self.html_assets_dir, pin_dir_path)
1106+
shutil.copytree(self.html_assets_dir, pin_dir_path, dirs_exist_ok=True)
11171107

11181108
# render index.html ------------------------------------------------
11191109

@@ -1174,17 +1164,3 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
11741164
(Path(pin_dir_path) / "index.html").write_text(rendered)
11751165

11761166
return meta
1177-
1178-
1179-
# TODO: replace with shutil.copytree once py3.7 is dropped
1180-
# copied from https://stackoverflow.com/a/12514470/1144523
1181-
def _copytree(src, dst, symlinks=False, ignore=None):
1182-
import os
1183-
1184-
for item in os.listdir(src):
1185-
s = os.path.join(src, item)
1186-
d = os.path.join(dst, item)
1187-
if os.path.isdir(s):
1188-
shutil.copytree(s, d, symlinks, ignore)
1189-
else:
1190-
shutil.copy2(s, d)

0 commit comments

Comments
 (0)