@@ -65,99 +65,116 @@ def init_external_storage(self, force=False):
65
65
@property
66
66
def external_storage_installed (self ):
67
67
"""Check that Large File Storage is installed."""
68
- return HAS_LFS and self .repo .config_reader (
69
- ).has_section ('filter "lfs"' )
68
+ return HAS_LFS
70
69
71
70
def track_paths_in_storage (self , * paths ):
72
71
"""Track paths in the external storage."""
73
- if self .use_external_storage and self .external_storage_installed :
74
- track_paths = []
75
- attrs = self .find_attr (* paths )
76
-
77
- for path in paths :
78
- # Do not add files with filter=lfs in .gitattributes
79
- if attrs .get (path , {}).get ('filter' ) == 'lfs' :
80
- continue
81
-
82
- path = Path (path )
83
- if path .is_dir ():
84
- track_paths .append (str (path / '**' ))
85
- elif path .suffix != '.ipynb' :
86
- # TODO create configurable filter and follow .gitattributes
87
- track_paths .append (str (path ))
88
-
89
- call (
90
- self ._CMD_STORAGE_TRACK + track_paths ,
91
- stdout = PIPE ,
92
- stderr = STDOUT ,
93
- cwd = str (self .path ),
94
- )
95
- elif self .use_external_storage :
72
+ if not self ._use_lfs ():
73
+ return
74
+
75
+ if not self .external_storage_installed :
96
76
raise errors .ExternalStorageNotInstalled (self .repo )
97
77
78
+ track_paths = []
79
+ attrs = self .find_attr (* paths )
80
+
81
+ for path in paths :
82
+ # Do not add files with filter=lfs in .gitattributes
83
+ if attrs .get (path , {}).get ('filter' ) == 'lfs' :
84
+ continue
85
+
86
+ path = Path (path )
87
+ if path .is_dir ():
88
+ track_paths .append (str (path / '**' ))
89
+ elif path .suffix != '.ipynb' :
90
+ # TODO create configurable filter and follow .gitattributes
91
+ track_paths .append (str (path ))
92
+
93
+ call (
94
+ self ._CMD_STORAGE_TRACK + track_paths ,
95
+ stdout = PIPE ,
96
+ stderr = STDOUT ,
97
+ cwd = str (self .path ),
98
+ )
99
+
98
100
def untrack_paths_from_storage (self , * paths ):
99
101
"""Untrack paths from the external storage."""
100
- if self .use_external_storage and self .external_storage_installed :
101
- call (
102
- self ._CMD_STORAGE_UNTRACK + list (paths ),
103
- stdout = PIPE ,
104
- stderr = STDOUT ,
105
- cwd = str (self .path ),
106
- )
107
- elif self .use_external_storage :
102
+ if not self ._use_lfs ():
103
+ return
104
+
105
+ if not self .external_storage_installed :
108
106
raise errors .ExternalStorageNotInstalled (self .repo )
109
107
108
+ call (
109
+ self ._CMD_STORAGE_UNTRACK + list (paths ),
110
+ stdout = PIPE ,
111
+ stderr = STDOUT ,
112
+ cwd = str (self .path ),
113
+ )
114
+
110
115
def pull_paths_from_storage (self , * paths ):
111
116
"""Pull paths from LFS."""
112
117
import math
113
- if self .use_external_storage and self .external_storage_installed :
114
- client_dict = defaultdict (list )
115
118
116
- for path in _expand_directories (paths ):
117
- client , commit , path = self .resolve_in_submodules (
118
- self .repo .commit (), path
119
- )
120
- client_dict [client .path ].append (str (path ))
121
-
122
- for client_path , paths in client_dict .items ():
123
- for ibatch in range (
124
- math .ceil (len (paths ) / ARGUMENT_BATCH_SIZE )
125
- ):
126
- run (
127
- self ._CMD_STORAGE_PULL + [
128
- shlex .quote (
129
- ',' .join (
130
- paths [ibatch * ARGUMENT_BATCH_SIZE :
131
- (ibatch + 1 ) * ARGUMENT_BATCH_SIZE ]
132
- )
133
- )
134
- ],
135
- cwd = str (client_path .absolute ()),
136
- stdout = PIPE ,
137
- stderr = STDOUT ,
138
- )
139
- elif self .use_external_storage :
119
+ if not self ._use_lfs ():
120
+ return
121
+
122
+ if not self .external_storage_installed :
140
123
raise errors .ExternalStorageNotInstalled (self .repo )
141
124
125
+ client_dict = defaultdict (list )
126
+
127
+ for path in _expand_directories (paths ):
128
+ client , commit , path = self .resolve_in_submodules (
129
+ self .repo .commit (), path
130
+ )
131
+ client_dict [client .path ].append (str (path ))
132
+
133
+ for client_path , paths in client_dict .items ():
134
+ for ibatch in range (math .ceil (len (paths ) / ARGUMENT_BATCH_SIZE )):
135
+ run (
136
+ self ._CMD_STORAGE_PULL + [
137
+ shlex .quote (
138
+ ',' .join (
139
+ paths [ibatch * ARGUMENT_BATCH_SIZE :
140
+ (ibatch + 1 ) * ARGUMENT_BATCH_SIZE ]
141
+ )
142
+ )
143
+ ],
144
+ cwd = str (client_path .absolute ()),
145
+ stdout = PIPE ,
146
+ stderr = STDOUT ,
147
+ )
148
+
142
149
def checkout_paths_from_storage (self , * paths ):
143
150
"""Checkout a paths from LFS."""
144
- if self .use_external_storage and self .external_storage_installed :
145
- run (
146
- self ._CMD_STORAGE_CHECKOUT + list (paths ),
147
- cwd = str (self .path .absolute ()),
148
- stdout = PIPE ,
149
- stderr = STDOUT ,
150
- check = True ,
151
- )
152
- elif self .use_external_storage :
151
+ if not self ._use_lfs ():
152
+ return
153
+
154
+ if not self .external_storage_installed :
153
155
raise errors .ExternalStorageNotInstalled (self .repo )
154
156
157
+ run (
158
+ self ._CMD_STORAGE_CHECKOUT + list (paths ),
159
+ cwd = str (self .path .absolute ()),
160
+ stdout = PIPE ,
161
+ stderr = STDOUT ,
162
+ check = True ,
163
+ )
164
+
155
165
def init_repository (self , name = None , force = False ):
156
166
"""Initialize a local Renku repository."""
157
167
result = super ().init_repository (name = name , force = force )
158
168
159
169
# initialize LFS if it is requested and installed
160
- if self .use_external_storage and HAS_LFS :
170
+ if self .use_external_storage and self . external_storage_installed :
161
171
self .init_external_storage (force = force )
162
172
163
173
return result
174
+
175
+ def _use_lfs (self ):
176
+ renku_initialized_to_use_lfs = self .repo .config_reader (
177
+ config_level = 'repository'
178
+ ).has_section ('filter "lfs"' )
179
+
180
+ return renku_initialized_to_use_lfs and self .use_external_storage
0 commit comments