Skip to content

Commit

Permalink
Minor fixes to the atlas update workflow (#287)
Browse files Browse the repository at this point in the history
* Add space to latest atlas warning

* Disable out of date atlas warning when updating atlases

* Update brainglobe_atlasapi/bg_atlas.py

Co-authored-by: Vasco Schiavo <115561717+VascoSch92@users.noreply.github.com>

---------

Co-authored-by: Vasco Schiavo <115561717+VascoSch92@users.noreply.github.com>
  • Loading branch information
adamltyson and VascoSch92 committed May 14, 2024
1 parent eee08c6 commit 1fd95db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
37 changes: 28 additions & 9 deletions brainglobe_atlasapi/bg_atlas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tarfile
from io import StringIO
from pathlib import Path
from typing import Optional

import requests
from rich import print as rprint
Expand Down Expand Up @@ -177,23 +178,41 @@ def download_extract_file(self):

destination_path.unlink()

def check_latest_version(self):
"""Checks if the local version is the latest available
def check_latest_version(
self, print_warning: bool = True
) -> Optional[bool]:
"""
Checks if the local version is the latest available
and prompts the user to update if not.
Parameters
----------
print_warning : bool, optional
If True, prints a message if the local version is not the latest,
by default True. Useful to turn off, e.g. when the user is updating
the atlas
Returns
-------
Optional[bool]
Returns False if the local version is not the latest,
True if it is, and None if we are offline.
"""

if self.remote_version is None: # in this case, we are offline
return
local = _version_str_from_tuple(self.local_version)
online = _version_str_from_tuple(self.remote_version)

if local != online:
rprint(
f"[b][magenta2]brainglobe_atlasapi[/b]: "
f"[b]{self.atlas_name}[/b] version [b]{local}[/b]"
f"is not the latest available ([b]{online}[/b]). "
"To update the atlas run in the terminal:[/magenta2]\n"
f" [gold1]brainglobe update -a {self.atlas_name}[/gold1]"
)
if print_warning:
rprint(
"[b][magenta2]brainglobe_atlasapi[/b]: "
f"[b]{self.atlas_name}[/b] version [b]{local}[/b] "
f"is not the latest available ([b]{online}[/b]). "
"To update the atlas run in the terminal:[/magenta2]\n"
f" [gold1]brainglobe update -a {self.atlas_name}[/gold1]"
)
return False
return True

Expand Down
4 changes: 2 additions & 2 deletions brainglobe_atlasapi/update_atlases.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def update_atlas(atlas_name, force=False):
and doesn't update if that's the case.
"""

atlas = BrainGlobeAtlas(atlas_name=atlas_name)
atlas = BrainGlobeAtlas(atlas_name=atlas_name, check_latest=False)

# Check if we need to update
if not force:
if atlas.check_latest_version():
if atlas.check_latest_version(print_warning=False):
rprint(
f"[b][magenta2]brainglobe_atlasapi: {atlas.atlas_name} "
"is already updated "
Expand Down

0 comments on commit 1fd95db

Please sign in to comment.