1
- # from jaraco.path 3.5
1
+ # from jaraco.path 3.6
2
2
3
3
import functools
4
4
import pathlib
11
11
from typing_extensions import Protocol , runtime_checkable # type: ignore
12
12
13
13
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
15
21
16
22
17
23
@runtime_checkable
@@ -28,6 +34,9 @@ def write_text(self, content, **kwargs):
28
34
def write_bytes (self , content ):
29
35
... # pragma: no cover
30
36
37
+ def symlink_to (self , target ):
38
+ ... # pragma: no cover
39
+
31
40
32
41
def _ensure_tree_maker (obj : Union [str , TreeMaker ]) -> TreeMaker :
33
42
return obj if isinstance (obj , TreeMaker ) else pathlib .Path (obj ) # type: ignore
@@ -51,12 +60,16 @@ def build(
51
60
... "__init__.py": "",
52
61
... },
53
62
... "baz.py": "# Some code",
54
- ... }
63
+ ... "bar.py": Symlink("baz.py"),
64
+ ... },
65
+ ... "bing": Symlink("foo"),
55
66
... }
56
67
>>> target = getfixture('tmp_path')
57
68
>>> build(spec, target)
58
69
>>> target.joinpath('foo/baz.py').read_text(encoding='utf-8')
59
70
'# Some code'
71
+ >>> target.joinpath('bing/bar.py').read_text(encoding='utf-8')
72
+ '# Some code'
60
73
"""
61
74
for name , contents in spec .items ():
62
75
create (contents , _ensure_tree_maker (prefix ) / name )
@@ -79,8 +92,8 @@ def _(content: str, path):
79
92
80
93
81
94
@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 )
84
97
85
98
86
99
class Recording :
@@ -107,3 +120,6 @@ def write_text(self, content, **kwargs):
107
120
108
121
def mkdir (self , ** kwargs ):
109
122
return
123
+
124
+ def symlink_to (self , target ):
125
+ pass
0 commit comments