otlmow-template 0.4__tar.gz → 0.6__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.6
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,7 +17,9 @@ 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
22
+ from otlmow_modelbuilder.SQLDataClasses.OSLOClass import OSLOClass
19
23
 
20
24
  ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
21
25
 
@@ -37,16 +41,15 @@ class SubsetTemplateCreator:
37
41
  return collector
38
42
 
39
43
  def generate_template_from_subset(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
40
- **kwargs):
44
+ ignore_relations: bool = True, **kwargs):
41
45
  tempdir = Path(tempfile.gettempdir()) / 'temp-otlmow'
42
46
  if not tempdir.exists():
43
47
  os.makedirs(tempdir)
44
48
  test = ntpath.basename(path_to_template_file_and_extension)
45
49
  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)
50
+ instantiated_attributes = self.generate_basic_template(
51
+ path_to_subset=path_to_subset, temporary_path=temporary_path, ignore_relations=ignore_relations,
52
+ path_to_template_file_and_extension=path_to_template_file_and_extension, **kwargs)
50
53
  extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
51
54
  if extension == '.xlsx':
52
55
  self.alter_excel_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
@@ -61,17 +64,25 @@ class SubsetTemplateCreator:
61
64
  **kwargs)
62
65
 
63
66
  def generate_basic_template(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
64
- temporary_path: Path, **kwargs):
65
- collector = self._load_collector_from_subset_path(path_to_subset=path_to_subset)
67
+ temporary_path: Path, ignore_relations: bool = True, **kwargs):
68
+ list_of_otl_objectUri = None
69
+ if kwargs is not None:
70
+ list_of_otl_objectUri = kwargs.get('list_of_otl_objectUri', None)
71
+ filtered_class_list = self.filters_classes_by_subset(
72
+ path_to_subset=path_to_subset, list_of_otl_objectUri=list_of_otl_objectUri)
66
73
  otl_objects = []
67
74
  amount_of_examples = kwargs.get('amount_of_examples', 0)
75
+ model_directory = None
76
+ if kwargs is not None:
77
+ model_directory = kwargs.get('model_directory', None)
78
+ relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
79
+
80
+ for class_object in [cl for cl in filtered_class_list if cl.abstract == 0]:
81
+ if ignore_relations and class_object.objectUri in relation_dict:
82
+ continue
68
83
 
69
- 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)
73
84
  if amount_of_examples != 0:
74
- for i in range(amount_of_examples):
85
+ for _ in range(amount_of_examples):
75
86
  instance = dynamic_create_instance_from_uri(class_object.objectUri, model_directory=model_directory)
76
87
  if instance is None:
77
88
  continue
@@ -84,11 +95,8 @@ class SubsetTemplateCreator:
84
95
  instance.fill_with_dummy_data()
85
96
  otl_objects.append(instance)
86
97
 
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()
98
+ DotnotationHelper.clear_list_of_list_attributes(instance)
99
+
92
100
  converter = OtlmowConverter()
93
101
  converter.from_objects_to_file(file_path=temporary_path,
94
102
  sequence_of_objects=otl_objects, **kwargs)
@@ -102,7 +110,7 @@ class SubsetTemplateCreator:
102
110
 
103
111
  @classmethod
104
112
  def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to_subset: Path,
105
- instantiated_attributes: List, temporary_path, **kwargs):
113
+ instantiated_attributes: list, temporary_path, **kwargs):
106
114
  generate_choice_list = kwargs.get('generate_choice_list', False)
107
115
  add_geo_artefact = kwargs.get('add_geo_artefact', False)
108
116
  add_attribute_info = kwargs.get('add_attribute_info', False)
@@ -128,7 +136,7 @@ class SubsetTemplateCreator:
128
136
  [f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
129
137
 
130
138
  def determine_multiplicity_csv(self, path_to_template_file_and_extension: Path, path_to_subset: Path,
131
- instantiated_attributes: List, temporary_path: Path, **kwargs):
139
+ instantiated_attributes: list, temporary_path: Path, **kwargs):
132
140
  path_is_split = kwargs.get('split_per_type', True)
133
141
  if path_is_split is False:
134
142
  self.alter_csv_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
@@ -142,13 +150,13 @@ class SubsetTemplateCreator:
142
150
  [f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
143
151
 
144
152
  @classmethod
145
- def filters_assets_by_subset(cls, path_to_subset: Path, list_of_otl_objectUri: [str] = None):
153
+ def filters_classes_by_subset(cls, path_to_subset: Path, list_of_otl_objectUri: [str] = None) -> list[OSLOClass]:
146
154
  if list_of_otl_objectUri is None:
147
155
  list_of_otl_objectUri = []
148
156
 
149
157
  collector = cls._load_collector_from_subset_path(path_to_subset=path_to_subset)
150
158
  if list_of_otl_objectUri == []:
151
- return [x for x in collector.classes]
159
+ return collector.classes
152
160
  return [x for x in collector.classes if x.objectUri in list_of_otl_objectUri]
153
161
 
154
162
  @staticmethod
@@ -165,7 +173,7 @@ class SubsetTemplateCreator:
165
173
  sheet.column_dimensions = dim_holder
166
174
 
167
175
  @classmethod
168
- def add_attribute_info_excel(cls, workbook, instantiated_attributes: List):
176
+ def add_attribute_info_excel(cls, workbook, instantiated_attributes: list):
169
177
  dotnotation_module = DotnotationHelper()
170
178
  for sheet in workbook:
171
179
  if sheet == workbook['Keuzelijsten']:
@@ -192,7 +200,7 @@ class SubsetTemplateCreator:
192
200
  fill_type="solid")
193
201
 
194
202
  @classmethod
195
- def check_for_deprecated_attributes(cls, workbook, instantiated_attributes: List):
203
+ def check_for_deprecated_attributes(cls, workbook, instantiated_attributes: list):
196
204
  dotnotation_module = DotnotationHelper()
197
205
  for sheet in workbook:
198
206
  if sheet == workbook['Keuzelijsten']:
@@ -215,7 +223,7 @@ class SubsetTemplateCreator:
215
223
  is_deprecated = True
216
224
 
217
225
  if is_deprecated:
218
- cell.value = '[DEPRECATED] ' + cell.value
226
+ cell.value = f'[DEPRECATED] {cell.value}'
219
227
 
220
228
  @classmethod
221
229
  def find_uri_in_sheet(cls, sheet):
@@ -237,7 +245,7 @@ class SubsetTemplateCreator:
237
245
  sheet.delete_cols(cell.column)
238
246
 
239
247
  @classmethod
240
- def add_choice_list_excel(cls, workbook, instantiated_attributes: List, path_to_subset: Path):
248
+ def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_subset: Path):
241
249
  choice_list_dict = {}
242
250
  dotnotation_module = DotnotationHelper()
243
251
  for sheet in workbook:
@@ -259,17 +267,10 @@ class SubsetTemplateCreator:
259
267
  name = dotnotation_attribute.field.naam
260
268
  valid_options = [v.invulwaarde for k, v in dotnotation_attribute.field.options.items()
261
269
  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)
270
+ if (dotnotation_attribute.field.naam not in choice_list_dict):
271
+ choice_list_dict = cls.add_choice_list_to_sheet(
272
+ workbook=workbook, name=name, options=valid_options, choice_list_dict=choice_list_dict)
273
+ column = choice_list_dict[dotnotation_attribute.field.naam]
273
274
  start_range = f"${column}$2"
274
275
  end_range = f"${column}${len(valid_options) + 1}"
275
276
  data_val = DataValidation(type="list", formula1=f"Keuzelijsten!{start_range}:{end_range}",
@@ -307,12 +308,11 @@ class SubsetTemplateCreator:
307
308
  instantiated_attributes, **kwargs):
308
309
  file_location = os.path.dirname(path_to_template_file_and_extension)
309
310
  tempdir = Path(tempfile.gettempdir()) / 'temp-otlmow'
310
- print(file_location)
311
+ logging.debug(file_location)
311
312
  file_name = ntpath.basename(path_to_template_file_and_extension)
312
313
  split_file_name = file_name.split('.')
313
314
  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)
315
+ csv_templates = [x for x in things_in_there if x.startswith(f'{split_file_name[0]}_')]
316
316
  for file in csv_templates:
317
317
  test_template_loc = Path(os.path.dirname(path_to_template_file_and_extension)) / file
318
318
  temp_loc = Path(tempdir) / file
@@ -334,27 +334,26 @@ class SubsetTemplateCreator:
334
334
  amount_of_examples = kwargs.get('amount_of_examples', 0)
335
335
  quote_char = '"'
336
336
  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()
337
+ with open(path_to_template_file_and_extension, 'w', encoding='utf-8') as new_file:
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')
358
357
 
359
358
  @classmethod
360
359
  def add_attribute_info_csv(cls, header, data, instantiated_attributes):
@@ -401,39 +400,35 @@ class SubsetTemplateCreator:
401
400
  for dotnototation_title in header:
402
401
  if dotnototation_title == 'typeURI':
403
402
  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:
403
+
404
+ index = header.index(dotnototation_title)
405
+ value = header[index]
406
+ try:
407
+ is_deprecated = False
408
+ if dotnototation_title.count('.') == 1:
409
+ dot_split = dotnototation_title.split('.')
410
+ attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
411
+ dot_split[0])
412
+
413
+ if len(attribute.deprecated_version) > 0:
419
414
  is_deprecated = True
420
- except AttributeError:
421
- continue
422
- if is_deprecated:
423
- header[index] = "[DEPRECATED] " + value
415
+ dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_object,
416
+ dotnototation_title)
417
+ if len(dotnotation_attribute.deprecated_version) > 0:
418
+ is_deprecated = True
419
+ except AttributeError:
420
+ continue
421
+ if is_deprecated:
422
+ header[index] = f"[DEPRECATED] {value}"
424
423
  return header
425
424
 
426
425
  @classmethod
427
426
  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
427
+ return header.index('typeURI') if 'typeURI' in header else None
432
428
 
433
429
  @classmethod
434
430
  def add_choice_list_to_sheet(cls, workbook, name, options, choice_list_dict):
435
431
  active_sheet = workbook['Keuzelijsten']
436
- print(options)
437
432
  row_nr = 2
438
433
  for rows in active_sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=700):
439
434
  for cell in rows:
@@ -441,10 +436,8 @@ class SubsetTemplateCreator:
441
436
  cell.value = name
442
437
  column_nr = cell.column
443
438
  for option in options:
444
- print(option)
445
439
  active_sheet.cell(row=row_nr, column=column_nr, value=option)
446
440
  row_nr += 1
447
- print(row_nr)
448
441
  choice_list_dict[name] = get_column_letter(column_nr)
449
442
  break
450
443
  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.6
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.6"
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