python-table-converter 0.2.1__tar.gz → 0.2.3__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.1 → python_table_converter-0.2.3}/PKG-INFO +1 -1
- {python_table_converter-0.2.1 → python_table_converter-0.2.3}/pyproject.toml +1 -1
- python_table_converter-0.2.3/table_converter/__init__.py +2 -0
- {python_table_converter-0.2.1 → python_table_converter-0.2.3}/table_converter/core/config.py +14 -3
- {python_table_converter-0.2.1 → python_table_converter-0.2.3}/table_converter/core/convert.py +18 -14
- python_table_converter-0.2.1/table_converter/__init__.py +0 -2
- {python_table_converter-0.2.1 → python_table_converter-0.2.3}/LICENSE +0 -0
- {python_table_converter-0.2.1 → python_table_converter-0.2.3}/README.md +0 -0
- {python_table_converter-0.2.1 → python_table_converter-0.2.3}/table_converter/cli.py +0 -0
- {python_table_converter-0.2.1 → python_table_converter-0.2.3}/table_converter/commands/convert_tables.py +0 -0
{python_table_converter-0.2.1 → python_table_converter-0.2.3}/table_converter/core/config.py
RENAMED
|
@@ -12,8 +12,12 @@ type FieldMap = Mapping[str, str|FieldMap]
|
|
|
12
12
|
|
|
13
13
|
@dataclasses.dataclass
|
|
14
14
|
class ProcessConfig:
|
|
15
|
+
assign_constants: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
15
16
|
split_by_newline: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
16
17
|
|
|
18
|
+
def __setitem__(self, key, value):
|
|
19
|
+
setattr(self, key, value)
|
|
20
|
+
|
|
17
21
|
@dataclasses.dataclass
|
|
18
22
|
class Config:
|
|
19
23
|
map: FieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
@@ -53,7 +57,14 @@ def setup_config(
|
|
|
53
57
|
ic(loaded)
|
|
54
58
|
if 'map' in loaded:
|
|
55
59
|
config.map = flatten(loaded['map'])
|
|
56
|
-
if 'process' in loaded:
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
#if 'process' in loaded:
|
|
61
|
+
dict_process = loaded.get('process')
|
|
62
|
+
if isinstance(dict_process, Mapping):
|
|
63
|
+
for process_key in [
|
|
64
|
+
'assign_constants',
|
|
65
|
+
'split_by_newline',
|
|
66
|
+
]:
|
|
67
|
+
dict_subprocess = dict_process.get(process_key)
|
|
68
|
+
if isinstance(dict_subprocess, Mapping):
|
|
69
|
+
config.process[process_key] = flatten(loaded['process'][process_key])
|
|
59
70
|
return config
|
{python_table_converter-0.2.1 → python_table_converter-0.2.3}/table_converter/core/convert.py
RENAMED
|
@@ -147,15 +147,21 @@ def map_formats(
|
|
|
147
147
|
new_row = OrderedDict(row)
|
|
148
148
|
for column in dict_formats.keys():
|
|
149
149
|
template = dict_formats[column]
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
params = {}
|
|
151
|
+
params.update(row['__debug__'])
|
|
152
|
+
params.update(row)
|
|
153
|
+
formatted = None
|
|
154
|
+
while formatted is None:
|
|
155
|
+
try:
|
|
156
|
+
formatted = template.format(**params)
|
|
157
|
+
except KeyError as e:
|
|
158
|
+
#ic(e)
|
|
159
|
+
#ic(e.args)
|
|
160
|
+
#ic(e.args[0])
|
|
161
|
+
key = e.args[0]
|
|
162
|
+
params[key] = '__undefined__'
|
|
163
|
+
except:
|
|
164
|
+
raise
|
|
159
165
|
set_field_value(new_row, f'__debug__.{column}', formatted)
|
|
160
166
|
return new_row
|
|
161
167
|
|
|
@@ -245,19 +251,17 @@ def convert(
|
|
|
245
251
|
ic()
|
|
246
252
|
ic(input_files)
|
|
247
253
|
df_list = []
|
|
248
|
-
dict_constants: OrderedDict | None = None
|
|
249
254
|
dict_formats: OrderedDict | None = None
|
|
250
255
|
dict_assign_ids= None
|
|
251
256
|
root_id_stat = create_id_stat_node()
|
|
252
257
|
config = setup_config(config_path)
|
|
253
258
|
ic(config)
|
|
254
259
|
if assign_constants:
|
|
255
|
-
dict_constants = OrderedDict()
|
|
256
260
|
fields = assign_constants.split(',')
|
|
257
261
|
for field in fields:
|
|
258
262
|
if '=' in field:
|
|
259
263
|
dst, src = field.split('=')
|
|
260
|
-
|
|
264
|
+
config.process.assign_constants[dst] = src
|
|
261
265
|
else:
|
|
262
266
|
raise ValueError(f'Invalid constant assignment: {field}')
|
|
263
267
|
if assign_formats:
|
|
@@ -321,8 +325,8 @@ def convert(
|
|
|
321
325
|
new_row = OrderedDict(row)
|
|
322
326
|
set_field_value(new_row, '__debug__.__original__', orig)
|
|
323
327
|
set_field_value(new_row, '__debug__.__file__', input_file)
|
|
324
|
-
if
|
|
325
|
-
new_row = map_constants(new_row,
|
|
328
|
+
if config.process.assign_constants:
|
|
329
|
+
new_row = map_constants(new_row, config.process.assign_constants)
|
|
326
330
|
if config.map:
|
|
327
331
|
new_row = remap_columns(new_row, config.map)
|
|
328
332
|
if config.process.split_by_newline:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|