Skip to content

Commit

Permalink
Merge pull request #171 from ku-nlp/develop
Browse files Browse the repository at this point in the history
Fix a bug where documentation contents are not built
  • Loading branch information
nobu-g authored Nov 9, 2023
2 parents 0b7499e + 72d686c commit 4ae2989
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 92 deletions.
27 changes: 0 additions & 27 deletions .coveragerc

This file was deleted.

8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ repos:
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
hooks:
- id: absolufy-imports
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
Expand All @@ -35,10 +31,6 @@ repos:
- fastapi
- jinja2
- pygments
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
Expand Down
4 changes: 0 additions & 4 deletions .pydocstyle

This file was deleted.

17 changes: 10 additions & 7 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
alabaster==0.7.13 ; python_version >= "3.8" and python_version < "4.0"
babel==2.12.1 ; python_version >= "3.8" and python_version < "4.0"
babel==2.13.1 ; python_version >= "3.8" and python_version < "4.0"
beautifulsoup4==4.12.2 ; python_version >= "3.8" and python_version < "4.0"
certifi==2023.7.22 ; python_version >= "3.8" and python_version < "4.0"
charset-normalizer==3.2.0 ; python_version >= "3.8" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.8" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and sys_platform == "win32"
docutils==0.20.1 ; python_version >= "3.8" and python_version < "4.0"
furo==2023.9.10 ; python_version >= "3.8" and python_version < "4.0"
idna==3.4 ; python_version >= "3.8" and python_version < "4.0"
imagesize==1.4.1 ; python_version >= "3.8" and python_version < "4.0"
importlib-metadata==6.7.0 ; python_version >= "3.8" and python_version < "3.10"
importlib-metadata==6.8.0 ; python_version >= "3.8" and python_version < "3.10"
jinja2==3.1.2 ; python_version >= "3.8" and python_version < "4.0"
markdown-it-py==3.0.0 ; python_version >= "3.8" and python_version < "4.0"
markupsafe==2.1.3 ; python_version >= "3.8" and python_version < "4.0"
mdit-py-plugins==0.4.0 ; python_version >= "3.8" and python_version < "4.0"
mdurl==0.1.2 ; python_version >= "3.8" and python_version < "4.0"
myst-parser==2.0.0 ; python_version >= "3.8" and python_version < "4.0"
packaging==23.1 ; python_version >= "3.8" and python_version < "4.0"
packaging==23.2 ; python_version >= "3.8" and python_version < "4.0"
pygments==2.16.1 ; python_version >= "3.8" and python_version < "4.0"
pytz==2023.3.post1 ; python_version >= "3.8" and python_version < "3.9"
pyyaml==6.0.1 ; python_version >= "3.8" and python_version < "4.0"
requests==2.31.0 ; python_version >= "3.8" and python_version < "4.0"
setuptools==68.2.2 ; python_version >= "3.12" and python_version < "4.0"
snowballstemmer==2.2.0 ; python_version >= "3.8" and python_version < "4.0"
soupsieve==2.5 ; python_version >= "3.8" and python_version < "4.0"
sphinx-basic-ng==1.0.0b2 ; python_version >= "3.8" and python_version < "4.0"
sphinx-copybutton==0.5.2 ; python_version >= "3.8" and python_version < "4.0"
sphinx-prompt==1.7.0 ; python_version >= "3.8" and python_version < "3.11"
sphinx-prompt==1.7.0 ; python_version >= "3.8" and python_version < "3.9"
sphinx-prompt==1.8.0 ; python_version >= "3.9" and python_version < "4.0"
sphinx==7.1.2 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-applehelp==1.0.4 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-devhelp==1.0.2 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-htmlhelp==2.0.1 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-jsmath==1.0.1 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-qthelp==1.0.3 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-serializinghtml==1.1.5 ; python_version >= "3.8" and python_version < "4.0"
urllib3==2.0.4 ; python_version >= "3.8" and python_version < "4.0"
zipp==3.15.0 ; python_version >= "3.8" and python_version < "3.10"
typing-extensions==4.8.0 ; python_version >= "3.8" and python_version < "4.0"
urllib3==2.0.7 ; python_version >= "3.8" and python_version < "4.0"
zipp==3.17.0 ; python_version >= "3.8" and python_version < "3.10"
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 46 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ ipython = [
{ version = "^8.13", python = ">=3.9" },
]
ipdb = "^0.13.13"
setuptools = "^68.2" # https://stackoverflow.com/questions/75307814/error-python-packaging-tool-setuptools-not

[tool.poetry.group.test.dependencies]
pytest = "^7.2"
coverage = "^7.3"
coverage = { version = "^7.3", extras = ["toml"] }
pytest-cov = "^4.1"
httpx = "^0.25.0"

Expand All @@ -70,6 +71,7 @@ sphinx-copybutton = "^0.5.0"
myst-parser = "^2.0"
markdown-it-py = "^3.0"
furo = "^2023.9"
typing-extensions = ">=4.4"

[tool.poetry.extras]
cli = ["typer", "PyYAML", "rich", "uvicorn", "fastapi", "jinja2", "pygments"]
Expand Down Expand Up @@ -100,12 +102,53 @@ ignore = [
"RUF003", # Comment contains ambiguous `(` (FULLWIDTH LEFT PARENTHESIS). Did you mean `(` (LEFT PARENTHESIS)?
"COM812", # Trailing comma missing
"PLR2004", # Magic value used in comparison
"D100", # Missing docstring in public module
"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
"D301", # Use `r"""` if any backslashes in a docstring
"D403", # First word of the first line should be properly capitalized
"D415", # First line should end with a period, question mark, or exclamation point
"ANN002", # Missing type annotation for `*args`
"ANN003", # Missing type annotation for `**kwargs`
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in classmethod
]
select = ["F", "E", "W", "I", "B", "PL", "PD", "NPY", "RUF", "UP", "TID", "COM", "PT"]
select = ["F", "E", "W", "I", "B", "PL", "PD", "NPY", "RUF", "UP", "TID", "COM", "PT", "D", "ARG", "PYI", "ANN"]

[tool.ruff.flake8-bugbear]
[tool.ruff.per-file-ignores]
"__init__.py" = [
"D104" # Missing docstring in `__init__`
]
"tests/*" = ["D", "ANN"]

[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = ["typer.Argument", "typer.Option"]

[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.coverage.run]
omit = ["tests/*"]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__", # Do not complain about missing debug-only code
"except ImportError", # Do not complain about packages we have installed
# Do not complain if tests do not hit defensive assertion code
"raise AssertionError",
"raise NotImplementedError",
"raise ImportError",
# Do not complain if non-runnable code is not run
"if TYPE_CHECKING:",
"if __name__ == .__main__.:",
"@(abc\\.)?abstractmethod", # Do not complain about abstract methods
"@overload", # Do not complain about overloads
]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
22 changes: 12 additions & 10 deletions src/rhoknp/cli/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ class _Span:


class _HTTPExceptionForIndex(fastapi.HTTPException):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
pass


class _HTTPExceptionForAnalyze(fastapi.HTTPException):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
pass


def _get_string_diff(pre_text: str, post_text) -> List[_Span]:
def _get_string_diff(pre_text: str, post_text: str) -> List[_Span]:
"""編集前後の文字列の差分を取得.
Args:
Expand Down Expand Up @@ -75,6 +73,8 @@ def _draw_tree(document: Document, show_rel: bool = False, show_pas: bool = Fals
Args:
document: 解析結果.
show_rel: True なら <rel> タグの内容を表示.
show_pas: True なら述語項構造を表示.
Returns:
構文木.
Expand Down Expand Up @@ -150,15 +150,17 @@ def create_app(analyzer: AnalyzerType, base_url: str = "/", *args, **kwargs) ->
templates.env.globals["base_url"] = base_url

@app.exception_handler(_HTTPExceptionForIndex)
async def http_exception_handler_for_index(request: fastapi.Request, exc: _HTTPExceptionForIndex):
async def http_exception_handler_for_index(
request: fastapi.Request, exc: _HTTPExceptionForIndex
) -> fastapi.Response:
return templates.TemplateResponse(
template_name,
{"request": request, "error": exc.detail},
status_code=exc.status_code,
)

@app.get("/", response_class=fastapi.responses.HTMLResponse)
async def index(request: fastapi.Request, text: str = ""):
async def index(request: fastapi.Request, text: str = "") -> fastapi.Response:
analyzed_document: Optional[Document] = None
if text != "":
try:
Expand All @@ -171,14 +173,14 @@ async def index(request: fastapi.Request, text: str = ""):
)

@app.exception_handler(_HTTPExceptionForAnalyze)
async def http_exception_handler_for_analyze(request: fastapi.Request, exc: _HTTPExceptionForAnalyze):
async def http_exception_handler_for_analyze(_: fastapi.Request, exc: _HTTPExceptionForAnalyze) -> fastapi.Response:
return fastapi.responses.JSONResponse(
content={"error": {"code": exc.status_code, "message": exc.detail}},
status_code=exc.status_code,
)

@app.get("/analyze", response_class=fastapi.responses.JSONResponse)
async def analyze(text: str):
async def analyze(text: str) -> fastapi.Response:
if text == "":
raise _HTTPExceptionForAnalyze(fastapi.status.HTTP_400_BAD_REQUEST, detail="text is empty")
try:
Expand All @@ -187,7 +189,7 @@ async def analyze(text: str):
result = analyzed_document.to_jumanpp()
else:
result = analyzed_document.to_knp()
return {"text": text, "result": result}
return fastapi.responses.JSONResponse(content={"text": text, "result": result})
except Exception as e:
raise _HTTPExceptionForAnalyze(fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e)) from e

Expand Down
8 changes: 4 additions & 4 deletions src/rhoknp/cohesion/argument.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from enum import Enum
from typing import TYPE_CHECKING, Any, Optional, Union
from typing import TYPE_CHECKING, Optional, Union

from rhoknp.cohesion.exophora import ExophoraReferent
from rhoknp.cohesion.predicate import Predicate
Expand Down Expand Up @@ -52,7 +52,7 @@ def __repr__(self) -> str:
raise NotImplementedError

@abstractmethod
def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
raise NotImplementedError

@property
Expand Down Expand Up @@ -96,7 +96,7 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return self.base_phrase.text

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)):
return False
if self._pas is not None and other._pas is not None:
Expand Down Expand Up @@ -171,7 +171,7 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return str(self.exophora_referent)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)):
return False
if self._pas is not None and other._pas is not None:
Expand Down
4 changes: 2 additions & 2 deletions src/rhoknp/cohesion/discourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from dataclasses import dataclass
from enum import Enum
from typing import TYPE_CHECKING, Any, ClassVar, Optional
from typing import TYPE_CHECKING, ClassVar, Optional

if TYPE_CHECKING:
from rhoknp import Clause, Sentence
Expand Down Expand Up @@ -133,7 +133,7 @@ class DiscourseRelation:
head: "Clause" #: 主辞節.
is_explicit: bool = False #: 明示的な談話関係ならTrue..

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)):
return False
return self.label == other.label and self.modifier == other.modifier and self.head == other.head
Expand Down
4 changes: 2 additions & 2 deletions src/rhoknp/cohesion/exophora.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import re
from enum import Enum
from typing import Any, ClassVar, Optional
from typing import ClassVar, Optional

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -64,7 +64,7 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return f"{self.__class__.__name__}(text={self.text!r})"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)) or self.type != other.type:
return False
if self.type == ExophoraReferentType.OTHER:
Expand Down
2 changes: 1 addition & 1 deletion src/rhoknp/cohesion/pas.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def is_empty(self) -> bool:
return False
return True

def parse_pas_string(self, base_phrase: "BasePhrase", pas_string: str, format_: CaseInfoFormat):
def parse_pas_string(self, base_phrase: "BasePhrase", pas_string: str, format_: CaseInfoFormat) -> None:
"""PAS 文字列から述語項構造を生成する.
Args:
Expand Down
4 changes: 2 additions & 2 deletions src/rhoknp/cohesion/predicate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from rhoknp.cohesion.pas import Pas
Expand Down Expand Up @@ -81,7 +81,7 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return f"<{self.__module__}.{self.__class__.__name__}: {self.text!r}>"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)) or self.base_phrase != other.base_phrase:
return False
if self.cfid is None or other.cfid is None:
Expand Down
2 changes: 1 addition & 1 deletion src/rhoknp/cohesion/rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class RelTag:
base_phrase_index: Optional[int]
mode: Optional[RelMode]

def __post_init__(self):
def __post_init__(self) -> None:
if self.type.startswith("="):
if self.type not in COREF_TYPES:
logger.warning(f"Unknown coreference type: {self.type} ({self})")
Expand Down
2 changes: 1 addition & 1 deletion src/rhoknp/processors/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __call__(self, text: Union[str, Sentence, Document], timeout: int = 10) -> U
引数の型が ``Sentence`` の場合は ``apply_to_sentence`` を呼び出す.
引数の型が ``Document`` の場合は ``apply_to_document`` を呼び出す.
"""
return self.apply(text)
return self.apply(text, timeout=timeout)

@overload
def apply(self, text: str, timeout: int = 10) -> Document:
Expand Down
4 changes: 2 additions & 2 deletions src/rhoknp/units/base_phrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __getstate__(self) -> Dict[str, Any]:
state["eids_nonidentical"] = tuple(entity.eid for entity in state["entities_nonidentical"])
return state

def __setstate__(self, state) -> None:
def __setstate__(self, state: Dict[str, Any]) -> None:
# Restore eids to Entity objects for hashing.
for entity, eid in zip(state["entities"], state.pop("eids")):
entity.eid = eid
Expand Down Expand Up @@ -114,7 +114,7 @@ def __post_init__(self) -> None:
self._add_argument(rel_tag)

@override
def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, type(self)):
return False
if self.parent_unit != other.parent_unit:
Expand Down
Loading

0 comments on commit 4ae2989

Please sign in to comment.