Skip to content

Commit

Permalink
Merge pull request #253 from shunichironomura/remove-pydantic
Browse files Browse the repository at this point in the history
Remove Pydantic
  • Loading branch information
shunichironomura authored Jun 29, 2024
2 parents 93b80ee + e29dba1 commit 74148f4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 38 deletions.
14 changes: 0 additions & 14 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@
"editor.insertSpaces": true
},
"python.languageServer": "Pylance",
"cSpell.words": [
"autouse",
"capsula",
"dgst",
"figsize",
"globalvars",
"hexsha",
"HHMMSS",
"pydantic",
"pyproject",
"pytest",
"savefig",
"xlim"
],
"yaml.schemas": {
"https://squidfunk.github.io/mkdocs-material/schema.json": "mkdocs.yml"
},
Expand Down
8 changes: 4 additions & 4 deletions capsula/_reporter/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import timedelta
from pathlib import Path
from types import TracebackType
from typing import TYPE_CHECKING, Any, Callable, Optional
from typing import TYPE_CHECKING, Any, Callable

import orjson

Expand Down Expand Up @@ -39,8 +39,8 @@ def __init__(
self,
path: Path | str,
*,
default: Optional[Callable[[Any], Any]] = None,
option: Optional[int] = None,
default: Callable[[Any], Any] | None = None,
option: int | None = None,
mkdir: bool = True,
) -> None:
self.path = Path(path)
Expand Down Expand Up @@ -80,7 +80,7 @@ def _str_to_tuple(s: str | tuple[str, ...]) -> tuple[str, ...]:
def default(
cls,
*,
option: Optional[int] = None,
option: int | None = None,
) -> Callable[[CapsuleParams], JsonDumpReporter]:
def callback(params: CapsuleParams) -> JsonDumpReporter:
return cls(
Expand Down
20 changes: 11 additions & 9 deletions capsula/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import queue
import threading
from collections import deque
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from random import choices
from string import ascii_letters, digits
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Literal, Tuple, TypeVar, Union, overload

from pydantic import BaseModel
from typing import TYPE_CHECKING, Any, Callable, Generic, Literal, TypeVar, Union, overload

from capsula._reporter import ReporterBase
from capsula.encapsulator import Encapsulator
Expand All @@ -32,18 +31,21 @@
logger = logging.getLogger(__name__)


class FuncInfo(BaseModel):
@dataclass
class FuncInfo:
func: Callable[..., Any]
args: Tuple[Any, ...]
kwargs: Dict[str, Any]
args: tuple[Any, ...]
kwargs: dict[str, Any]


class CommandInfo(BaseModel):
@dataclass
class CommandInfo:
command: str


class CapsuleParams(BaseModel):
exec_info: Union[FuncInfo, CommandInfo, None]
@dataclass
class CapsuleParams:
exec_info: FuncInfo | CommandInfo | None
run_dir: Path
phase: Literal["pre", "in", "post"]

Expand Down
5 changes: 3 additions & 2 deletions examples/calculate_pi_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import logging
import random
import sys
from pathlib import Path
from typing import Optional

import click

Expand All @@ -24,7 +25,7 @@
help="The seed to use for the random number generator passed to numpy.random.default_rng.",
default=None,
)
def main(n: int, seed: Optional[int] = None) -> None:
def main(n: int, seed: int | None = None) -> None:
"""Calculate pi using the Monte Carlo method."""
if n < 1:
logger.error("n must be greater than or equal to 1.")
Expand Down
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ packages = [{ include = "capsula" }]

[tool.poetry.dependencies]
python = ">=3.8"
pydantic = ">=2.0.2"
py-cpuinfo = ">=9.0.0"
gitpython = ">=3.1.31"
tomli = { version = ">=2.0.1", python = "<3.11" }
Expand All @@ -33,7 +32,6 @@ mypy = "1.10.1"
pytest = "8.2.2"
coverage = "7.5.4"
genbadge = { extras = ["coverage"], version = "1.1.1" }
tomli-w = "1.0.0"

[tool.poetry.group.examples.dependencies]
click = ">=8.1.3"
Expand Down Expand Up @@ -109,13 +107,6 @@ ignore = [
]


[tool.ruff.lint.flake8-type-checking]
runtime-evaluated-base-classes = ["pydantic.BaseModel"]

[tool.ruff.lint.pyupgrade]
# Keep runtime typing for Pydantic.
keep-runtime-typing = true

[tool.ruff.lint.per-file-ignores]
"examples/*" = [
"INP001", # implicit-namespace-package
Expand Down

0 comments on commit 74148f4

Please sign in to comment.