python-table-converter 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/PKG-INFO +1 -1
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/pyproject.toml +1 -1
- python_table_converter-0.2.1/table_converter/__init__.py +2 -0
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/table_converter/core/config.py +14 -11
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/table_converter/core/convert.py +5 -10
- python_table_converter-0.2.0/table_converter/__init__.py +0 -2
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/LICENSE +0 -0
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/README.md +0 -0
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/table_converter/cli.py +0 -0
- {python_table_converter-0.2.0 → python_table_converter-0.2.1}/table_converter/commands/convert_tables.py +0 -0
{python_table_converter-0.2.0 → python_table_converter-0.2.1}/table_converter/core/config.py
RENAMED
|
@@ -10,10 +10,14 @@ import yaml
|
|
|
10
10
|
type FlatFieldMap = Mapping[str, str]
|
|
11
11
|
type FieldMap = Mapping[str, str|FieldMap]
|
|
12
12
|
|
|
13
|
+
@dataclasses.dataclass
|
|
14
|
+
class ProcessConfig:
|
|
15
|
+
split_by_newline: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
16
|
+
|
|
13
17
|
@dataclasses.dataclass
|
|
14
18
|
class Config:
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
map: FieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
20
|
+
process: ProcessConfig = dataclasses.field(default_factory=ProcessConfig)
|
|
17
21
|
|
|
18
22
|
def flatten(
|
|
19
23
|
mapping: FieldMap,
|
|
@@ -33,6 +37,7 @@ def flatten(
|
|
|
33
37
|
def setup_config(
|
|
34
38
|
config_path: str | None = None,
|
|
35
39
|
):
|
|
40
|
+
config = Config()
|
|
36
41
|
if config_path:
|
|
37
42
|
if config_path.endswith('.yaml'):
|
|
38
43
|
yaml.add_constructor(
|
|
@@ -40,17 +45,15 @@ def setup_config(
|
|
|
40
45
|
lambda loader, node: OrderedDict(loader.construct_pairs(node)),
|
|
41
46
|
)
|
|
42
47
|
with open(config_path, 'r') as f:
|
|
43
|
-
|
|
44
|
-
#ic(data)
|
|
45
|
-
config = Config(
|
|
46
|
-
#**data,
|
|
47
|
-
map = flatten(data.get('map', {})),
|
|
48
|
-
)
|
|
48
|
+
loaded = yaml.load(f, yaml.Loader)
|
|
49
49
|
else:
|
|
50
50
|
raise ValueError(
|
|
51
51
|
'Only YAML configuration files are supported.'
|
|
52
52
|
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
ic(loaded)
|
|
54
|
+
if 'map' in loaded:
|
|
55
|
+
config.map = flatten(loaded['map'])
|
|
56
|
+
if 'process' in loaded:
|
|
57
|
+
if 'split_by_newline' in loaded['process']:
|
|
58
|
+
config.process.split_by_newline = flatten(loaded['process']['split_by_newline'])
|
|
56
59
|
return config
|
{python_table_converter-0.2.0 → python_table_converter-0.2.1}/table_converter/core/convert.py
RENAMED
|
@@ -247,7 +247,6 @@ def convert(
|
|
|
247
247
|
df_list = []
|
|
248
248
|
dict_constants: OrderedDict | None = None
|
|
249
249
|
dict_formats: OrderedDict | None = None
|
|
250
|
-
dict_split_by_newline: OrderedDict | None = None
|
|
251
250
|
dict_assign_ids= None
|
|
252
251
|
root_id_stat = create_id_stat_node()
|
|
253
252
|
config = setup_config(config_path)
|
|
@@ -271,23 +270,19 @@ def convert(
|
|
|
271
270
|
else:
|
|
272
271
|
raise ValueError(f'Invalid template assignment: {field}')
|
|
273
272
|
if pickup_columns:
|
|
274
|
-
if config.map is None:
|
|
275
|
-
config.map = OrderedDict()
|
|
276
273
|
fields = pickup_columns.split(',')
|
|
277
274
|
for field in fields:
|
|
278
275
|
if '=' in field:
|
|
279
276
|
dst, value = field.split('=')
|
|
280
|
-
|
|
277
|
+
config.map[dst] = value
|
|
281
278
|
else:
|
|
282
|
-
|
|
279
|
+
config.map[field] = field
|
|
283
280
|
if fields_to_split_by_newline:
|
|
284
|
-
#list_fields_to_split_by_newline = fields_to_split_by_newline.split(',')
|
|
285
|
-
dict_split_by_newline = OrderedDict()
|
|
286
281
|
fields = fields_to_split_by_newline.split(',')
|
|
287
282
|
for field in fields:
|
|
288
283
|
if '=' in field:
|
|
289
284
|
dst, src = field.split('=')
|
|
290
|
-
|
|
285
|
+
config.process.split_by_newline[dst] = src
|
|
291
286
|
else:
|
|
292
287
|
raise ValueError(f'Invalid split by newline: {field}')
|
|
293
288
|
if fields_to_assign_ids:
|
|
@@ -330,8 +325,8 @@ def convert(
|
|
|
330
325
|
new_row = map_constants(new_row, dict_constants)
|
|
331
326
|
if config.map:
|
|
332
327
|
new_row = remap_columns(new_row, config.map)
|
|
333
|
-
if
|
|
334
|
-
new_row = apply_fields_split_by_newline(new_row,
|
|
328
|
+
if config.process.split_by_newline:
|
|
329
|
+
new_row = apply_fields_split_by_newline(new_row, config.process.split_by_newline)
|
|
335
330
|
if dict_assign_ids:
|
|
336
331
|
new_row = assign_id(new_row, dict_assign_ids, root_id_stat)
|
|
337
332
|
if dict_formats:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|