Skip to content

Commit 641e511

Browse files
Remove syntax used as a workaround while Python 3.7 was being supported (#246)
* Remove syntax used as a workaround while Python 3.7 was being supported * Fix missing user["username"] access.
1 parent 70380b4 commit 641e511

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

@@ -1135,18 +1135,9 @@ def path_to_deploy_version(self, name: str, version: str):
11351135
# to fs.put to the <user>/<content_name>.
11361136
return self.path_to_pin(name)
11371137

1138-
@property
1138+
@functools.cached_property
11391139
def user_name(self):
1140-
# note that this is essentially the manual version of functools.cached_property
1141-
# since we support python 3.7
1142-
name = getattr(self, "_user_name", None)
1143-
if name is not None:
1144-
return name
1145-
else:
1146-
user = self.fs.api.get_user()
1147-
self._user_name = user["username"]
1148-
1149-
return self._user_name
1140+
return self.fs.api.get_user()["username"]
11501141

11511142
def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwargs):
11521143
# RSC pin names can have form <user_name>/<name>, but this will try to
@@ -1169,8 +1160,7 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
11691160
)
11701161

11711162
# recursively copy all assets into prepped pin version dir
1172-
# shutil.copytree(self.html_assets_dir, pin_dir_path, dirs_exist_ok=True)
1173-
_copytree(self.html_assets_dir, pin_dir_path)
1163+
shutil.copytree(self.html_assets_dir, pin_dir_path, dirs_exist_ok=True)
11741164

11751165
# render index.html ------------------------------------------------
11761166

@@ -1231,17 +1221,3 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
12311221
(Path(pin_dir_path) / "index.html").write_text(rendered)
12321222

12331223
return meta
1234-
1235-
1236-
# TODO: replace with shutil.copytree once py3.7 is dropped
1237-
# copied from https://stackoverflow.com/a/12514470/1144523
1238-
def _copytree(src, dst, symlinks=False, ignore=None):
1239-
import os
1240-
1241-
for item in os.listdir(src):
1242-
s = os.path.join(src, item)
1243-
d = os.path.join(dst, item)
1244-
if os.path.isdir(s):
1245-
shutil.copytree(s, d, symlinks, ignore)
1246-
else:
1247-
shutil.copy2(s, d)

0 commit comments

Comments
 (0)