55import re
66
77from io import IOBase
8- from functools import cached_property
98from pathlib import Path
109from importlib_resources import files
1110from datetime import datetime , timedelta
1211
13- from typing import Protocol , Sequence , Optional , Mapping
12+ from typing import Sequence , Optional , Mapping
1413
1514from .versions import VersionRaw , guess_version
1615from .meta import Meta , MetaRaw , MetaFactory
1716from .errors import PinsError
1817from .drivers import load_data , save_data , default_title
1918
2019
21- class IFileSystem (Protocol ):
20+ # Note that once we drop python 3.7, we can make this a Protocol
21+ class IFileSystem :
2222 def ls (self , path : str ) -> Sequence [str ]:
2323 ...
2424
@@ -797,10 +797,18 @@ def path_to_deploy_version(self, name: str, version: str):
797797 # to fs.put to the <user>/<content_name>.
798798 return self .path_to_pin (name )
799799
800- @cached_property
800+ @property
801801 def user_name (self ):
802- user = self .fs .api .get_user ()
803- return user ["username" ]
802+ # note that this is essentially the manual version of functools.cached_property
803+ # since we support python 3.7
804+ name = getattr (self , "_user_name" , None )
805+ if name is not None :
806+ return name
807+ else :
808+ user = self .fs .api .get_user ()
809+ self ._user_name = user ["username" ]
810+
811+ return self ._user_name
804812
805813 def prepare_pin_version (self , pin_dir_path , x , name : "str | None" , * args , ** kwargs ):
806814
@@ -824,7 +832,8 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
824832 )
825833
826834 # recursively copy all assets into prepped pin version dir
827- shutil .copytree (self .html_assets_dir , pin_dir_path , dirs_exist_ok = True )
835+ # shutil.copytree(self.html_assets_dir, pin_dir_path, dirs_exist_ok=True)
836+ _copytree (self .html_assets_dir , pin_dir_path )
828837
829838 # render index.html ------------------------------------------------
830839
@@ -870,3 +879,17 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
870879 (Path (pin_dir_path ) / "index.html" ).write_text (rendered )
871880
872881 return meta
882+
883+
884+ # TODO: replace with shutil.copytree once py3.7 is dropped
885+ # copied from https://stackoverflow.com/a/12514470/1144523
886+ def _copytree (src , dst , symlinks = False , ignore = None ):
887+ import os
888+
889+ for item in os .listdir (src ):
890+ s = os .path .join (src , item )
891+ d = os .path .join (dst , item )
892+ if os .path .isdir (s ):
893+ shutil .copytree (s , d , symlinks , ignore )
894+ else :
895+ shutil .copy2 (s , d )
0 commit comments