Skip to content

Commit cf9d54e

Browse files
Excel to entities (#56)
* Fixed permId getter * Fixed ruff formatting * Fetched object_type headers from excel to dict * Corrected linting * First conversor from one entity excel file to dict * Minor changes * Starting to treat each entiy as individual blocks * Entities to dict by blocks finished * Added excel_to_entities to cli using fill_masterdata * Finished and working parser using CLI from masterdata excel file to python model entities * Added sorting for entities dictionary by inheritance * added checker to properties * added checker to vocabulary terms * added checker to entity headers * Checks and bug fixing, all working properly and conversion done * Added missing docstrings, comments, typings and review notes * Fied mypy checks for dict typing * Fixed mypy checks and reviewed bugs and comments * Fixed mypy checks * Fixing mypy and other extras (#61) Added str_to_bool function Fix mypy in excel_to_entities Added tmp/ to gitignore --------- Co-authored-by: Jose M. Pizarro <[email protected]>
1 parent c3d541a commit cf9d54e

File tree

4 files changed

+942
-17
lines changed

4 files changed

+942
-17
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,6 @@ pytest.xml
174174
pytest-coverage.txt
175175

176176
# artifacts
177-
artifacts
177+
artifacts
178+
# and tmp files
179+
tmp/

bam_masterdata/cli/cli.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,46 @@ def cli():
3838
it is using the value of the `OPENBIS_URL` environment variable.
3939
""",
4040
)
41-
def fill_masterdata(url):
41+
@click.option(
42+
"--excel-file",
43+
type=click.Path(exists=True, dir_okay=False),
44+
required=False,
45+
help="""
46+
(Optional) The path to the Masterdata Excel file.
47+
""",
48+
)
49+
def fill_masterdata(url, excel_file):
4250
start_time = time.time()
4351

52+
# Define output directory
53+
output_directory = (
54+
os.path.join(DATAMODEL_DIR, "tmp") if excel_file else DATAMODEL_DIR
55+
)
56+
57+
# Ensure the output directory exists
58+
os.makedirs(output_directory, exist_ok=True)
59+
60+
# Check for mutual exclusivity
61+
if excel_file and url:
62+
raise click.UsageError(
63+
"You cannot specify both --url and --excel-file. Please choose one."
64+
)
65+
4466
# ! this takes a lot of time loading all the entities in Openbis
4567
# Use the URL if provided, otherwise fall back to defaults
46-
if not url:
47-
url = environ("OPENBIS_URL")
48-
click.echo(f"Using the openBIS instance: {url}\n")
49-
generator = MasterdataCodeGenerator(url=url)
68+
if excel_file:
69+
click.echo(f"Using the Masterdata Excel file path: {excel_file}\n")
70+
generator = MasterdataCodeGenerator(path=excel_file)
71+
else:
72+
if not url:
73+
url = environ("OPENBIS_URL")
74+
click.echo(f"Using the openBIS instance: {url}\n")
75+
generator = MasterdataCodeGenerator(url=url)
5076

5177
# Add each module to the `bam_masterdata/datamodel` directory
5278
for module_name in ["property", "collection", "dataset", "object", "vocabulary"]:
5379
module_start_time = time.perf_counter() # more precise time measurement
54-
output_file = Path(os.path.join(DATAMODEL_DIR, f"{module_name}_types.py"))
80+
output_file = Path(os.path.join(output_directory, f"{module_name}_types.py"))
5581

5682
# Get the method from `MasterdataCodeGenerator`
5783
code = getattr(generator, f"generate_{module_name}_types")()

0 commit comments

Comments
 (0)