1- # from jaraco.path 3.5
1+ # from jaraco.path 3.6
22
33import functools
44import pathlib
1111 from typing_extensions import Protocol , runtime_checkable # type: ignore
1212
1313
14- FilesSpec = Dict [str , Union [str , bytes , 'FilesSpec' ]] # type: ignore
14+ class Symlink (str ):
15+ """
16+ A string indicating the target of a symlink.
17+ """
18+
19+
20+ FilesSpec = Dict [str , Union [str , bytes , Symlink , 'FilesSpec' ]] # type: ignore
1521
1622
1723@runtime_checkable
@@ -28,6 +34,9 @@ def write_text(self, content, **kwargs):
2834 def write_bytes (self , content ):
2935 ... # pragma: no cover
3036
37+ def symlink_to (self , target ):
38+ ... # pragma: no cover
39+
3140
3241def _ensure_tree_maker (obj : Union [str , TreeMaker ]) -> TreeMaker :
3342 return obj if isinstance (obj , TreeMaker ) else pathlib .Path (obj ) # type: ignore
@@ -51,12 +60,16 @@ def build(
5160 ... "__init__.py": "",
5261 ... },
5362 ... "baz.py": "# Some code",
54- ... }
63+ ... "bar.py": Symlink("baz.py"),
64+ ... },
65+ ... "bing": Symlink("foo"),
5566 ... }
5667 >>> target = getfixture('tmp_path')
5768 >>> build(spec, target)
5869 >>> target.joinpath('foo/baz.py').read_text(encoding='utf-8')
5970 '# Some code'
71+ >>> target.joinpath('bing/bar.py').read_text(encoding='utf-8')
72+ '# Some code'
6073 """
6174 for name , contents in spec .items ():
6275 create (contents , _ensure_tree_maker (prefix ) / name )
@@ -79,8 +92,8 @@ def _(content: str, path):
7992
8093
8194@create .register
82- def _ (content : str , path ):
83- path .write_text (content , encoding = 'utf-8' )
95+ def _ (content : Symlink , path ):
96+ path .symlink_to (content )
8497
8598
8699class Recording :
@@ -107,3 +120,6 @@ def write_text(self, content, **kwargs):
107120
108121 def mkdir (self , ** kwargs ):
109122 return
123+
124+ def symlink_to (self , target ):
125+ pass
0 commit comments