3
3
import shutil
4
4
import inspect
5
5
import re
6
+ import functools
6
7
7
8
from io import IOBase
8
9
from pathlib import Path
9
10
from importlib_resources import files
10
11
from datetime import datetime , timedelta
11
12
12
- from typing import Sequence , Optional , Mapping
13
+ from typing import Protocol , Sequence , Optional , Mapping
13
14
14
15
from .versions import VersionRaw , guess_version , version_setup
15
16
from .meta import Meta , MetaRaw , MetaFactory
23
24
_log = logging .getLogger (__name__ )
24
25
25
26
26
- # Note that once we drop python 3.7, we can make this a Protocol
27
- class IFileSystem :
27
+ class IFileSystem (Protocol ):
28
28
29
29
protocol : "str | list"
30
30
@@ -1075,18 +1075,9 @@ def path_to_deploy_version(self, name: str, version: str):
1075
1075
# to fs.put to the <user>/<content_name>.
1076
1076
return self .path_to_pin (name )
1077
1077
1078
- @property
1078
+ @functools . cached_property
1079
1079
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 ()
1090
1081
1091
1082
def prepare_pin_version (self , pin_dir_path , x , name : "str | None" , * args , ** kwargs ):
1092
1083
# 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
1112
1103
)
1113
1104
1114
1105
# 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 )
1117
1107
1118
1108
# render index.html ------------------------------------------------
1119
1109
@@ -1174,17 +1164,3 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
1174
1164
(Path (pin_dir_path ) / "index.html" ).write_text (rendered )
1175
1165
1176
1166
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