diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 509349ef..cc13e4a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,10 @@ repos: + - + repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.21 + hooks: + - id: isort + language_version: python3.7 - repo: 'https://github.com/psf/black' rev: stable diff --git a/README.md b/README.md index 0af22036..21e25ad1 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ $ pip install -e .[dev] **Python >=3.7 only** -This repo is set to use `pre-commit` to run *flake8*, *pydocstring*, *black* ("uncompromising Python code formatter") and mypy when committing new code. +This repo is set to use `pre-commit` to run *isort*, *flake8*, *pydocstring*, *black* ("uncompromising Python code formatter") and mypy when committing new code. ``` $ pre-commit install @@ -249,6 +249,7 @@ $ pre-commit install $ git add . $ git commit -m'my change' +isort....................................................................Passed black....................................................................Passed Flake8...................................................................Passed Verifying PEP257 Compliance..............................................Passed diff --git a/cogeo_mosaic/backends/base.py b/cogeo_mosaic/backends/base.py index d907cdd3..a0a47195 100644 --- a/cogeo_mosaic/backends/base.py +++ b/cogeo_mosaic/backends/base.py @@ -1,13 +1,13 @@ """cogeo_mosaic.backend.base: base Backend class.""" -from typing import Dict, List, Sequence - import abc from contextlib import AbstractContextManager +from typing import Dict, List, Sequence import mercantile -from cogeo_mosaic.mosaic import MosaicJSON + from cogeo_mosaic.backends.utils import get_hash +from cogeo_mosaic.mosaic import MosaicJSON from cogeo_mosaic.utils import bbox_union diff --git a/cogeo_mosaic/backends/dynamodb.py b/cogeo_mosaic/backends/dynamodb.py index 8f771bee..f714ca5b 100644 --- a/cogeo_mosaic/backends/dynamodb.py +++ b/cogeo_mosaic/backends/dynamodb.py @@ -1,7 +1,5 @@ """cogeo-mosaic AWS DynamoDB backend.""" -from typing import Any, Dict, List, Optional, Union, Sequence - import functools import itertools import json @@ -9,6 +7,7 @@ import sys import warnings from decimal import Decimal +from typing import Any, Dict, List, Optional, Sequence, Union import boto3 import click diff --git a/cogeo_mosaic/backends/file.py b/cogeo_mosaic/backends/file.py index 85fc9eba..84725e02 100644 --- a/cogeo_mosaic/backends/file.py +++ b/cogeo_mosaic/backends/file.py @@ -1,19 +1,18 @@ """cogeo-mosaic File backend.""" -from typing import Any, Dict, List, Optional, Union - -import json import functools +import json +from typing import Any, Dict, List, Optional, Union import mercantile -from cogeo_mosaic.mosaic import MosaicJSON from cogeo_mosaic.backends.base import BaseBackend from cogeo_mosaic.backends.utils import ( _compress_gz_json, _decompress_gz, get_assets_from_json, ) +from cogeo_mosaic.mosaic import MosaicJSON class FileBackend(BaseBackend): diff --git a/cogeo_mosaic/backends/http.py b/cogeo_mosaic/backends/http.py index c0ee52cc..b9b8ad87 100644 --- a/cogeo_mosaic/backends/http.py +++ b/cogeo_mosaic/backends/http.py @@ -1,16 +1,15 @@ """cogeo-mosaic HTTP backend.""" -from typing import Any, Dict, List, Optional, Union - -import json import functools +import json +from typing import Any, Dict, List, Optional, Union -import requests import mercantile +import requests -from cogeo_mosaic.mosaic import MosaicJSON from cogeo_mosaic.backends.base import BaseBackend from cogeo_mosaic.backends.utils import _decompress_gz, get_assets_from_json +from cogeo_mosaic.mosaic import MosaicJSON class HttpBackend(BaseBackend): diff --git a/cogeo_mosaic/backends/s3.py b/cogeo_mosaic/backends/s3.py index 66e15b41..fdb3b8a0 100644 --- a/cogeo_mosaic/backends/s3.py +++ b/cogeo_mosaic/backends/s3.py @@ -1,21 +1,19 @@ """cogeo-mosaic AWS S3 backend.""" -from typing import Any, Dict, List, Optional, Union - -import json import functools +import json +from typing import Any, Dict, List, Optional, Union import mercantile - from boto3.session import Session as boto3_session -from cogeo_mosaic.mosaic import MosaicJSON from cogeo_mosaic.backends.base import BaseBackend from cogeo_mosaic.backends.utils import ( _compress_gz_json, _decompress_gz, get_assets_from_json, ) +from cogeo_mosaic.mosaic import MosaicJSON class S3Backend(BaseBackend): diff --git a/cogeo_mosaic/backends/utils.py b/cogeo_mosaic/backends/utils.py index c137aaad..c0a40b6a 100644 --- a/cogeo_mosaic/backends/utils.py +++ b/cogeo_mosaic/backends/utils.py @@ -1,12 +1,11 @@ """cogeo-mosaic.backends utility functions.""" -from typing import Any, Dict, List - import hashlib import itertools import json import os import zlib +from typing import Any, Dict, List import mercantile diff --git a/cogeo_mosaic/mosaic.py b/cogeo_mosaic/mosaic.py index 9f681387..2ce068b9 100644 --- a/cogeo_mosaic/mosaic.py +++ b/cogeo_mosaic/mosaic.py @@ -1,17 +1,15 @@ """cogeo_mosaic.mosaic MosaicJSON models and helper functions.""" -from typing import Any, Callable, Dict, List, Optional, Tuple, Sequence - import warnings +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple import click import mercantile +from pydantic import BaseModel, Field from pygeos import STRtree, polygons, total_bounds from supermercado import burntiles -from cogeo_mosaic.utils import get_footprints, _intersect_percent - -from pydantic import BaseModel, Field +from cogeo_mosaic.utils import _intersect_percent, get_footprints def default_accessor(feature: Dict): diff --git a/cogeo_mosaic/overviews.py b/cogeo_mosaic/overviews.py index f7b9b1f5..e1c9cf1c 100644 --- a/cogeo_mosaic/overviews.py +++ b/cogeo_mosaic/overviews.py @@ -1,26 +1,21 @@ """cogeo_mosaic.overviews: create low resolution image from a mosaic.""" -from typing import Dict, Tuple - import random from concurrent import futures +from typing import Dict, Tuple import click - import mercantile -from affine import Affine -from supermercado.burntiles import tile_extrema - import rasterio +from affine import Affine from rasterio.io import MemoryFile from rasterio.windows import Window - -from rio_tiler.io import cogeo -from rio_tiler_mosaic.mosaic import mosaic_tiler -from rio_tiler_mosaic.methods import defaults - from rio_cogeo.cogeo import cog_translate from rio_cogeo.utils import _meters_per_pixel, has_mask_band +from rio_tiler.io import cogeo +from rio_tiler_mosaic.methods import defaults +from rio_tiler_mosaic.mosaic import mosaic_tiler +from supermercado.burntiles import tile_extrema from cogeo_mosaic.backends import MosaicBackend from cogeo_mosaic.utils import _filter_futures diff --git a/cogeo_mosaic/scripts/cli.py b/cogeo_mosaic/scripts/cli.py index d3da4aba..e0a2315c 100644 --- a/cogeo_mosaic/scripts/cli.py +++ b/cogeo_mosaic/scripts/cli.py @@ -1,22 +1,21 @@ """Cogeo-mosaic: cli.""" -import os import json import multiprocessing -from pkg_resources import iter_entry_points +import os -from click_plugins import with_plugins import click import cligj +from click_plugins import with_plugins +from pkg_resources import iter_entry_points +from rasterio.rio import options +from rio_cogeo.profiles import cog_profiles from cogeo_mosaic import version as cogeo_mosaic_version -from cogeo_mosaic.utils import get_footprints -from cogeo_mosaic.mosaic import MosaicJSON from cogeo_mosaic.backends import MosaicBackend +from cogeo_mosaic.mosaic import MosaicJSON from cogeo_mosaic.overviews import create_low_level_cogs - -from rasterio.rio import options -from rio_cogeo.profiles import cog_profiles +from cogeo_mosaic.utils import get_footprints @with_plugins(iter_entry_points("cogeo_mosaic.plugins")) diff --git a/cogeo_mosaic/utils.py b/cogeo_mosaic/utils.py index 6e1761a0..1eb918c4 100644 --- a/cogeo_mosaic/utils.py +++ b/cogeo_mosaic/utils.py @@ -1,22 +1,18 @@ """cogeo_mosaic.utils: utility functions.""" -from typing import Dict, List, Sequence - +import logging import os import sys -import logging from concurrent import futures +from typing import Dict, List, Sequence import click - -import numpy -from pygeos import intersection, area import mercantile - +import numpy import rasterio -from rio_tiler.mercator import get_zooms +from pygeos import area, intersection from rasterio.warp import transform_bounds - +from rio_tiler.mercator import get_zooms logger = logging.getLogger() logger.setLevel(logging.INFO) diff --git a/setup.py b/setup.py index ac654ea6..7c61dea0 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ """Setup cogeo-mosaic.""" -from setuptools import setup, find_packages - +from setuptools import find_packages, setup # Runtime requirements. inst_reqs = [ diff --git a/tests/test_backends.py b/tests/test_backends.py index 479324ff..d2bf0cf3 100644 --- a/tests/test_backends.py +++ b/tests/test_backends.py @@ -1,26 +1,23 @@ """Test backends.""" -from typing import Dict, List - -import os import json +import os import time -from io import BytesIO from decimal import Decimal - -import pytest +from io import BytesIO +from typing import Dict, List from unittest.mock import patch +import pytest from click.testing import CliRunner -from cogeo_mosaic.mosaic import MosaicJSON from cogeo_mosaic.backends import MosaicBackend from cogeo_mosaic.backends.dynamodb import DynamoDBBackend from cogeo_mosaic.backends.file import FileBackend from cogeo_mosaic.backends.http import HttpBackend from cogeo_mosaic.backends.s3 import S3Backend from cogeo_mosaic.backends.utils import _decompress_gz - +from cogeo_mosaic.mosaic import MosaicJSON mosaic_gz = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic.json.gz") mosaic_bin = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic.bin") diff --git a/tests/test_backends_utils.py b/tests/test_backends_utils.py index 77f23b7a..6df80957 100644 --- a/tests/test_backends_utils.py +++ b/tests/test_backends_utils.py @@ -1,12 +1,12 @@ """Test backends utils.""" +import json import os import re -import json import mercantile -from cogeo_mosaic.backends import utils +from cogeo_mosaic.backends import utils mosaic_gz = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic.json.gz") mosaic_json = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic.json") diff --git a/tests/test_create.py b/tests/test_create.py index f01208db..ce3b9636 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -5,7 +5,6 @@ from cogeo_mosaic.mosaic import MosaicJSON, default_filter - basepath = os.path.join(os.path.dirname(__file__), "fixtures") mosaic_gz = os.path.join(basepath, "mosaic.json.gz") mosaic_json = os.path.join(basepath, "mosaic.json") diff --git a/tests/test_overview.py b/tests/test_overview.py index 5e5cda30..c329b9f9 100644 --- a/tests/test_overview.py +++ b/tests/test_overview.py @@ -1,10 +1,10 @@ """tests cogeo_mosaic.overview.""" -import os import json -from click.testing import CliRunner +import os import rasterio +from click.testing import CliRunner from rio_cogeo.profiles import cog_profiles from cogeo_mosaic.mosaic import MosaicJSON diff --git a/tox.ini b/tox.ini index a7b1b8ac..7e7b71a1 100644 --- a/tox.ini +++ b/tox.ini @@ -42,3 +42,11 @@ ignore = D203 exclude = .git,__pycache__,docs/source/conf.py,old,build,dist max-complexity = 15 max-line-length = 90 + +[tool:isort] +include_trailing_comma = True +multi_line_output = 3 +line_length = 90 +known_first_party = cogeo_mosaic +known_third_party = rasterio,rio_tiler,rio_cogeo,mercantile,supermercado,pygeos +default_section = THIRDPARTY