1
1
from bonobo .config import Configurable , ContextProcessor , Option , Service
2
2
3
3
4
+ def filesystem_path (path : str ):
5
+ if path .startswith ("/" ):
6
+ raise ValueError (
7
+ "File path should not be absolute. If you really need to provide absolute paths, then you must pass a "
8
+ "filesystem instance that is bound to your filesystem root and provide a relative path from there."
9
+ )
10
+ return str (path )
11
+
12
+
4
13
class FileHandler (Configurable ):
5
14
"""Abstract component factory for file-related components.
6
15
@@ -13,39 +22,12 @@ class FileHandler(Configurable):
13
22
"""
14
23
15
24
path = Option (
16
- str ,
17
- required = True ,
18
- positional = True ,
19
- __doc__ = """
20
- Path to use within the provided filesystem.
21
- """ ,
22
- ) # type: str
23
- eol = Option (
24
- str ,
25
- default = "\n " ,
26
- __doc__ = """
27
- Character to use as line separator.
28
- """ ,
29
- ) # type: str
30
- mode = Option (
31
- str ,
32
- __doc__ = """
33
- What mode to use for open() call.
34
- """ ,
35
- ) # type: str
36
- encoding = Option (
37
- str ,
38
- default = "utf-8" ,
39
- __doc__ = """
40
- Encoding.
41
- """ ,
42
- ) # type: str
43
- fs = Service (
44
- "fs" ,
45
- __doc__ = """
46
- The filesystem instance to use.
47
- """ ,
25
+ filesystem_path , required = True , positional = True , __doc__ = "Path to use within the provided filesystem."
48
26
) # type: str
27
+ eol = Option (str , default = "\n " , __doc__ = "Character to use as line separator." ) # type: str
28
+ mode = Option (str , __doc__ = "What mode to use for open() call." ) # type: str
29
+ encoding = Option (str , default = "utf-8" , __doc__ = "Encoding." ) # type: str
30
+ fs = Service ("fs" , __doc__ = "The filesystem instance to use." ) # type: str
49
31
50
32
@ContextProcessor
51
33
def file (self , context , * , fs ):
0 commit comments