Skip to content

Commit

Permalink
Remove tqdm dependency; use click.proggressbar instead
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeopti committed Aug 11, 2021
1 parent def4808 commit f757591
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
37 changes: 19 additions & 18 deletions docs/_static/example-ingestion-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import glob

import tqdm
import click
import boto3
s3 = boto3.resource('s3')

Expand Down Expand Up @@ -36,29 +36,30 @@

available_datasets = driver.get_datasets()
raster_files = list(glob.glob(RASTER_GLOB))
pbar = tqdm.tqdm(raster_files)

for raster_path in pbar:
pbar.set_postfix(file=raster_path)
with click.progressbar(raster_files) as pbar:

raster_filename = os.path.basename(raster_path)
for raster_path in pbar:
pbar.set_postfix(file=raster_path)

# extract keys from filename
match = re.match(RASTER_NAME_PATTERN, raster_filename)
if match is None:
raise ValueError(f'Input file {raster_filename} does not match raster pattern')
raster_filename = os.path.basename(raster_path)

keys = match.groups()
# extract keys from filename
match = re.match(RASTER_NAME_PATTERN, raster_filename)
if match is None:
raise ValueError(f'Input file {raster_filename} does not match raster pattern')

# skip already processed data
if keys in available_datasets:
continue
keys = match.groups()

with driver.connect():
# since the rasters will be served from S3, we need to pass the correct remote path
driver.insert(keys, raster_path, override_path=f'{S3_PATH}/{raster_filename}')
s3.meta.client.upload_file(raster_path, S3_BUCKET,
f'{S3_RASTER_FOLDER}/{raster_filename}')
# skip already processed data
if keys in available_datasets:
continue

with driver.connect():
# since the rasters will be served from S3, we need to pass the correct remote path
driver.insert(keys, raster_path, override_path=f'{S3_PATH}/{raster_filename}')
s3.meta.client.upload_file(raster_path, S3_BUCKET,
f'{S3_RASTER_FOLDER}/{raster_filename}')

# upload database to S3
s3.meta.client.upload_file(DB_NAME, S3_BUCKET, DB_NAME)
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
'shapely',
'rasterio>=1.0,<=1.1.8', # TODO: unpin when performance issues with GDAL3 are fixed
'shapely',
'toml',
'tqdm'
'toml'
],
extras_require={
'test': [
Expand Down
7 changes: 3 additions & 4 deletions terracotta/scripts/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging

import click
import tqdm

from terracotta.scripts.click_types import RasterPattern, RasterPatternType, PathlibPath

Expand Down Expand Up @@ -83,7 +82,7 @@ def push_to_last(seq: Sequence[Any], index: int) -> Tuple[Any, ...]:
)
click.Abort()

with driver.connect():
progress = tqdm.tqdm(raster_files.items(), desc='Ingesting raster files', disable=quiet)
for key, filepath in progress:
with driver.connect(), click.progressbar(raster_files.items(),
label='Ingesting raster files') as bar:
for key, filepath in bar:
driver.insert(key, filepath, skip_metadata=skip_metadata)
6 changes: 3 additions & 3 deletions terracotta/scripts/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import logging

import click
import tqdm

from terracotta.scripts.click_types import RasterPattern, RasterPatternType
from terracotta.scripts.http_utils import find_open_port
Expand Down Expand Up @@ -81,9 +80,10 @@ def push_to_last(seq: Sequence[Any], index: int) -> Tuple[Any, ...]:
driver = get_driver(dbfile.name, provider='sqlite')
driver.create(keys)

with driver.connect():
with driver.connect(), click.progressbar(raster_files.items(),
label='Ingesting raster files') as bar:
click.echo('')
for key, filepath in tqdm.tqdm(raster_files.items(), desc="Ingesting raster files"):
for key, filepath in bar:
driver.insert(key, filepath, skip_metadata=True)
click.echo('')

Expand Down

0 comments on commit f757591

Please sign in to comment.