From db966752861527a657e71b5e6e22eee9695283a5 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 17 Oct 2024 19:03:49 +0200 Subject: [PATCH 1/2] update starlette-cramjam and update ruff --- .pre-commit-config.yaml | 15 +++++---------- CHANGES.md | 8 +++++++- pyproject.toml | 4 ++-- tipg/collections.py | 4 +--- tipg/dependencies.py | 2 +- tipg/factory.py | 4 +--- tipg/main.py | 5 ++++- tipg/middleware.py | 5 +---- tipg/model.py | 12 ++++++------ 9 files changed, 28 insertions(+), 31 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1333a4b7..55c3dfd5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,26 +4,21 @@ repos: hooks: - id: validate-pyproject - - repo: https://github.com/psf/black - rev: 22.12.0 - hooks: - - id: black - language_version: python - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort language_version: python - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.238 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.5 hooks: - id: ruff args: ["--fix"] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.3.0 + rev: v1.11.2 hooks: - id: mypy language_version: python diff --git a/CHANGES.md b/CHANGES.md index f746a4b4..6bce1160 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,10 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin ## Unreleased +## [0.8.0] - TBD + +* update starlette-cramjam dependency and set compression-level default to 6 + ## [0.7.3] - 2024-09-16 * add `TIPG_SORT_COLUMNS` settings to enable/disable columns sorting (default to `True`) (author @mattdiez-at, https://github.com/developmentseed/tipg/pull/187) @@ -316,7 +320,9 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin - Initial release -[unreleased]: https://github.com/developmentseed/tipg/compare/0.7.2...HEAD +[unreleased]: https://github.com/developmentseed/tipg/compare/0.8.0...HEAD +[0.8.0]: https://github.com/developmentseed/tipg/compare/0.7.3...0.8.0 +[0.7.3]: https://github.com/developmentseed/tipg/compare/0.7.2...0.7.3 [0.7.2]: https://github.com/developmentseed/tipg/compare/0.7.1...0.7.2 [0.7.1]: https://github.com/developmentseed/tipg/compare/0.7.0...0.7.1 [0.7.0]: https://github.com/developmentseed/tipg/compare/0.6.3...0.7.0 diff --git a/pyproject.toml b/pyproject.toml index ecd5b021..cf72301b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ dependencies = [ "geojson-pydantic>=1.0,<2.0", "pygeofilter>=0.2.0,<0.3.0", "ciso8601~=2.3", - "starlette-cramjam>=0.3,<0.4", + "starlette-cramjam>=0.4,<0.5", "importlib_resources>=1.1.0; python_version < '3.9'", "typing_extensions; python_version < '3.9'", ] @@ -117,7 +117,7 @@ default_section = "THIRDPARTY" [tool.mypy] no_strict_optional = "True" -[tool.ruff] +[tool.ruff.lint] select = [ "D1", # pydocstyle errors "E", # pycodestyle errors diff --git a/tipg/collections.py b/tipg/collections.py index b003f771..05b5d5dc 100644 --- a/tipg/collections.py +++ b/tipg/collections.py @@ -600,9 +600,7 @@ def _sortby(self, sortby: Optional[str]): sorts = [] if sortby: for s in sortby.strip().split(","): - parts = re.match( - "^(?P[+-]?)(?P.*)$", s - ).groupdict() # type:ignore + parts = re.match("^(?P[+-]?)(?P.*)$", s).groupdict() # type:ignore direction = parts["direction"] column = parts["column"].strip() diff --git a/tipg/dependencies.py b/tipg/dependencies.py index 4b5320fb..28e8d586 100644 --- a/tipg/dependencies.py +++ b/tipg/dependencies.py @@ -189,7 +189,7 @@ def bbox_query( bbox: Annotated[ Optional[str], Query(description="Spatial Filter."), - ] = None + ] = None, ) -> Optional[List[float]]: """BBox dependency.""" if bbox: diff --git a/tipg/factory.py b/tipg/factory.py index de7efa73..a5fde58a 100644 --- a/tipg/factory.py +++ b/tipg/factory.py @@ -776,9 +776,7 @@ async def items( # noqa: C901 MediaType.json, MediaType.ndjson, ): - if any( - [f.get("geometry", None) is not None for f in item_list["items"]] - ): + if any(f.get("geometry", None) is not None for f in item_list["items"]): rows = ( { "collectionId": collection.id, diff --git a/tipg/main.py b/tipg/main.py index 743e926c..88fdc432 100644 --- a/tipg/main.py +++ b/tipg/main.py @@ -101,7 +101,10 @@ async def lifespan(app: FastAPI): ) app.add_middleware(CacheControlMiddleware, cachecontrol=settings.cachecontrol) -app.add_middleware(CompressionMiddleware) +app.add_middleware( + CompressionMiddleware, + compression_level=6, +) if settings.catalog_ttl: app.add_middleware( diff --git a/tipg/middleware.py b/tipg/middleware.py index 476e4362..50b6a44b 100644 --- a/tipg/middleware.py +++ b/tipg/middleware.py @@ -52,10 +52,7 @@ async def send_wrapper(message: Message): scope["method"] in ["HEAD", "GET"] and message["status"] < self.cachecontrol_max_http_code and not any( - [ - re.match(path, scope["path"]) - for path in self.exclude_path - ] + re.match(path, scope["path"]) for path in self.exclude_path ) ): response_headers["Cache-Control"] = self.cachecontrol diff --git a/tipg/model.py b/tipg/model.py index 442e49bd..cab89da4 100644 --- a/tipg/model.py +++ b/tipg/model.py @@ -236,9 +236,9 @@ class Queryables(BaseModel): title: str properties: Dict[str, Dict[str, str]] type: str = "object" - schema_name: Annotated[ - str, Field(alias="$schema") - ] = "https://json-schema.org/draft/2019-09/schema" + schema_name: Annotated[str, Field(alias="$schema")] = ( + "https://json-schema.org/draft/2019-09/schema" + ) link: Annotated[str, Field(alias="$id")] model_config = {"populate_by_name": True} @@ -391,9 +391,9 @@ class BoundingBox(BaseModel): ), ] crs: Annotated[Optional[CRSType], Field(json_schema_extra={"title": "CRS"})] = None - orderedAxes: Annotated[ - Optional[List[str]], Field(max_length=2, min_length=2) - ] = None + orderedAxes: Annotated[Optional[List[str]], Field(max_length=2, min_length=2)] = ( + None + ) # Ref: https://github.com/opengeospatial/ogcapi-tiles/blob/master/openapi/schemas/tms/propertiesSchema.yaml From 79dc32815221bc852cdcdeb3417a3d1c784ca64b Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 17 Oct 2024 21:43:18 +0200 Subject: [PATCH 2/2] format --- tipg/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tipg/main.py b/tipg/main.py index 88fdc432..a98186e1 100644 --- a/tipg/main.py +++ b/tipg/main.py @@ -101,10 +101,7 @@ async def lifespan(app: FastAPI): ) app.add_middleware(CacheControlMiddleware, cachecontrol=settings.cachecontrol) -app.add_middleware( - CompressionMiddleware, - compression_level=6, -) +app.add_middleware(CompressionMiddleware, compression_level=6) if settings.catalog_ttl: app.add_middleware(