Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create titiler namespaces packages #284

Merged
merged 18 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
if: success()
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
file: ./coverage_core.xml,./coverage_mosaic.xml,./coverage_application.xml,
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
flags: unittests
name: ${{ matrix.platform }}-${{ matrix.tox-env }}
fail_ci_if_error: false
Expand All @@ -72,7 +72,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
pip install setuptools wheel twine

- name: Set tag version
id: tag
Expand All @@ -82,15 +82,16 @@ jobs:
- name: Set module version
id: module
# https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
run: echo ::set-output name=version::$(python setup.py --version)
run: echo ::set-output name=version::$(python titiler/core/setup.py --version)

- name: Build and publish
if: steps.tag.outputs.tag == steps.module.outputs.version
env:
TOXENV: release
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: tox
run: |
scripts/publish

publish-docker:
needs: [tests]
Expand Down
26 changes: 6 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,28 @@ repos:
rev: 19.10b0
hooks:
- id: black
language_version: python3.8
args: ["--safe"]
language_version: python

- repo: https://github.com/PyCQA/isort
rev: 5.4.2
hooks:
- id: isort
language_version: python3.8
language_version: python

- repo: https://github.com/PyCQA/flake8
rev: 3.8.3
hooks:
- id: flake8
language_version: python3.8
args: [
# E501 let black handle all line length decisions
# W503 black conflicts with "line break before operator" rule
# E203 black conflicts with "whitespace before ':'" rule
"--ignore=E501,W503,E203",
]
language_version: python

- repo: https://github.com/PyCQA/pydocstyle
rev: 5.1.1
hooks:
- id: pydocstyle
language_version: python3.8
args: [
# Check for docstring presence only
"--select=D1",
# Don't require docstrings for tests
'--match=(?!test).*\.py',
]
language_version: python

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
rev: v0.812
hooks:
- id: mypy
language_version: python3.8
args: ["--no-strict-optional", "--ignore-missing-imports"]
language_version: python
5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env bash

SUBPACKAGE_DIRS=(
"core"
"mosaic"
"application"
)

for PACKAGE_DIR in "${SUBPACKAGE_DIRS[@]}"
do
echo "publishing titiler-${PACKAGE_DIR}"
pushd ./titiler/${PACKAGE_DIR}
rm -rf dist
python setup.py sdist
# twine upload dist/*
popd
done
50 changes: 45 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
[bumpversion]
current_version = 0.2.0
current_version = 0.2.1
commit = True
tag = True
tag_name = {new_version}
parse =
parse =
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
((?P<pre>a|b|rc)(?P<prenum>\d+))?
serialize =
serialize =
{major}.{minor}.{patch}{pre}{prenum}
{major}.{minor}.{patch}

[bumpversion:file:setup.py]
[bumpversion:file:titiler/application/setup.py]
search = version="{current_version}"
replace = version="{new_version}"

[bumpversion:file:titiler/__init__.py]
[bumpversion:file:titiler/application/titiler/application/version.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[bumpversion:file:titiler/core/setup.py]
search = version="{current_version}"
replace = version="{new_version}"

[bumpversion:file:titiler/core/titiler/core/version.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[bumpversion:file:titiler/mosaic/setup.py]
search = version="{current_version}"
replace = version="{new_version}"

[bumpversion:file:titiler/mosaic/titiler/mosaic/version.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[isort]
profile = black
known_first_party = titiler
forced_separate = fastapi,starlette
known_third_party = rasterio,morecantile,rio_tiler,cogeo_mosaic,brotli_asgi,geojson_pydantic
default_section = THIRDPARTY

[flake8]
ignore = E501,W503,E203
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
max-complexity = 12
max-line-length = 90

[mypy]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved the linters config to setup.cfg

no_implicit_optional = True
strict_optional = True
ignore_missing_imports = True
namespace_packages = True
explicit_package_bases = True

[pydocstyle]
select = D1
match = (?!test).*\.py
3 changes: 0 additions & 3 deletions titiler/__init__.py

This file was deleted.

4 changes: 4 additions & 0 deletions titiler/application/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include titiler/application/templates/*.html

recursive-exclude tests *

1 change: 1 addition & 0 deletions titiler/application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## titiler.application
46 changes: 46 additions & 0 deletions titiler/application/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Setup titiler-application."""

from setuptools import find_namespace_packages, setup

with open("README.md") as f:
long_description = f.read()

inst_reqs = [
"titiler.core",
"titiler.mosaic",
"brotli-asgi>=1.0.0",
"python-dotenv",
]
extra_reqs = {
"test": ["pytest", "pytest-cov", "pytest-asyncio", "requests"],
"server": ["uvicorn[standard]>=0.12.0,<0.14.0"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uvicorn is optional (e.g when running the application in AWS Lambda you don't need Uvicorn)

}


setup(
name="titiler.application",
version="0.2.0",
description=u"A modern dynamic tile server built on top of FastAPI and Rasterio/GDAL.",
long_description=long_description,
long_description_content_type="text/markdown",
python_requires=">=3.6",
classifiers=[
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
keywords="COG STAC MosaicJSON FastAPI",
author=u"Vincent Sarago",
author_email="[email protected]",
url="https://github.com/developmentseed/titiler",
license="MIT",
packages=find_namespace_packages(exclude=["tests*"]),
package_data={"titiler": ["application/templates/*.html"]},
include_package_data=True,
zip_safe=False,
install_requires=inst_reqs,
extras_require=extra_reqs,
)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def set_env(monkeypatch):
@pytest.fixture(autouse=True)
def app(set_env) -> TestClient:
"""Create App."""
from titiler.main import app
from titiler.application.main import app

return TestClient(app)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,14 @@ def test_point(rio, app):


def test_file_not_found_error(app):
"""raise 404 when file is not found."""
response = app.get("/cog/info?url=foo.tif")
assert response.status_code == 404


@patch("rio_tiler.io.cogeo.rasterio")
def test_tile_outside_bounds_error(rio, app):
"""raise 404 when tile is not found."""
rio.open = mock_rasterio_open

response = app.get("/cog/tiles/15/0/0?url=https://myurl.com/cog.tif&rescale=0,1000")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cogeo_mosaic.backends import FileBackend
from cogeo_mosaic.mosaic import MosaicJSON

from titiler.models.mapbox import TileJSON
from titiler.core.models.mapbox import TileJSON

from ..conftest import DATA_DIR, parse_img, read_json_fixture

Expand All @@ -18,7 +18,7 @@
def mosaic_read_factory(fname: str) -> Callable:
"""Factory method for patching mosaic reading"""

def _read(gzip: bool = None) -> MosaicJSON:
def _read(*args, **kwargs) -> MosaicJSON: # type: ignore
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
"""Match signature of `cogeo_mosaic.backends.BaseBackend._read`"""
data = read_json_fixture(fname)
for qk in data["tiles"]:
Expand Down Expand Up @@ -210,6 +210,7 @@ def test_wmts(app):


def test_mosaic_auth_error(app):
"""Raise auth error 401."""
response = app.get("/mosaicjson", params={"url": "s3://bucket/mosaic.json"})
assert response.status_code == 401

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test titiler.main.app."""
"""Test titiler.application.main.app."""


def test_health(app):
Expand Down
3 changes: 3 additions & 0 deletions titiler/application/titiler/application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""titiler.application"""

from .version import __version__ # noqa
98 changes: 98 additions & 0 deletions titiler/application/titiler/application/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""TiTiler demo custon dependencies."""

import json
from enum import Enum
from typing import Dict, Optional

import morecantile
from morecantile import tms
from morecantile.models import TileMatrixSet
from rasterio.crs import CRS
from rio_tiler.colormap import cmap, parse_color

from fastapi import HTTPException, Query

from starlette.templating import Jinja2Templates

try:
import importlib.resources as pkg_resources
except ImportError:
import importlib_resources as pkg_resources # type: ignore


with pkg_resources.path(__package__, "templates") as p:
templates = Jinja2Templates(directory=str(p))


# colors from https://daac.ornl.gov/ABOVE/guides/Annual_Landcover_ABoVE.html
above_cmap = {
1: [58, 102, 24, 255], # Evergreen Forest
2: [100, 177, 41, 255], # Deciduous Forest
3: [177, 177, 41, 255], # Shrubland
4: [221, 203, 154, 255], # Herbaceous
5: [218, 203, 47, 255], # Sparely Vegetated
6: [177, 177, 177, 255], # Barren
7: [175, 255, 205, 255], # Fen
8: [239, 255, 192, 255], # Bog
9: [144, 255, 255, 255], # Shallows/Littoral
10: [29, 0, 250, 255], # Water
}
cmap = cmap.register({"above": above_cmap})

ColorMapName = Enum( # type: ignore
"ColorMapName", [(a, a) for a in sorted(cmap.list())]
)

# CUSTOM TMS for EPSG:3413
EPSG3413 = morecantile.TileMatrixSet.custom(
(-4194300, -4194300, 4194300, 4194300),
CRS.from_epsg(3413),
identifier="EPSG3413",
matrix_scale=[2, 2],
)

# CUSTOM TMS for EPSG:6933
# info from https://epsg.io/6933
EPSG6933 = morecantile.TileMatrixSet.custom(
(-17357881.81713629, -7324184.56362408, 17357881.81713629, 7324184.56362408),
CRS.from_epsg(6933),
identifier="EPSG6933",
matrix_scale=[1, 1],
)
tms = tms.register([EPSG3413, EPSG6933])

TileMatrixSetName = Enum( # type: ignore
"TileMatrixSetName", [(a, a) for a in sorted(tms.list())]
)


def ColorMapParams(
colormap_name: ColorMapName = Query(None, description="Colormap name"),
colormap: str = Query(None, description="JSON encoded custom Colormap"),
) -> Optional[Dict]:
"""Colormap Dependency."""
if colormap_name:
return cmap.get(colormap_name.value)

if colormap:
try:
return json.loads(
colormap,
object_hook=lambda x: {int(k): parse_color(v) for k, v in x.items()},
)
except json.JSONDecodeError:
raise HTTPException(
status_code=400, detail="Could not parse the colormap value."
)

return None


def TMSParams(
TileMatrixSetId: TileMatrixSetName = Query(
TileMatrixSetName.WebMercatorQuad, # type: ignore
description="TileMatrixSet Name (default: 'WebMercatorQuad')",
)
) -> TileMatrixSet:
"""TileMatrixSet Dependency."""
return tms.get(TileMatrixSetId.name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved all custom code to the application part

Loading