From 6ae69eae16069b3b5155cb718ab6a0bd0cbab55d Mon Sep 17 00:00:00 2001 From: peterrrock2 <27579114+peterrrock2@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:37:22 -0600 Subject: [PATCH] Fix some formatting issues --- gerrydb/create.py | 8 +++++++- gerrydb/exceptions.py | 5 +++-- gerrydb/repos/__init__.py | 1 + gerrydb/repos/column_set.py | 1 + gerrydb/repos/geo_layer.py | 9 ++++++--- gerrydb/repos/geography.py | 2 +- gerrydb/repos/locality.py | 30 +++++++++++++++++------------- gerrydb/repos/namespace.py | 3 ++- gerrydb/repos/plan.py | 1 + tests/repos/conftest.py | 1 + tests/repos/test_base.py | 1 + tests/repos/test_column.py | 1 + tests/repos/test_column_set.py | 1 + tests/repos/test_geo_import.py | 1 + tests/repos/test_geo_layer.py | 1 + tests/repos/test_geography.py | 1 + tests/repos/test_locality.py | 1 + tests/repos/test_namespace.py | 1 + tests/repos/test_plan.py | 1 + tests/repos/test_view.py | 1 + tests/repos/test_view_template.py | 1 + tests/test_cache.py | 1 + tests/test_client.py | 1 + 23 files changed, 53 insertions(+), 21 deletions(-) diff --git a/gerrydb/create.py b/gerrydb/create.py index bdf24d4..d5e00d2 100644 --- a/gerrydb/create.py +++ b/gerrydb/create.py @@ -1,4 +1,5 @@ """CLI for creating GerryDB resources.""" + from typing import Optional import click @@ -6,6 +7,7 @@ from gerrydb import GerryDB from gerrydb.exceptions import ResultError + @click.group() def cli(): """Creates GerryDB resources.""" @@ -27,6 +29,7 @@ def namespace(path: str, description: str, public: bool): else: raise e + @cli.command() @click.argument("path") @click.option("--description", required=True) @@ -37,12 +40,15 @@ def geo_layer(path: str, description: str, namespace: str, source_url: Optional[ db = GerryDB(namespace=namespace) with db.context(notes=f'Creating geographic layer "{path}" from CLI') as ctx: try: - ctx.geo_layers.create(path=path, description=description, source_url=source_url) + ctx.geo_layers.create( + path=path, description=description, source_url=source_url + ) except ResultError as e: if "Failed to create geographic layer" in e.args[0]: print(f"Failed to create {path} layer, already exists") else: raise e + if __name__ == "__main__": cli() diff --git a/gerrydb/exceptions.py b/gerrydb/exceptions.py index b973331..fee0e76 100644 --- a/gerrydb/exceptions.py +++ b/gerrydb/exceptions.py @@ -39,6 +39,7 @@ class CacheInitError(CacheError): class ViewLoadError(GerryDBError): """Raised when a view cannot be loaded (e.g. from a GeoPackage).""" - + + class GerryPathError(GerryDBError): - """Raised when an invalid path is provided. Generally, this means invalid characters are present""" \ No newline at end of file + """Raised when an invalid path is provided. Generally, this means invalid characters are present""" diff --git a/gerrydb/repos/__init__.py b/gerrydb/repos/__init__.py index 64411ac..166649e 100644 --- a/gerrydb/repos/__init__.py +++ b/gerrydb/repos/__init__.py @@ -1,4 +1,5 @@ """GerryDB API object repositories.""" + from gerrydb.repos.column import ColumnRepo from gerrydb.repos.column_set import ColumnSetRepo from gerrydb.repos.geo_layer import GeoLayerRepo diff --git a/gerrydb/repos/column_set.py b/gerrydb/repos/column_set.py index cfc89f5..4e2f305 100644 --- a/gerrydb/repos/column_set.py +++ b/gerrydb/repos/column_set.py @@ -1,4 +1,5 @@ """Repository for column sets.""" + from typing import Optional, Union from gerrydb.exceptions import RequestError diff --git a/gerrydb/repos/geo_layer.py b/gerrydb/repos/geo_layer.py index 0d69a0a..0331ffe 100644 --- a/gerrydb/repos/geo_layer.py +++ b/gerrydb/repos/geo_layer.py @@ -1,4 +1,5 @@ """Repository for geographic layers.""" + from typing import Optional, Union from gerrydb.repos.base import ( @@ -69,9 +70,11 @@ def map_locality( response = self.ctx.client.put( f"{self.base_url}/{layer.namespace}/{layer.path}", params={ - "locality": locality.canonical_path - if isinstance(locality, Locality) - else locality + "locality": ( + locality.canonical_path + if isinstance(locality, Locality) + else locality + ) }, json=GeoSetCreate( paths=[ diff --git a/gerrydb/repos/geography.py b/gerrydb/repos/geography.py index b25294c..2d2b874 100644 --- a/gerrydb/repos/geography.py +++ b/gerrydb/repos/geography.py @@ -268,4 +268,4 @@ def all_paths(self, fips: str, layer_name: str) -> list[str]: response.raise_for_status() response_json = response.json() - return response_json \ No newline at end of file + return response_json diff --git a/gerrydb/repos/locality.py b/gerrydb/repos/locality.py index 5476252..eccba01 100644 --- a/gerrydb/repos/locality.py +++ b/gerrydb/repos/locality.py @@ -1,10 +1,12 @@ """Repository for localities.""" + from dataclasses import dataclass from typing import TYPE_CHECKING, Optional from gerrydb.repos.base import ObjectRepo, err, normalize_path, online, write_context from gerrydb.schemas import Locality, LocalityCreate, LocalityPatch from gerrydb.exceptions import ResultError + if TYPE_CHECKING: from gerrydb.client import GerryDB, WriteContext @@ -35,9 +37,11 @@ def get(self, path: str) -> Optional[Locality]: response.raise_for_status() return Locality(**response.json()) - @err("Failed to create locality") # Decorator for handling HTTP request and Pydantic validation errors - @write_context # Decorator for marking operations that require a write context - @online # Decorator for marking online-only operations + @err( + "Failed to create locality" + ) # Decorator for handling HTTP request and Pydantic validation errors + @write_context # Decorator for marking operations that require a write context + @online # Decorator for marking online-only operations def create( self, canonical_path: str, @@ -104,24 +108,24 @@ def create_bulk( Returns: The new localities. """ - loc_list = [-1]*len(locs) + loc_list = [-1] * len(locs) for i, loc in enumerate(locs): try: - loc_object = self.create(canonical_path=loc.canonical_path, - name=loc.name, - parent_path=loc.parent_path, - default_proj=loc.default_proj, - aliases=loc.aliases,) + loc_object = self.create( + canonical_path=loc.canonical_path, + name=loc.name, + parent_path=loc.parent_path, + default_proj=loc.default_proj, + aliases=loc.aliases, + ) loc_list[i] = loc_object except ResultError as e: if "Failed to create canonical path to new location(s)." in e.args[0]: print(f"Failed to create {loc.name}, path already exists") else: raise e - + return loc_list - - # loc_list = [-1]*len(locs) # for i, loc in enumerate(locs): @@ -132,7 +136,7 @@ def create_bulk( # response.raise_for_status() # loc_list[i] = Locality(**response.json()[0]) # return(loc_list[i]) - + # response = self.ctx.client.post( # "/localities/", # json=[loc.dict() for loc in locs], diff --git a/gerrydb/repos/namespace.py b/gerrydb/repos/namespace.py index 31d5a45..9a58ed9 100644 --- a/gerrydb/repos/namespace.py +++ b/gerrydb/repos/namespace.py @@ -1,4 +1,5 @@ """Repository for namespaces.""" + from dataclasses import dataclass from typing import TYPE_CHECKING, Optional @@ -86,7 +87,7 @@ def create( ) response.raise_for_status() - + return Namespace(**response.json()) def __getitem__(self, path: str) -> Optional[Namespace]: diff --git a/gerrydb/repos/plan.py b/gerrydb/repos/plan.py index 3dc5918..c51cf3a 100644 --- a/gerrydb/repos/plan.py +++ b/gerrydb/repos/plan.py @@ -1,4 +1,5 @@ """Repository for districting plans.""" + from typing import Optional, Union from gerrydb.repos.base import ( diff --git a/tests/repos/conftest.py b/tests/repos/conftest.py index 3655ac4..5885372 100644 --- a/tests/repos/conftest.py +++ b/tests/repos/conftest.py @@ -1,4 +1,5 @@ """Fixtures for repository tests.""" + import pytest diff --git a/tests/repos/test_base.py b/tests/repos/test_base.py index cf21178..b8fd052 100644 --- a/tests/repos/test_base.py +++ b/tests/repos/test_base.py @@ -1,4 +1,5 @@ """Tests for base objects and utilities for GerryDB API object repositories.""" + from dataclasses import dataclass from typing import Optional diff --git a/tests/repos/test_column.py b/tests/repos/test_column.py index 0734f85..183092e 100644 --- a/tests/repos/test_column.py +++ b/tests/repos/test_column.py @@ -1,4 +1,5 @@ """Integration/VCR tests for columns.""" + import pytest from shapely import box diff --git a/tests/repos/test_column_set.py b/tests/repos/test_column_set.py index 32de339..4320cd5 100644 --- a/tests/repos/test_column_set.py +++ b/tests/repos/test_column_set.py @@ -1,4 +1,5 @@ """Integration/VCR tests for columns.""" + import pytest diff --git a/tests/repos/test_geo_import.py b/tests/repos/test_geo_import.py index 7be5247..0d0bae0 100644 --- a/tests/repos/test_geo_import.py +++ b/tests/repos/test_geo_import.py @@ -1,4 +1,5 @@ """Integration/VCR tests for geographic import metadata.""" + import pytest # The `GeoImport` object is used for internal tracking, so we don't diff --git a/tests/repos/test_geo_layer.py b/tests/repos/test_geo_layer.py index 76a4bff..133aa7f 100644 --- a/tests/repos/test_geo_layer.py +++ b/tests/repos/test_geo_layer.py @@ -1,4 +1,5 @@ """Integration/VCR tests for geographic layers.""" + import pytest diff --git a/tests/repos/test_geography.py b/tests/repos/test_geography.py index c3df225..ab214bd 100644 --- a/tests/repos/test_geography.py +++ b/tests/repos/test_geography.py @@ -1,4 +1,5 @@ """Integration/VCR tests for columns.""" + from shapely import box diff --git a/tests/repos/test_locality.py b/tests/repos/test_locality.py index 0798f9d..0916f07 100644 --- a/tests/repos/test_locality.py +++ b/tests/repos/test_locality.py @@ -1,4 +1,5 @@ """Integration/VCR tests for localities.""" + import pytest from gerrydb.schemas import LocalityCreate diff --git a/tests/repos/test_namespace.py b/tests/repos/test_namespace.py index 52f90c9..58aea42 100644 --- a/tests/repos/test_namespace.py +++ b/tests/repos/test_namespace.py @@ -1,4 +1,5 @@ """Integration/VCR tests for namespaces.""" + import pytest diff --git a/tests/repos/test_plan.py b/tests/repos/test_plan.py index fe4b8d8..da64a4f 100644 --- a/tests/repos/test_plan.py +++ b/tests/repos/test_plan.py @@ -1,4 +1,5 @@ """Integration/VCR tests for districting plans.""" + import pytest from gerrydb.exceptions import ResultError diff --git a/tests/repos/test_view.py b/tests/repos/test_view.py index b6122b9..e45df59 100644 --- a/tests/repos/test_view.py +++ b/tests/repos/test_view.py @@ -1,4 +1,5 @@ """Tests for views.""" + import pytest diff --git a/tests/repos/test_view_template.py b/tests/repos/test_view_template.py index 6d4347f..68df48a 100644 --- a/tests/repos/test_view_template.py +++ b/tests/repos/test_view_template.py @@ -1,4 +1,5 @@ """Integration/VCR tests for view templates.""" + import pytest diff --git a/tests/test_cache.py b/tests/test_cache.py index c773e12..96706e3 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,4 +1,5 @@ """Tests for GerryDB's local caching layer.""" + import uuid from datetime import datetime, timedelta, timezone diff --git a/tests/test_client.py b/tests/test_client.py index 095dcfd..9a8e266 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,4 +1,5 @@ """Tests for GerryDB session management.""" + import os from unittest import mock