Skip to content

Commit

Permalink
Formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Nov 27, 2024
1 parent 5d0d1e8 commit e7b006d
Show file tree
Hide file tree
Showing 4 changed files with 550 additions and 317 deletions.
27 changes: 18 additions & 9 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,30 @@ def store_library_content(
"""
hash_checksum = sha256(library_content)
if hash_checksum in StoredLibrary.HASH_CHECKSUM_SET:
return None # We do not store the library if its hash checksum is in the database.
return None # We do not store the library if its hash checksum is in the database.
try:
library_data = yaml.safe_load(library_content)
if not isinstance(library_data, dict):
return ("LibraryErrorBadType", {
"value": repr(library_data)[:100]
"type": type(library_data).__name__,
"expected_type": "dict"
}, [])
return (
"LibraryErrorBadType",
{
"value": repr(library_data)[:100],
"type": type(library_data).__name__,
"expected_type": "dict",
},
[],
)
except yaml.YAMLError as e:
logger.error("Error while loading library content", error=e)
return ("LibraryErrorInvalidYamlFormat", {}, [])

from library.utils import LibraryFormatChecker # Should this really be imported within the function ?
from library.utils import (
LibraryFormatChecker,
) # Should this really be imported within the function ?

library_format_checker = LibraryFormatChecker(library_data)
error_msg = library_format_checker.run()
if error_msg is not None :
if error_msg is not None:
return error_msg

urn = library_data["urn"].lower()
Expand Down Expand Up @@ -342,7 +349,9 @@ def store_library_file(
return StoredLibrary.store_library_content(library_content, builtin)

def load(self) -> Union[str, None]:
from library.utils import LibraryImporter # Should this really be imported within the function ?
from library.utils import (
LibraryImporter,
) # Should this really be imported within the function ?

if LoadedLibrary.objects.filter(urn=self.urn, locale=self.locale):
return "This library has already been loaded."
Expand Down
Loading

0 comments on commit e7b006d

Please sign in to comment.