otlmow-template 0.4__tar.gz → 0.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: otlmow_template
3
- Version: 0.4
3
+ Version: 0.5
4
4
  Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>, Jasper Berton <jasperberton1@telenet.be>
5
5
  License: GNU GENERAL PUBLIC LICENSE
6
6
  Version 3, 29 June 2007
@@ -679,10 +679,11 @@ License: GNU GENERAL PUBLIC LICENSE
679
679
  Project-URL: Homepage, https://github.com/davidvlaminck/OTLMOW-Template
680
680
  Project-URL: Bug Tracker, https://github.com/davidvlaminck/OTLMOW-Template/issues
681
681
  Classifier: Programming Language :: Python :: 3
682
- Classifier: Programming Language :: Python :: 3.8
683
682
  Classifier: Programming Language :: Python :: 3.9
684
683
  Classifier: Programming Language :: Python :: 3.10
685
684
  Classifier: Programming Language :: Python :: 3.11
685
+ Classifier: Programming Language :: Python :: 3.12
686
+ Classifier: Programming Language :: Python :: 3.13
686
687
  Classifier: Operating System :: OS Independent
687
688
  Classifier: Development Status :: 5 - Production/Stable
688
689
  Classifier: Environment :: Console
@@ -693,11 +694,11 @@ Classifier: Natural Language :: Dutch
693
694
  Classifier: Topic :: Software Development
694
695
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
695
696
  Classifier: Topic :: Software Development :: Quality Assurance
696
- Requires-Python: >=3.8
697
+ Requires-Python: >=3.9
697
698
  Description-Content-Type: text/markdown
698
699
  License-File: LICENSE
699
- Requires-Dist: otlmow-converter>=0.14
700
- Requires-Dist: otlmow-modelbuilder>=0.11
700
+ Requires-Dist: otlmow-converter>=0.15
701
+ Requires-Dist: otlmow-modelbuilder>=0.24
701
702
 
702
703
  # OTLMOW-Template
703
704
  [![PyPI](https://img.shields.io/pypi/v/otlmow-template?label=latest%20release)](https://pypi.org/project/otlmow-template/)
@@ -1,10 +1,12 @@
1
+ import csv
2
+ import logging
1
3
  import ntpath
2
4
  import os
3
- import csv
4
5
  import site
5
6
  import tempfile
6
7
  from pathlib import Path
7
- from typing import List
8
+
9
+
8
10
  from openpyxl.reader.excel import load_workbook
9
11
  from openpyxl.styles import PatternFill
10
12
  from openpyxl.utils import get_column_letter
@@ -15,6 +17,7 @@ from otlmow_converter.OtlmowConverter import OtlmowConverter
15
17
  from otlmow_model.OtlmowModel.BaseClasses.BooleanField import BooleanField
16
18
  from otlmow_model.OtlmowModel.BaseClasses.KeuzelijstField import KeuzelijstField
17
19
  from otlmow_model.OtlmowModel.BaseClasses.OTLObject import dynamic_create_instance_from_uri
20
+ from otlmow_model.OtlmowModel.Helpers.generated_lists import get_hardcoded_relation_dict
18
21
  from otlmow_modelbuilder.OSLOCollector import OSLOCollector
19
22
 
20
23
  ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
@@ -37,16 +40,15 @@ class SubsetTemplateCreator:
37
40
  return collector
38
41
 
39
42
  def generate_template_from_subset(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
40
- **kwargs):
43
+ ignore_relations: bool = True, **kwargs):
41
44
  tempdir = Path(tempfile.gettempdir()) / 'temp-otlmow'
42
45
  if not tempdir.exists():
43
46
  os.makedirs(tempdir)
44
47
  test = ntpath.basename(path_to_template_file_and_extension)
45
48
  temporary_path = Path(tempdir) / test
46
- instantiated_attributes = self.generate_basic_template(path_to_subset=path_to_subset,
47
- temporary_path=temporary_path,
48
- path_to_template_file_and_extension=path_to_template_file_and_extension,
49
- **kwargs)
49
+ instantiated_attributes = self.generate_basic_template(
50
+ path_to_subset=path_to_subset, temporary_path=temporary_path, ignore_relations=ignore_relations,
51
+ path_to_template_file_and_extension=path_to_template_file_and_extension, **kwargs)
50
52
  extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
51
53
  if extension == '.xlsx':
52
54
  self.alter_excel_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
@@ -61,17 +63,21 @@ class SubsetTemplateCreator:
61
63
  **kwargs)
62
64
 
63
65
  def generate_basic_template(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
64
- temporary_path: Path, **kwargs):
66
+ temporary_path: Path, ignore_relations: bool = True, **kwargs):
65
67
  collector = self._load_collector_from_subset_path(path_to_subset=path_to_subset)
66
68
  otl_objects = []
67
69
  amount_of_examples = kwargs.get('amount_of_examples', 0)
70
+ model_directory = None
71
+ if kwargs is not None:
72
+ model_directory = kwargs.get('model_directory', None)
73
+ relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
68
74
 
69
75
  for class_object in list(filter(lambda cl: cl.abstract == 0, collector.classes)):
70
- model_directory = None
71
- if kwargs is not None:
72
- model_directory = kwargs.get('model_directory', None)
76
+ if ignore_relations and class_object.objectUri in relation_dict:
77
+ continue
78
+
73
79
  if amount_of_examples != 0:
74
- for i in range(amount_of_examples):
80
+ for _ in range(amount_of_examples):
75
81
  instance = dynamic_create_instance_from_uri(class_object.objectUri, model_directory=model_directory)
76
82
  if instance is None:
77
83
  continue
@@ -84,11 +90,8 @@ class SubsetTemplateCreator:
84
90
  instance.fill_with_dummy_data()
85
91
  otl_objects.append(instance)
86
92
 
87
- # TODO: check if this is needed, as the above line should cover this
88
- attributen = collector.find_attributes_by_class(class_object)
89
- for attribute_object in attributen:
90
- attr = getattr(instance, '_' + attribute_object.name)
91
- attr.fill_with_dummy_data()
93
+ DotnotationHelper.clear_list_of_list_attributes(instance)
94
+
92
95
  converter = OtlmowConverter()
93
96
  converter.from_objects_to_file(file_path=temporary_path,
94
97
  sequence_of_objects=otl_objects, **kwargs)
@@ -102,7 +105,7 @@ class SubsetTemplateCreator:
102
105
 
103
106
  @classmethod
104
107
  def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to_subset: Path,
105
- instantiated_attributes: List, temporary_path, **kwargs):
108
+ instantiated_attributes: list, temporary_path, **kwargs):
106
109
  generate_choice_list = kwargs.get('generate_choice_list', False)
107
110
  add_geo_artefact = kwargs.get('add_geo_artefact', False)
108
111
  add_attribute_info = kwargs.get('add_attribute_info', False)
@@ -128,7 +131,7 @@ class SubsetTemplateCreator:
128
131
  [f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
129
132
 
130
133
  def determine_multiplicity_csv(self, path_to_template_file_and_extension: Path, path_to_subset: Path,
131
- instantiated_attributes: List, temporary_path: Path, **kwargs):
134
+ instantiated_attributes: list, temporary_path: Path, **kwargs):
132
135
  path_is_split = kwargs.get('split_per_type', True)
133
136
  if path_is_split is False:
134
137
  self.alter_csv_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
@@ -148,7 +151,7 @@ class SubsetTemplateCreator:
148
151
 
149
152
  collector = cls._load_collector_from_subset_path(path_to_subset=path_to_subset)
150
153
  if list_of_otl_objectUri == []:
151
- return [x for x in collector.classes]
154
+ return collector.classes
152
155
  return [x for x in collector.classes if x.objectUri in list_of_otl_objectUri]
153
156
 
154
157
  @staticmethod
@@ -165,7 +168,7 @@ class SubsetTemplateCreator:
165
168
  sheet.column_dimensions = dim_holder
166
169
 
167
170
  @classmethod
168
- def add_attribute_info_excel(cls, workbook, instantiated_attributes: List):
171
+ def add_attribute_info_excel(cls, workbook, instantiated_attributes: list):
169
172
  dotnotation_module = DotnotationHelper()
170
173
  for sheet in workbook:
171
174
  if sheet == workbook['Keuzelijsten']:
@@ -192,7 +195,7 @@ class SubsetTemplateCreator:
192
195
  fill_type="solid")
193
196
 
194
197
  @classmethod
195
- def check_for_deprecated_attributes(cls, workbook, instantiated_attributes: List):
198
+ def check_for_deprecated_attributes(cls, workbook, instantiated_attributes: list):
196
199
  dotnotation_module = DotnotationHelper()
197
200
  for sheet in workbook:
198
201
  if sheet == workbook['Keuzelijsten']:
@@ -215,7 +218,7 @@ class SubsetTemplateCreator:
215
218
  is_deprecated = True
216
219
 
217
220
  if is_deprecated:
218
- cell.value = '[DEPRECATED] ' + cell.value
221
+ cell.value = f'[DEPRECATED] {cell.value}'
219
222
 
220
223
  @classmethod
221
224
  def find_uri_in_sheet(cls, sheet):
@@ -237,7 +240,7 @@ class SubsetTemplateCreator:
237
240
  sheet.delete_cols(cell.column)
238
241
 
239
242
  @classmethod
240
- def add_choice_list_excel(cls, workbook, instantiated_attributes: List, path_to_subset: Path):
243
+ def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_subset: Path):
241
244
  choice_list_dict = {}
242
245
  dotnotation_module = DotnotationHelper()
243
246
  for sheet in workbook:
@@ -259,17 +262,10 @@ class SubsetTemplateCreator:
259
262
  name = dotnotation_attribute.field.naam
260
263
  valid_options = [v.invulwaarde for k, v in dotnotation_attribute.field.options.items()
261
264
  if v.status != 'verwijderd']
262
- if dotnotation_attribute.field.naam in choice_list_dict:
263
- column = choice_list_dict[dotnotation_attribute.field.naam]
264
- else:
265
- choice_list_dict = cls.add_choice_list_to_sheet(workbook=workbook, name=name,
266
- options=valid_options,
267
- choice_list_dict=choice_list_dict)
268
- column = choice_list_dict[dotnotation_attribute.field.naam]
269
- print(column)
270
- option_list = []
271
- for option in valid_options:
272
- option_list.append(option)
265
+ if (dotnotation_attribute.field.naam not in choice_list_dict):
266
+ choice_list_dict = cls.add_choice_list_to_sheet(
267
+ workbook=workbook, name=name, options=valid_options, choice_list_dict=choice_list_dict)
268
+ column = choice_list_dict[dotnotation_attribute.field.naam]
273
269
  start_range = f"${column}$2"
274
270
  end_range = f"${column}${len(valid_options) + 1}"
275
271
  data_val = DataValidation(type="list", formula1=f"Keuzelijsten!{start_range}:{end_range}",
@@ -307,12 +303,11 @@ class SubsetTemplateCreator:
307
303
  instantiated_attributes, **kwargs):
308
304
  file_location = os.path.dirname(path_to_template_file_and_extension)
309
305
  tempdir = Path(tempfile.gettempdir()) / 'temp-otlmow'
310
- print(file_location)
306
+ logging.debug(file_location)
311
307
  file_name = ntpath.basename(path_to_template_file_and_extension)
312
308
  split_file_name = file_name.split('.')
313
309
  things_in_there = os.listdir(tempdir)
314
- csv_templates = [x for x in things_in_there if x.startswith(split_file_name[0] + '_')]
315
- print(csv_templates)
310
+ csv_templates = [x for x in things_in_there if x.startswith(f'{split_file_name[0]}_')]
316
311
  for file in csv_templates:
317
312
  test_template_loc = Path(os.path.dirname(path_to_template_file_and_extension)) / file
318
313
  temp_loc = Path(tempdir) / file
@@ -334,27 +329,26 @@ class SubsetTemplateCreator:
334
329
  amount_of_examples = kwargs.get('amount_of_examples', 0)
335
330
  quote_char = '"'
336
331
  with open(temporary_path, 'r+', encoding='utf-8') as csvfile:
337
- new_file = open(path_to_template_file_and_extension, 'w', encoding='utf-8')
338
- reader = csv.reader(csvfile, delimiter=delimiter, quotechar=quote_char)
339
- for row_nr, row in enumerate(reader):
340
- if row_nr == 0:
341
- header = row
342
- else:
343
- data.append(row)
344
- if add_geo_artefact is False:
345
- [header, data] = cls.remove_geo_artefact_csv(header=header, data=data)
346
- if add_attribute_info:
347
- [info, header] = cls.add_attribute_info_csv(header=header, data=data,
348
- instantiated_attributes=instantiated_attributes)
349
- new_file.write(delimiter.join(info) + '\n')
350
- data = cls.add_mock_data_csv(header=header, data=data, rows_of_examples=amount_of_examples)
351
- if highlight_deprecated_attributes:
352
- header = cls.highlight_deprecated_attributes_csv(header=header, data=data,
353
- instantiated_attributes=instantiated_attributes)
354
- new_file.write(delimiter.join(header) + '\n')
355
- for d in data:
356
- new_file.write(delimiter.join(d) + '\n')
357
- new_file.close()
332
+ with open(path_to_template_file_and_extension, 'w', encoding='utf-8') as new_file:
333
+ reader = csv.reader(csvfile, delimiter=delimiter, quotechar=quote_char)
334
+ for row_nr, row in enumerate(reader):
335
+ if row_nr == 0:
336
+ header = row
337
+ else:
338
+ data.append(row)
339
+ if add_geo_artefact is False:
340
+ [header, data] = cls.remove_geo_artefact_csv(header=header, data=data)
341
+ if add_attribute_info:
342
+ [info, header] = cls.add_attribute_info_csv(header=header, data=data,
343
+ instantiated_attributes=instantiated_attributes)
344
+ new_file.write(delimiter.join(info) + '\n')
345
+ data = cls.add_mock_data_csv(header=header, data=data, rows_of_examples=amount_of_examples)
346
+ if highlight_deprecated_attributes:
347
+ header = cls.highlight_deprecated_attributes_csv(header=header, data=data,
348
+ instantiated_attributes=instantiated_attributes)
349
+ new_file.write(delimiter.join(header) + '\n')
350
+ for d in data:
351
+ new_file.write(delimiter.join(d) + '\n')
358
352
 
359
353
  @classmethod
360
354
  def add_attribute_info_csv(cls, header, data, instantiated_attributes):
@@ -401,39 +395,35 @@ class SubsetTemplateCreator:
401
395
  for dotnototation_title in header:
402
396
  if dotnototation_title == 'typeURI':
403
397
  continue
404
- else:
405
- index = header.index(dotnototation_title)
406
- value = header[index]
407
- try:
408
- is_deprecated = False
409
- if dotnototation_title.count('.') == 1:
410
- dot_split = dotnototation_title.split('.')
411
- attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
412
- dot_split[0])
413
-
414
- if len(attribute.deprecated_version) > 0:
415
- is_deprecated = True
416
- dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
417
- dotnototation_title)
418
- if len(dotnotation_attribute.deprecated_version) > 0:
398
+
399
+ index = header.index(dotnototation_title)
400
+ value = header[index]
401
+ try:
402
+ is_deprecated = False
403
+ if dotnototation_title.count('.') == 1:
404
+ dot_split = dotnototation_title.split('.')
405
+ attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
406
+ dot_split[0])
407
+
408
+ if len(attribute.deprecated_version) > 0:
419
409
  is_deprecated = True
420
- except AttributeError:
421
- continue
422
- if is_deprecated:
423
- header[index] = "[DEPRECATED] " + value
410
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
411
+ dotnototation_title)
412
+ if len(dotnotation_attribute.deprecated_version) > 0:
413
+ is_deprecated = True
414
+ except AttributeError:
415
+ continue
416
+ if is_deprecated:
417
+ header[index] = f"[DEPRECATED] {value}"
424
418
  return header
425
419
 
426
420
  @classmethod
427
421
  def find_uri_in_csv(cls, header):
428
- filter_uri = None
429
- if 'typeURI' in header:
430
- filter_uri = header.index('typeURI')
431
- return filter_uri
422
+ return header.index('typeURI') if 'typeURI' in header else None
432
423
 
433
424
  @classmethod
434
425
  def add_choice_list_to_sheet(cls, workbook, name, options, choice_list_dict):
435
426
  active_sheet = workbook['Keuzelijsten']
436
- print(options)
437
427
  row_nr = 2
438
428
  for rows in active_sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=700):
439
429
  for cell in rows:
@@ -441,10 +431,8 @@ class SubsetTemplateCreator:
441
431
  cell.value = name
442
432
  column_nr = cell.column
443
433
  for option in options:
444
- print(option)
445
434
  active_sheet.cell(row=row_nr, column=column_nr, value=option)
446
435
  row_nr += 1
447
- print(row_nr)
448
436
  choice_list_dict[name] = get_column_letter(column_nr)
449
437
  break
450
438
  return choice_list_dict
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: otlmow_template
3
- Version: 0.4
3
+ Version: 0.5
4
4
  Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>, Jasper Berton <jasperberton1@telenet.be>
5
5
  License: GNU GENERAL PUBLIC LICENSE
6
6
  Version 3, 29 June 2007
@@ -679,10 +679,11 @@ License: GNU GENERAL PUBLIC LICENSE
679
679
  Project-URL: Homepage, https://github.com/davidvlaminck/OTLMOW-Template
680
680
  Project-URL: Bug Tracker, https://github.com/davidvlaminck/OTLMOW-Template/issues
681
681
  Classifier: Programming Language :: Python :: 3
682
- Classifier: Programming Language :: Python :: 3.8
683
682
  Classifier: Programming Language :: Python :: 3.9
684
683
  Classifier: Programming Language :: Python :: 3.10
685
684
  Classifier: Programming Language :: Python :: 3.11
685
+ Classifier: Programming Language :: Python :: 3.12
686
+ Classifier: Programming Language :: Python :: 3.13
686
687
  Classifier: Operating System :: OS Independent
687
688
  Classifier: Development Status :: 5 - Production/Stable
688
689
  Classifier: Environment :: Console
@@ -693,11 +694,11 @@ Classifier: Natural Language :: Dutch
693
694
  Classifier: Topic :: Software Development
694
695
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
695
696
  Classifier: Topic :: Software Development :: Quality Assurance
696
- Requires-Python: >=3.8
697
+ Requires-Python: >=3.9
697
698
  Description-Content-Type: text/markdown
698
699
  License-File: LICENSE
699
- Requires-Dist: otlmow-converter>=0.14
700
- Requires-Dist: otlmow-modelbuilder>=0.11
700
+ Requires-Dist: otlmow-converter>=0.15
701
+ Requires-Dist: otlmow-modelbuilder>=0.24
701
702
 
702
703
  # OTLMOW-Template
703
704
  [![PyPI](https://img.shields.io/pypi/v/otlmow-template?label=latest%20release)](https://pypi.org/project/otlmow-template/)
@@ -0,0 +1,2 @@
1
+ otlmow-converter>=0.15
2
+ otlmow-modelbuilder>=0.24
@@ -4,17 +4,18 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "otlmow_template"
7
- version = "0.4"
7
+ version = "0.5"
8
8
  authors = [{name = "David Vlaminck", email = "david.vlaminck@mow.vlaanderen.be"},
9
- {name = "Jasper Berton", email = "jasperberton1@telenet.be"}]
9
+ {name = "Jasper Berton", email = "jasperberton1@telenet.be"},]
10
10
  readme = "README.md"
11
11
  license = {file = "LICENSE"}
12
12
  classifiers = [
13
13
  "Programming Language :: Python :: 3",
14
- "Programming Language :: Python :: 3.8",
15
14
  "Programming Language :: Python :: 3.9",
16
15
  "Programming Language :: Python :: 3.10",
17
16
  "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
18
19
  "Operating System :: OS Independent",
19
20
  "Development Status :: 5 - Production/Stable",
20
21
  "Environment :: Console",
@@ -26,10 +27,10 @@ classifiers = [
26
27
  "Topic :: Software Development :: Libraries :: Python Modules",
27
28
  "Topic :: Software Development :: Quality Assurance",
28
29
  ]
29
- requires-python = ">=3.8"
30
+ requires-python = ">=3.9"
30
31
  dependencies = [
31
- 'otlmow-converter >= 0.14',
32
- 'otlmow-modelbuilder >= 0.11',
32
+ 'otlmow-converter >= 0.15',
33
+ 'otlmow-modelbuilder >= 0.24',
33
34
  ]
34
35
 
35
36
  [tool.setuptools.packages.find]
@@ -1,2 +0,0 @@
1
- otlmow-converter>=0.14
2
- otlmow-modelbuilder>=0.11
File without changes
File without changes
File without changes