From 7cad0b98f2f957507349e648bd0c913ebfff4870 Mon Sep 17 00:00:00 2001 From: FedeClaudi Date: Wed, 7 Oct 2020 11:09:59 +0100 Subject: [PATCH 1/6] up --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 317a65ae..dc196d16 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,7 +12,7 @@ search = __version__ = "{current_version}" replace = __version__ = "{new_version}" [flake8] -ignore = E203,W503,E501,E731,C901,W291,W293,E741,F401 +ignore = E203,W503,E501,E731,C901,W291,W293,E741 max-line-length = 79 max-complexity = 18 exclude = __init__.py From 03d3dcadd06cec116e7d6d1faf91abbc71020d91 Mon Sep 17 00:00:00 2001 From: FedeClaudi Date: Wed, 7 Oct 2020 11:11:45 +0100 Subject: [PATCH 2/6] improved show atlases layout --- bg_atlasapi/list_atlases.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/bg_atlasapi/list_atlases.py b/bg_atlasapi/list_atlases.py index 340749b3..522c7f2d 100644 --- a/bg_atlasapi/list_atlases.py +++ b/bg_atlasapi/list_atlases.py @@ -1,5 +1,6 @@ -from rich.table import Table, box, Style +from rich.table import Table from rich import print as rprint +from rich.panel import Panel from bg_atlasapi import config, utils, descriptors from bg_atlasapi.bg_atlas import BrainGlobeAtlas @@ -119,13 +120,14 @@ def show_atlases(show_local_path=False): table = Table( show_header=True, header_style="bold green", - title="\n\nBrainglobe Atlases", + show_lines=True, expand=False, - box=box.ROUNDED, + box=None, ) table.add_column("Name", no_wrap=True, width=32) table.add_column("Downloaded", justify="center") + table.add_column("Updated", justify="center") table.add_column("Local version", justify="center") table.add_column("Latest version", justify="center") if show_local_path: @@ -134,25 +136,28 @@ def show_atlases(show_local_path=False): for n, (atlas, info) in enumerate(atlases.items()): if info["downloaded"]: downloaded = "[green]:heavy_check_mark:[/green]" + + if info["version"] == info["latest_version"]: + updated = "[green]:heavy_check_mark:[/green]" + else: + updated = "[red dim]x" + else: - downloaded = "[red]---[/red]" + downloaded = "" + updated = "" row = [ - "[b]" + atlas + "[/b]", + "[bold]" + atlas, downloaded, - info["version"], - info["latest_version"], + updated, + "[#c4c4c4]" + info["version"] + if "-" not in info["version"] + else "", + "[#c4c4c4]" + info["latest_version"], ] if show_local_path: row.append(info["local"]) table.add_row(*row) - - if info["updated"] is not None: - if not info["updated"]: - table.row_styles.append( - Style(color="black", bgcolor="magenta2") - ) - - rprint(table) + rprint(Panel.fit(table, width=88, title="Brainglobe Atlases",)) From 19033b82b7953be9d591707aed7925d55ad19dd5 Mon Sep 17 00:00:00 2001 From: FedeClaudi Date: Wed, 7 Oct 2020 11:12:54 +0100 Subject: [PATCH 3/6] rich progress bar --- bg_atlasapi/utils.py | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/bg_atlasapi/utils.py b/bg_atlasapi/utils.py index cf698a7e..ef4960f5 100644 --- a/bg_atlasapi/utils.py +++ b/bg_atlasapi/utils.py @@ -3,7 +3,14 @@ import requests import logging import configparser -from tqdm.auto import tqdm +from rich.progress import ( + BarColumn, + DownloadColumn, + TextColumn, + TransferSpeedColumn, + TimeRemainingColumn, + Progress, +) logging.getLogger("urllib3").setLevel(logging.WARNING) @@ -79,19 +86,35 @@ def retrieve_over_http(url, output_file_path): Full file destination for download. """ + # Make Rich progress bar + progress = Progress( + TextColumn("[bold]Downloading...", justify="right"), + BarColumn(bar_width=None), + "{task.percentage:>3.1f}%", + "•", + DownloadColumn(), + "• speed:", + TransferSpeedColumn(), + "• ETA:", + TimeRemainingColumn(), + ) + CHUNK_SIZE = 4096 response = requests.get(url, stream=True) try: - with tqdm.wrapattr( - open(output_file_path, "wb"), - "write", - miniters=1, - total=int(response.headers.get("content-length", 0)), - desc=output_file_path.name, - ) as fout: - for chunk in response.iter_content(chunk_size=CHUNK_SIZE): - fout.write(chunk) + with progress: + task_id = progress.add_task( + "download", + filename=output_file_path.name, + start=True, + total=int(response.headers.get("content-length", 0)), + ) + + with open(output_file_path, "wb") as fout: + for chunk in response.iter_content(chunk_size=CHUNK_SIZE): + fout.write(chunk) + progress.update(task_id, advance=len(chunk), refresh=True) except requests.exceptions.ConnectionError: output_file_path.unlink() From c848b58c0eef0b59d7e4e8965b8772f56b84477b Mon Sep 17 00:00:00 2001 From: FedeClaudi Date: Wed, 7 Oct 2020 11:13:30 +0100 Subject: [PATCH 4/6] requirements update --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 66cc3457..f2c6c883 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,5 @@ pandas requests meshio click -rich -tqdm>=4.46.1 +rich>=8.0.0 bg-space>=0.5.0 From 6b04d6506617907fd7d0344a6338d530d9e520b3 Mon Sep 17 00:00:00 2001 From: FedeClaudi Date: Wed, 7 Oct 2020 13:00:15 +0100 Subject: [PATCH 5/6] test --- bg_atlasapi/list_atlases.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bg_atlasapi/list_atlases.py b/bg_atlasapi/list_atlases.py index 522c7f2d..e3b669dc 100644 --- a/bg_atlasapi/list_atlases.py +++ b/bg_atlasapi/list_atlases.py @@ -110,8 +110,8 @@ def show_atlases(show_local_path=False): if atlas not in atlases.keys(): atlases[str(atlas)] = dict( downloaded=False, - local="[red]---[/red]", - version="[red]---[/red]", + local="", + version="", latest_version=str(available_atlases[atlas]), updated=None, ) From ffd8e72df251e5466c13fa9de127f0b40fc339d8 Mon Sep 17 00:00:00 2001 From: FedeClaudi Date: Wed, 7 Oct 2020 13:03:57 +0100 Subject: [PATCH 6/6] bumped black version --- .pre-commit-config.yaml | 2 +- bg_atlasapi/list_atlases.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 73b679a1..35aaac5f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/python/black - rev: 19.10b0 + rev: 20.8b1 hooks: - id: black pass_filenames: true diff --git a/bg_atlasapi/list_atlases.py b/bg_atlasapi/list_atlases.py index e3b669dc..0b0d255a 100644 --- a/bg_atlasapi/list_atlases.py +++ b/bg_atlasapi/list_atlases.py @@ -160,4 +160,10 @@ def show_atlases(show_local_path=False): row.append(info["local"]) table.add_row(*row) - rprint(Panel.fit(table, width=88, title="Brainglobe Atlases",)) + rprint( + Panel.fit( + table, + width=88, + title="Brainglobe Atlases", + ) + )