Skip to content

Commit 4d5900f

Browse files
carlosmada22JosePizarro3
authored andcommitted
Fixed mypy checks and reviewed bugs and comments
1 parent 84c6ebb commit 4d5900f

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

bam_masterdata/cli/cli.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,28 @@ def cli():
4646
(Optional) The path to the Masterdata Excel file.
4747
""",
4848
)
49-
def fill_masterdata(url, path):
49+
def fill_masterdata(url, excel_file):
5050
start_time = time.time()
5151

5252
# Define output directory
53-
output_directory = os.path.join(DATAMODEL_DIR, "tmp") if path else DATAMODEL_DIR
53+
output_directory = (
54+
os.path.join(DATAMODEL_DIR, "tmp") if excel_file else DATAMODEL_DIR
55+
)
5456

5557
# Ensure the output directory exists
5658
os.makedirs(output_directory, exist_ok=True)
5759

5860
# Check for mutual exclusivity
59-
if path and url:
61+
if excel_file and url:
6062
raise click.UsageError(
61-
"You cannot specify both --url and --path. Please choose one."
63+
"You cannot specify both --url and --excel-file. Please choose one."
6264
)
6365

6466
# ! this takes a lot of time loading all the entities in Openbis
6567
# Use the URL if provided, otherwise fall back to defaults
66-
if path:
67-
click.echo(f"Using the Masterdata Excel file path: {path}\n")
68-
generator = MasterdataCodeGenerator(path=path)
68+
if excel_file:
69+
click.echo(f"Using the Masterdata Excel file path: {excel_file}\n")
70+
generator = MasterdataCodeGenerator(path=excel_file)
6971
else:
7072
if not url:
7173
url = environ("OPENBIS_URL")

bam_masterdata/cli/excel_to_entities.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def properties_to_dict(
177177
# Check the cell below "Mandatory"
178178
elif term == "Mandatory":
179179
for cell in sheet[term_letter][header_index:last_non_empty_row]:
180-
mandatory = cell.value
180+
mandatory = str(cell.value)
181181
if mandatory is not None:
182182
mandatory = mandatory.strip().lower()
183183
if mandatory not in {"true", "false"}:
@@ -192,7 +192,7 @@ def properties_to_dict(
192192
# Check the cell below "Show in edit views"
193193
elif term == "Show in edit views":
194194
for cell in sheet[term_letter][header_index:last_non_empty_row]:
195-
show = cell.value
195+
show = str(cell.value)
196196
if show is not None:
197197
show = show.strip().lower()
198198
if show not in {"true", "false"}:
@@ -307,12 +307,11 @@ def terms_to_dict(
307307

308308
for term in expected_terms:
309309
if term not in row_headers:
310-
print(f"Warning: '{term}' not found in the properties headers.")
310+
logger.warning(f"{term} not found in the properties headers.")
311311
else:
312312
# Find the index of the term in the row
313313
term_index = row_headers.index(term) + 1
314314
term_letter = index_to_excel_column(term_index)
315-
# print(term_index)
316315

317316
# Check the column below "Code"
318317
if term == "Code":
@@ -366,7 +365,7 @@ def terms_to_dict(
366365
# Check the cell below "Officials"
367366
elif term == "Official":
368367
for cell in sheet[term_letter][header_index:last_non_empty_row]:
369-
official = cell.value
368+
official = str(cell.value)
370369
official = official.strip().lower()
371370
if official is not None:
372371
if official not in {"true", "false"}:
@@ -408,7 +407,7 @@ def block_to_entity_dict(
408407
Returns:
409408
A dictionary containing the entity attributes.
410409
"""
411-
attributes_dict = {}
410+
attributes_dict: dict[str, Any] = {}
412411

413412
# Get the entity type from the specified cell
414413
entity_type_position = f"A{start_index_row}"
@@ -429,7 +428,7 @@ def block_to_entity_dict(
429428

430429
# Check if the entity type is valid
431430
if entity_type not in entity_types:
432-
print(
431+
logger.error(
433432
"The entity type (cell A1) should be one of the following: SAMPLE_TYPE/OBJECT_TYPE, EXPERIMENT_TYPE/COLLECTION_TYPE, DATASET_TYPE, PROPERTY_TYPE, VOCABULARY_TYPE"
434433
)
435434
else:
@@ -504,9 +503,11 @@ def block_to_entity_dict(
504503

505504
# Check the cell below "Auto generate codes"
506505
elif term == "Auto generate codes":
507-
auto_generate_value = sheet.cell(
508-
row=start_index_row + 2, column=term_index + 1
509-
).value
506+
auto_generate_value = str(
507+
sheet.cell(
508+
row=start_index_row + 2, column=term_index + 1
509+
).value
510+
)
510511
auto_generate_value = auto_generate_value.strip().lower()
511512
if auto_generate_value not in {"true", "false"}:
512513
logger.error(
@@ -600,7 +601,7 @@ def block_to_entity_dict(
600601
]
601602
for term in expected_terms:
602603
if term not in header_terms:
603-
print(f"Error: '{term}' not found in the second row.")
604+
logger.error(f"{term} not found in the second row.")
604605
else:
605606
# Find the index of the term in the second row
606607
term_index = header_terms.index(term)
@@ -718,7 +719,7 @@ def block_to_entity_dict(
718719
expected_terms = ["Code", "Description", "Url template"]
719720
for term in expected_terms:
720721
if term not in header_terms:
721-
print(f"Error: '{term}' not found in the second row.")
722+
logger.error(f"{term} not found in the second row.")
722723
else:
723724
# Find the index of the term in the second row
724725
term_index = header_terms.index(term)
@@ -812,11 +813,11 @@ def excel_to_entities(
812813
# Check if we've reached the end of the sheet or found two consecutive empty rows
813814
if last_non_empty_row is None:
814815
if i == len(sheet_names) - 1: # Check if it's the last sheet
815-
print(
816+
logger.info(
816817
f"Last sheet {sheet_name} processed. End of the file reached."
817818
)
818819
else:
819-
print(
820+
logger.info(
820821
f"End of the current sheet {sheet_name} reached. Switching to next sheet..."
821822
)
822823
break
@@ -840,11 +841,11 @@ def excel_to_entities(
840841
for col in range(1, sheet.max_column + 1)
841842
):
842843
if i == len(sheet_names) - 1: # Check if it's the last sheet
843-
print(
844+
logger.info(
844845
f"Last sheet {sheet_name} processed. End of the file reached."
845846
)
846847
else:
847-
print(
848+
logger.info(
848849
f"End of the current sheet {sheet_name} reached. Switching to next sheet..."
849850
)
850851
break

0 commit comments

Comments
 (0)