Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
yu23ki14 committed May 13, 2024
2 parents a83af8e + 1db863f commit a82d7dc
Show file tree
Hide file tree
Showing 38 changed files with 987 additions and 257 deletions.
53 changes: 47 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permissions:
packages: read

jobs:
test-check:
common-test-check:
runs-on: ubuntu-latest
services:
postgres:
Expand All @@ -22,15 +22,56 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup python 3.12
- name: Setup python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.12
python-version: "3.10"
cache: pip
cache-dependency-path: pyproject.toml
cache-dependency-path: common/pyproject.toml
- name: dependency install
run: pip install -e ".[dev]"
run: pip install -e "./common[dev]"
- name: copy env
run: cp .env.example .env
run: cp .env.example common/.env
- name: test
working-directory: common
run: tox

api-test-check:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
cache-dependency-path: api/pyproject.toml
- name: dependency install
run: pip install -e "./api[dev]"
- name: copy env
run: cp .env.example api/.env
- name: test
working-directory: api
run: tox

etl-test-check:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
cache-dependency-path: etl/pyproject.toml
- name: dependency install
run: pip install -e "./etl[dev]"
- name: copy env
run: cp .env.example etl/.env
- name: test
working-directory: etl
run: tox
20 changes: 16 additions & 4 deletions .vscode/settings.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"editor.formatOnSave": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
Expand All @@ -23,9 +23,21 @@
".venv/lib/python3.10/site-packages"
],
"python.defaultInterpreterPath": ".venv/bin/python",
"python.analysis.stubPath": "stubs",
"python.analysis.stubPath": "common/stubs",
"black-formatter.args": [
"--config",
"common/pyproject.toml"
],
"flake8.path": [
".venv/bin/pflake8"
],
"python.formatting.provider": "none",
}
"flake8.args": [
"--config",
"common/pyproject.toml"
],
"isort.args": [
"--settings-path",
"common/pyproject.toml"
],
"python.formatting.provider": "none"
}
File renamed without changes.
7 changes: 4 additions & 3 deletions birdxplorer/app.py → api/birdxplorer_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from pydantic.alias_generators import to_snake
from starlette.types import ASGIApp, Receive, Scope, Send

from .logger import get_logger
from birdxplorer_common.logger import get_logger
from birdxplorer_common.settings import GlobalSettings
from birdxplorer_common.storage import gen_storage

from .routers.data import gen_router as gen_data_router
from .routers.system import gen_router as gen_system_router
from .settings import GlobalSettings
from .storage import gen_storage


class QueryStringFlatteningMiddleware:
Expand Down
3 changes: 2 additions & 1 deletion birdxplorer/main.py → api/birdxplorer_api/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from fastapi import FastAPI

from birdxplorer_common.settings import GlobalSettings

from .app import gen_app
from .settings import GlobalSettings


def main() -> FastAPI:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@
from dateutil.parser import parse as dateutil_parse
from fastapi import APIRouter, HTTPException, Query

from ..models import (
from birdxplorer_common.models import (
BaseModel,
LanguageIdentifier,
Note,
NoteId,
ParticipantId,
Post,
PostId,
Topic,
TopicId,
TweetId,
TwitterTimestamp,
UserEnrollment,
)
from ..storage import Storage
from birdxplorer_common.storage import Storage


class TopicListResponse(BaseModel):
data: List[Topic]


class NoteListResponse(BaseModel):
data: List[Note]


class PostListResponse(BaseModel):
data: List[Post]

Expand All @@ -46,7 +55,9 @@ def gen_router(storage: Storage) -> APIRouter:
router = APIRouter()

@router.get("/user-enrollments/{participant_id}", response_model=UserEnrollment)
def get_user_enrollment_by_participant_id(participant_id: ParticipantId) -> UserEnrollment:
def get_user_enrollment_by_participant_id(
participant_id: ParticipantId,
) -> UserEnrollment:
res = storage.get_user_enrollment_by_participant_id(participant_id=participant_id)
if res is None:
raise ValueError(f"participant_id={participant_id} not found")
Expand All @@ -56,6 +67,28 @@ def get_user_enrollment_by_participant_id(participant_id: ParticipantId) -> User
def get_topics() -> TopicListResponse:
return TopicListResponse(data=list(storage.get_topics()))

@router.get("/notes", response_model=NoteListResponse)
def get_notes(
note_ids: Union[List[NoteId], None] = Query(default=None),
created_at_from: Union[None, TwitterTimestamp] = Query(default=None),
created_at_to: Union[None, TwitterTimestamp] = Query(default=None),
topic_ids: Union[List[TopicId], None] = Query(default=None),
post_ids: Union[List[TweetId], None] = Query(default=None),
language: Union[LanguageIdentifier, None] = Query(default=None),
) -> NoteListResponse:
return NoteListResponse(
data=list(
storage.get_notes(
note_ids=note_ids,
created_at_from=created_at_from,
created_at_to=created_at_to,
topic_ids=topic_ids,
post_ids=post_ids,
language=language,
)
)
)

@router.get("/posts", response_model=PostListResponse)
def get_posts(
post_id: Union[List[PostId], None] = Query(default=None),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import APIRouter

from ..models import Message
from birdxplorer_common.models import Message


def gen_router() -> APIRouter:
Expand Down
114 changes: 114 additions & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[build-system]
build-backend = "flit_core.buildapi"
requires = ["flit_core >=3.8.0,<4"]


[project]
name = "birdxplorer_api"
description = "The Web API for BirdXplorer project."
authors = [
{name = "osoken"},
]
dynamic = [
"version",
]
readme = "../README.md"
license = {file = "../LICENSE"}
requires-python = ">=3.10"

classifiers = [
"Development Status :: 3 - Alpha",
"Natural Language :: Japanese",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
]

dependencies = [
"birdxplorer_common @ git+https://github.com/codeforjapan/BirdXplorer.git@feature/issue-53-divide-python-packages#subdirectory=common",
"fastapi",
"python-dateutil",
"pydantic",
"starlette",
"python-dotenv",
]

[project.urls]
Source = "https://github.com/codeforjapan/BirdXplorer"

[tool.setuptools]
packages=["birdxplorer"]

[tool.setuptools.package-data]
birdxplorer = ["py.typed"]

[project.optional-dependencies]
dev=[
"black",
"flake8",
"pyproject-flake8",
"pytest",
"mypy",
"tox",
"isort",
"pytest-mock",
"pytest-cov",
"freezegun",
"types-python-dateutil",
"psycopg2-binary",
"factory_boy",
"uvicorn",
"polyfactory",
"httpx",
]
prod=[
]

[tool.pytest.ini_options]
addopts = ["-sv", "--doctest-modules", "--ignore-glob=birdxplorer_api/main.py", "--cov=birdxplorer_api", "--cov-report=xml", "--cov-report=term-missing"]
testpaths = ["tests", "birdxplorer_api"]
filterwarnings = [
"error",
"ignore:The \\'app\\' shortcut is now deprecated. Use the explicit style \\'transport=WSGITransport\\(app=\\.\\.\\.\\)\\' instead\\.",
]

[tool.black]
line-length = 120
target-version = ['py310']

[tool.flake8]
max-line-length = 120
extend-ignore = "E203,E701"

[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
plugins = ["pydantic.mypy"]

[tool.pydantic.mypy]
init_typed = true

[tool.isort]
profile = "black"
known_first_party = "birdxplorer_api,birdxplorer_common,birdxplorer_etl"

[tool.tox]
legacy_tox_ini = """
[tox]
skipsdist = true
envlist = py310
[testenv]
setenv =
VIRTUALENV_PIP = 24.0
deps =
-e .[dev]
commands =
black birdxplorer_api tests
isort birdxplorer_api tests
pytest
pflake8 birdxplorer_api/ tests/
mypy birdxplorer_api --strict
mypy tests --strict
"""
Loading

0 comments on commit a82d7dc

Please sign in to comment.