@@ -92,9 +92,6 @@ def transform_data(rows, transformer):
9292 if errors :
9393 return column_names , data , errors
9494
95- if transformer .row_filters :
96- data = list (transformer .filter_rows (data ))
97-
9895 return column_names , data , errors
9996
10097
@@ -143,18 +140,6 @@ def transform_data(rows, transformer):
143140 column_filters:
144141 - name
145142 - version
146-
147- * row_filters:
148- An optional list of mappings of <column name>: <value> that a source CSV row
149- should match to be added to the transformed target CSV. If any column value of a
150- row matches any such filter it is kept. Otherwise it is skipped. Filters are
151- applied last after all renamings, checks and tranforms and can therefore onlu
152- use remaining column names.
153-
154- For instance with this configuration the target CSV will only contain rows that
155- have a "path" equal to "/root/user/lib":
156- row_filters:
157- path : /root/user/lib
158143'''
159144
160145
@@ -165,15 +150,20 @@ class Transformer(object):
165150 column_renamings = attr .attrib (default = attr .Factory (dict ))
166151 required_columns = attr .attrib (default = attr .Factory (list ))
167152 column_filters = attr .attrib (default = attr .Factory (list ))
168- row_filters = attr .attrib (default = attr .Factory (list ))
169153
170- # TODO: populate these!
171154 # a list of all the standard columns from AboutCode toolkit
172155 standard_columns = attr .attrib (default = attr .Factory (list ), init = False )
173156 # a list of the subset of standard columns that are essential and MUST be
174157 # present for AboutCode toolkit to work
175158 essential_columns = attr .attrib (default = attr .Factory (list ), init = False )
176159
160+ # called by attr after the __init__()
161+ def __attrs_post_init__ (self , * args , ** kwargs ):
162+ from attributecode .model import About
163+ about = About ()
164+ self .essential_columns = list (about .required_fields )
165+ self .standard_columns = [f .name for f in about .all_fields ()]
166+
177167 @classmethod
178168 def default (cls ):
179169 """
@@ -183,7 +173,6 @@ def default(cls):
183173 column_renamings = {},
184174 required_columns = [],
185175 column_filters = [],
186- row_filters = [],
187176 )
188177
189178 @classmethod
@@ -198,7 +187,6 @@ def from_file(cls, location):
198187 column_renamings = data .get ('column_renamings' , {}),
199188 required_columns = data .get ('required_columns' , []),
200189 column_filters = data .get ('column_filters' , []),
201- row_filters = data .get ('row_filters' , []),
202190 )
203191
204192 def check_required_columns (self , data ):
@@ -257,20 +245,6 @@ def filter_columns(self, data):
257245 items = ((k , v ) for k , v in entry .items () if k in column_filters )
258246 yield OrderedDict (items )
259247
260- def filter_rows (self , data ):
261- """
262- Yield a filtered list of mappings from a `data` list of mappings keeping
263- only items that match any one of the `row_filters` of this Transformer.
264- Return the data unchanged if no `row_filters` is avilable in this
265- Transformer.
266- """
267- filters = self .row_filters
268- for entry in data :
269- for filt in filters :
270- for filtered_column_name , filtered_column_value in filt .items ():
271- if entry .get (filtered_column_name ) == filtered_column_value :
272- yield entry
273-
274248
275249def check_duplicate_columns (column_names ):
276250 """
0 commit comments