Skip to content

Commit

Permalink
force=true in case of updating cads-catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
alex75 committed Aug 10, 2023
1 parent b3995cd commit 9039a15
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions cads_catalogue/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def update_catalogue(
# check if source folders have changed from last registered update
(
is_db_to_update,
did_catalogue_repo_change,
catalogue_hash,
metadata_hash,
licence_hash,
Expand All @@ -219,6 +220,8 @@ def update_catalogue(
messages_folder_path,
cim_folder_path,
)
if did_catalogue_repo_change:
force = True
if not force and not is_db_to_update:
logger.info(
"catalogue update skipped: source files have not changed. "
Expand Down
18 changes: 12 additions & 6 deletions cads_catalogue/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ def is_db_to_update(
messages_folder_path: str | pathlib.Path,
cim_folder_path: str | pathlib.Path,
) -> Tuple[
bool, Optional[str], Optional[str], Optional[str], Optional[str], Optional[str]
bool,
bool,
Optional[str],
Optional[str],
Optional[str],
Optional[str],
Optional[str],
]:
"""
Compare current and last run's status of repo folders and return if the database is to update.
Compare current and last run's status of repo folders and return information if the database is to update.
Parameters
----------
Expand All @@ -89,7 +95,7 @@ def is_db_to_update(
Returns
-------
(True or False | hash for resources, hash for licences)
(did_input_folders_change, did_catalogue_source_change, *last_commit_hashes)
"""
current_hashes = [None, None, None, None, None]

Expand Down Expand Up @@ -121,7 +127,7 @@ def is_db_to_update(
if not last_update_record:
logger.warning("table catalogue_updates is currently empty")
is_to_update = True
return is_to_update, *current_hashes # type: ignore
return is_to_update, True, *current_hashes # type: ignore
for i, last_hash_attr in enumerate(
[
"catalogue_repo_commit",
Expand Down Expand Up @@ -154,8 +160,8 @@ def is_db_to_update(
is_to_update = (
last_hashes == [None, None, None, None, None] or last_hashes != current_hashes
)

return is_to_update, *current_hashes # type: ignore
did_catalogue_source_change = last_hashes[0] != current_hashes[0]
return is_to_update, did_catalogue_source_change, *current_hashes # type: ignore


def is_resource_to_update(session, resource_folder_path):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_40_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def test_is_db_to_update(
licences_folder_path,
messages_folder_path,
cim_folder_path,
) == (True, *folder_commit_hashes)
# insert a catalogue update with the folder commit hashes
) == (True, True, *folder_commit_hashes)
# insert a db update with the folder commit hashes
new_record = database.CatalogueUpdate(
catalogue_repo_commit=folder_commit_hashes[0],
metadata_repo_commit=folder_commit_hashes[1],
Expand All @@ -81,7 +81,7 @@ def test_is_db_to_update(
licences_folder_path,
messages_folder_path,
cim_folder_path,
) == (False, *folder_commit_hashes)
) == (False, False, *folder_commit_hashes)
# simulate only stored cads-catalogue hash was different
session.execute(sa.delete(database.CatalogueUpdate))
new_record = database.CatalogueUpdate(
Expand All @@ -99,7 +99,7 @@ def test_is_db_to_update(
licences_folder_path,
messages_folder_path,
cim_folder_path,
) == (True, *folder_commit_hashes)
) == (True, True, *folder_commit_hashes)


def test_load_resource_for_object_storage() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_90_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def test_update_catalogue(
session.execute(
sa.update(database.CatalogueUpdate).values(
**{
"catalogue_repo_commit": "aaa",
"metadata_repo_commit": "aaa",
"licence_repo_commit": "bbb",
"message_repo_commit": "ccc",
}
Expand Down

0 comments on commit 9039a15

Please sign in to comment.