-
Notifications
You must be signed in to change notification settings - Fork 27
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
update pre-commit and use ruff for linting/formating #105
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0e6174
update pre-commit and use ruff for linting/formating
vincentsarago 4c505de
use python 3.11 for lint
vincentsarago 06146c8
try pydantic 1.
vincentsarago 494510d
Merge branch 'main' into feature/update-linter
jonhealy1 8b11351
update from main
vincentsarago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,23 @@ | ||
repos: | ||
- repo: https://github.com/PyCQA/isort | ||
rev: 5.12.0 | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort | ||
language_version: python | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 22.12.0 | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.3.5 | ||
hooks: | ||
- id: black | ||
args: ["--safe"] | ||
language_version: python | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
language_version: python | ||
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,C901", | ||
] | ||
- repo: https://github.com/chewse/pre-commit-mirrors-pydocstyle | ||
# 2.1.1 | ||
rev: v2.1.1 | ||
hooks: | ||
- id: pydocstyle | ||
language_version: python | ||
exclude: ".*(test|scripts).*" | ||
args: | ||
[ | ||
# Check for docstring presence only | ||
"--select=D1", | ||
] | ||
# Don't require docstrings for tests | ||
# '--match=(?!test).*\.py'] | ||
# - | ||
# repo: https://github.com/pre-commit/mirrors-mypy | ||
# rev: v0.770 | ||
# hooks: | ||
# - id: mypy | ||
# language_version: python3.8 | ||
# args: [--no-strict-optional, --ignore-missing-imports] | ||
- id: ruff | ||
args: ["--fix"] | ||
- id: ruff-format | ||
|
||
- repo: https://github.com/PyCQA/pydocstyle | ||
rev: 6.3.0 | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v1.9.0 | ||
hooks: | ||
- id: pydocstyle | ||
- id: mypy | ||
language_version: python | ||
exclude: ".*(test|scripts).*" | ||
#args: [ | ||
# Don't require docstrings for tests | ||
#'--match=(?!test|scripts).*\.py', | ||
#] | ||
exclude: tests/.* | ||
additional_dependencies: | ||
- types-requests | ||
- types-attrs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
[flake8] | ||
ignore = "D203" | ||
exclude = [".git", "__pycache__", "docs/source/conf.py", "build", "dist"] | ||
max-complexity = 12 | ||
max-line-length = 90 | ||
|
||
[tool.isort] | ||
profile = "black" | ||
known_first_party = "stac_fastapi.pgstac" | ||
known_third_party = ["rasterio", "stac-pydantic", "sqlalchemy", "geoalchemy2", "fastapi", "stac_fastapi"] | ||
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] | ||
|
||
[tool.mypy] | ||
ignore_missing_imports = true | ||
namespace_packages = true | ||
explicit_package_bases = true | ||
exclude = ["tests", ".venv"] | ||
|
||
[tool.ruff] | ||
line-length = 90 | ||
|
||
[tool.ruff.lint] | ||
select = [ | ||
"C", | ||
"E", | ||
"F", | ||
"W", | ||
"B", | ||
] | ||
ignore = [ | ||
"E203", # line too long, handled by black | ||
"E501", # do not perform function calls in argument defaults | ||
"B028", # No explicit `stacklevel` keyword argument found | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Ingest sample data during docker-compose""" | ||
|
||
import json | ||
import sys | ||
from pathlib import Path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Item crud client.""" | ||
|
||
import re | ||
from datetime import datetime | ||
from typing import Any, Dict, List, Optional, Union | ||
|
@@ -168,10 +169,10 @@ async def _search_base( | |
req=search_request_json, | ||
) | ||
items = await conn.fetchval(q, *p) | ||
except InvalidDatetimeFormatError: | ||
except InvalidDatetimeFormatError as e: | ||
raise InvalidQueryParameter( | ||
f"Datetime parameter {search_request.datetime} is invalid." | ||
) | ||
) from e | ||
|
||
next: Optional[str] = items.pop("next", None) | ||
prev: Optional[str] = items.pop("prev", None) | ||
|
@@ -203,8 +204,8 @@ async def _add_item_links( | |
and all([collection_id, item_id]) | ||
): | ||
feature["links"] = await ItemLinks( | ||
collection_id=collection_id, | ||
item_id=item_id, | ||
collection_id=collection_id, # type: ignore | ||
item_id=item_id, # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. collection_id and item_id should always be define but for some reason mypy thinks it can be None |
||
request=request, | ||
).get_links(extra_links=feature.get("links")) | ||
|
||
|
@@ -251,7 +252,7 @@ async def item_collection( | |
bbox: Optional[List[NumType]] = None, | ||
datetime: Optional[Union[str, datetime]] = None, | ||
limit: Optional[int] = None, | ||
token: str = None, | ||
token: Optional[str] = None, | ||
**kwargs, | ||
) -> ItemCollection: | ||
"""Get all items from a specific collection. | ||
|
@@ -336,7 +337,7 @@ async def post_search( | |
item_collection = await self._search_base(search_request, request=request) | ||
return ItemCollection(**item_collection) | ||
|
||
async def get_search( | ||
async def get_search( # noqa: C901 | ||
self, | ||
request: Request, | ||
collections: Optional[List[str]] = None, | ||
|
@@ -428,5 +429,6 @@ async def get_search( | |
except ValidationError as e: | ||
raise HTTPException( | ||
status_code=400, detail=f"Invalid parameters provided {e}" | ||
) | ||
) from e | ||
|
||
return await self.post_search(search_request, request=request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,16 @@ | |
|
||
import json | ||
from contextlib import asynccontextmanager, contextmanager | ||
from typing import AsyncIterator, Callable, Dict, Generator, Literal, Union | ||
from typing import ( | ||
AsyncIterator, | ||
Callable, | ||
Dict, | ||
Generator, | ||
List, | ||
Literal, | ||
Optional, | ||
Union, | ||
) | ||
|
||
import attr | ||
import orjson | ||
|
@@ -36,14 +45,17 @@ async def con_init(conn): | |
ConnectionGetter = Callable[[Request, Literal["r", "w"]], AsyncIterator[Connection]] | ||
|
||
|
||
async def connect_to_db(app: FastAPI, get_conn: ConnectionGetter = None) -> None: | ||
async def connect_to_db( | ||
app: FastAPI, get_conn: Optional[ConnectionGetter] = None | ||
) -> None: | ||
"""Create connection pools & connection retriever on application.""" | ||
settings = app.state.settings | ||
if app.state.settings.testing: | ||
readpool = writepool = settings.testing_connection_string | ||
else: | ||
readpool = settings.reader_connection_string | ||
writepool = settings.writer_connection_string | ||
|
||
db = DB() | ||
app.state.readpool = await db.create_pool(readpool, settings) | ||
app.state.writepool = await db.create_pool(writepool, settings) | ||
|
@@ -62,15 +74,13 @@ async def get_connection( | |
readwrite: Literal["r", "w"] = "r", | ||
) -> AsyncIterator[Connection]: | ||
"""Retrieve connection from database conection pool.""" | ||
pool = ( | ||
request.app.state.writepool if readwrite == "w" else request.app.state.readpool | ||
) | ||
pool = request.app.state.writepool if readwrite == "w" else request.app.state.readpool | ||
with translate_pgstac_errors(): | ||
async with pool.acquire() as conn: | ||
yield conn | ||
|
||
|
||
async def dbfunc(conn: Connection, func: str, arg: Union[str, Dict]): | ||
async def dbfunc(conn: Connection, func: str, arg: Union[str, Dict, List]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix |
||
"""Wrap PLPGSQL Functions. | ||
|
||
Keyword arguments: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Get Queryables.""" | ||
|
||
from typing import Any, Optional | ||
|
||
from buildpg import render | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why I was getting a Mypy error here 🤷