Skip to content

Commit

Permalink
Fix export_to_excel cli
Browse files Browse the repository at this point in the history
Fix cls_name in entities.py
  • Loading branch information
JosePizarro3 committed Jan 9, 2025
1 parent 7cf3729 commit a508e31
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/.venv/bin/bam_masterdata",
"justMyCode": false,
"args": ["export-entities-to-json"]
"args": ["export_to_json"]
},
{
"name": "BM export-to-excel",
Expand All @@ -66,7 +66,7 @@
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/.venv/bin/bam_masterdata",
"justMyCode": false,
"args": ["export-entities-to-excel"]
"args": ["export_to_excel"]
},
]
},
Expand Down
5 changes: 3 additions & 2 deletions bam_masterdata/cli/entities_to_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def entities_to_excel(
val = getattr(obj, f_set)
row.append(val)
worksheet.append(row)
worksheet.append([""]) # empty row after entity definitions
return None

# All other datamodel modules
Expand All @@ -69,8 +70,8 @@ def entities_to_excel(
]
worksheet.append(header_values)

# Properties assignment for ObjectType
if obj_instance.cls_name == "ObjectType":
# Properties assignment for ObjectType, DatasetType, and CollectionType
if obj_instance.cls_name in ["ObjectType", "DatasetType", "CollectionType"]:
if not obj_instance.properties:
continue
worksheet.append(obj_instance.properties[0].excel_headers)
Expand Down
5 changes: 4 additions & 1 deletion bam_masterdata/datamodel/collection_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from bam_masterdata.metadata.definitions import CollectionTypeDef, PropertyTypeAssignment
from bam_masterdata.metadata.definitions import (
CollectionTypeDef,
PropertyTypeAssignment,
)
from bam_masterdata.metadata.entities import CollectionType


Expand Down
31 changes: 28 additions & 3 deletions bam_masterdata/metadata/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def to_dict(self) -> dict:
@property
def cls_name(self) -> str:
"""
Returns the entity name of the class as a string to speed up checks.
Returns the entity name of the class as a string to speed up checks. This is a property
to be overwritten by each of the abstract entity types.
"""
return self.__class__.__name__

Expand Down Expand Up @@ -108,6 +109,13 @@ def model_validator_after_init(cls, data: Any) -> Any:

return data

@property
def cls_name(self) -> str:
"""
Returns the entity name of the class as a string.
"""
return "ObjectType"


class VocabularyType(BaseEntity):
"""
Expand Down Expand Up @@ -147,10 +155,27 @@ def model_validator_after_init(cls, data: Any) -> Any:

return data

@property
def cls_name(self) -> str:
"""
Returns the entity name of the class as a string.
"""
return "VocabularyType"


class CollectionType(ObjectType):
pass
@property
def cls_name(self) -> str:
"""
Returns the entity name of the class as a string.
"""
return "CollectionType"


class DatasetType(ObjectType):
pass
@property
def cls_name(self) -> str:
"""
Returns the entity name of the class as a string.
"""
return "DatasetType"

1 comment on commit a508e31

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
bam_masterdata
   logger.py80100% 
bam_masterdata/cli
   cli.py362222 39%
   entities_to_excel.py5433 94%
   entities_to_json.py3655 86%
bam_masterdata/datamodel
   collection_types.py370100% 
   dataset_types.py184184184 0%
   object_types.py15150100% 
   property_types.py8000100% 
   vocabulary_types.py137210100% 
bam_masterdata/metadata
   definitions.py770100% 
   entities.py5433 94%
bam_masterdata/openbis
   get_entities.py525252 0%
   login.py777 0%
bam_masterdata/utils
   utils.py3366 82%
TOTAL1661428298% 

Tests Skipped Failures Errors Time
57 1 💤 0 ❌ 0 🔥 16.514s ⏱️

Please sign in to comment.