Skip to content

Commit 567e818

Browse files
committed
feat: update pyproject.toml
1 parent 6357a4d commit 567e818

8 files changed

Lines changed: 194 additions & 107 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"ghcr.io/devcontainers-extra/features/nox:2": {},
66
"ghcr.io/devcontainers-extra/features/uv:1": {}
77
},
8-
"postCreateCommand": "uv sync --all-groups --all-extras",
8+
"postCreateCommand": "uv sync",
99
"appPort": [],
1010
"customizations": {
1111
"vscode": {

.github/workflows/ci.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ jobs:
2727
with:
2828
enable-cache: true
2929
- name: Sync dependencies
30-
run: uv sync --all-groups --all-extras --no-group docs
30+
run: uv sync
3131
- name: Run tests
3232
run: uv run pytest
3333
- name: Run linter
34-
run: uv run ruff check .
34+
run: uv run ruff check
35+
- name: Run formatter
36+
run: uv run ruff format --check
3537
- name: Run mypy
36-
run: uv run mypy .
38+
run: uv run mypy
3739
- name: Run basedpyright
38-
run: uv run basedpyright .
40+
run: uv run basedpyright

noxfile.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,42 @@
1212

1313
def install_deps(s: nox.Session, groups: list[str]) -> None:
1414
s.env["UV_PROJECT_ENVIRONMENT"] = s.virtualenv.location
15-
cmd = ["uv", "sync", "--frozen", "--all-extras"]
15+
cmd = ["uv", "sync", "--frozen"]
16+
cmd.append("--no-dev")
1617
for g in groups:
1718
cmd.extend(("--group", g))
1819
_ = s.run_install(*cmd)
1920

2021

21-
@nox.session(python=ALL_PYTHON)
22-
def test(s: nox.Session) -> None:
23-
install_deps(s, [])
22+
@nox.session(reuse_venv=True, default=False)
23+
def check(s: nox.Session) -> None:
24+
install_deps(s, ["test", "typing", "lint"])
25+
_ = s.run("ruff", "format")
26+
_ = s.run("ruff", "check", "--fix")
27+
_ = s.run("ruff", "format")
2428
_ = s.run("pytest")
29+
_ = s.run("mypy")
30+
_ = s.run("basedpyright", "--venvpath", s.virtualenv.location)
2531

2632

2733
@nox.session(python=ALL_PYTHON)
34+
def test(s: nox.Session) -> None:
35+
install_deps(s, ["test"])
36+
_ = s.run("pytest", "--runslow")
37+
38+
39+
@nox.session
2840
def type_check(s: nox.Session) -> None:
29-
install_deps(s, ["type-checking", "examples"])
41+
install_deps(s, ["typing", "examples"])
3042
_ = s.run("mypy", ".")
3143
_ = s.run("basedpyright", "--venvpath", s.virtualenv.location, ".")
3244

3345

3446
@nox.session
3547
def lint(s: nox.Session) -> None:
3648
install_deps(s, ["lint"])
37-
_ = s.run("ruff", "check", ".")
38-
_ = s.run("ruff", "format", "--check", ".")
49+
_ = s.run("ruff", "check")
50+
_ = s.run("ruff", "format", "--check")
3951

4052

4153
@nox.session

pyproject.toml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,35 @@ build-backend = "uv_build"
1515

1616
[dependency-groups]
1717
dev = [
18-
"pydantic>=2.11.9",
19-
"pytest-asyncio>=0.21",
20-
"pytest-codspeed>=4.1.1",
21-
"pytest>=7.0",
18+
{include-group = "lint"},
19+
{include-group = "test"},
20+
{include-group = "typing"},
2221
]
23-
type-checking = [
24-
"basedmypy>=2.10.0",
25-
"basedpyright>=1.31.2",
22+
test = [
23+
"pytest",
24+
"pytest-asyncio",
25+
"pytest-codspeed",
26+
"pydantic",
27+
]
28+
typing = [
29+
"basedmypy",
30+
"basedpyright",
31+
"pytest",
32+
"pydantic",
2633
]
2734
lint = [
28-
"ruff>=0.12.8",
35+
"ruff",
2936
]
3037
docs = [
31-
"mkdocs-material>=9.6.18",
32-
"mkdocs-mermaid2-plugin>=1.2.1",
33-
"mkdocs>=1.6.1",
34-
"mkdocstrings[python]>=0.30.0",
38+
"mkdocs",
39+
"mkdocs-material",
40+
"mkdocs-mermaid2-plugin",
41+
"mkdocstrings[python]",
3542
]
3643
examples = [
37-
"openai>=2.2.0",
38-
"pydantic>=2.11.9",
39-
"rich>=14.1.0",
44+
"openai",
45+
"pydantic",
46+
"rich",
4047
]
4148

4249
[tool.ruff.lint]
@@ -70,15 +77,20 @@ preview = true
7077
docstring-code-format = true
7178

7279
[tool.mypy]
80+
files = ["src", "tests"]
81+
strict = true
82+
python_version = "3.10"
7383
disable_error_code = [
7484
"decorated-any",
7585
"explicit-any",
7686
"any",
7787
]
7888

7989
[tool.pyright]
90+
include = ["src", "tests"]
8091
venv = "."
8192
venvPath = ".venv"
93+
typeCheckingMode = "strict"
8294
enableExperimentalFeatures = true
8395
reportAny = false
8496
reportExplicitAny = false

src/duron/_core/context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ async def run(
104104
raise RuntimeError(msg)
105105

106106
if isinstance(fn, CheckpointOp):
107-
async with self.run_stream(fn, *args, **kwargs) as stream:
107+
async with self.run_stream(
108+
cast("CheckpointOp[_P, _T, Any]", fn), *args, **kwargs
109+
) as stream:
108110
await stream.discard()
109111
return await stream
110112

@@ -142,7 +144,7 @@ def run_stream(
142144
fn.action_type,
143145
fn.initial(),
144146
fn.reducer,
145-
fn,
147+
fn.fn,
146148
*args,
147149
**kwargs,
148150
)

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import cast
2+
3+
import pytest
4+
5+
6+
def pytest_addoption(parser: pytest.OptionGroup) -> None:
7+
parser.addoption(
8+
"--runslow", action="store_true", default=False, help="run slow tests"
9+
)
10+
11+
12+
def pytest_configure(config: pytest.Config) -> None:
13+
config.addinivalue_line("markers", "slow: mark test as slow to run")
14+
15+
16+
def pytest_collection_modifyitems(
17+
config: pytest.Config, items: list[pytest.Item]
18+
) -> None:
19+
if cast("bool", cast("object", config.getoption("--runslow"))):
20+
return
21+
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
22+
for item in items:
23+
if "slow" in item.keywords:
24+
item.add_marker(skip_slow)

tests/test_pydantic.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from typing import TYPE_CHECKING, cast
44
from typing_extensions import Any, override
55

6+
import pydantic
67
import pytest
7-
from pydantic import BaseModel, TypeAdapter
88

99
from duron import Context, fn
1010
from duron.codec import Codec
@@ -15,26 +15,29 @@
1515
from duron.typing import TypeHint
1616

1717

18-
class PydanticPoint(BaseModel):
18+
class PydanticPoint(pydantic.BaseModel):
1919
x: int
2020
y: int
2121

2222

23-
class PydanticCodec(Codec):
24-
@override
25-
def encode_json(self, result: object) -> JSONValue:
26-
return cast(
27-
"JSONValue",
28-
TypeAdapter(type(result)).dump_python(result, mode="json"),
29-
)
30-
31-
@override
32-
def decode_json(self, encoded: JSONValue, expected_type: TypeHint[Any]) -> object:
33-
return cast("object", TypeAdapter(expected_type).validate_python(encoded))
34-
35-
3623
@pytest.mark.asyncio
3724
async def test_pydantic_serialize() -> None:
25+
class PydanticCodec(Codec):
26+
@override
27+
def encode_json(self, result: object) -> JSONValue:
28+
return cast(
29+
"JSONValue",
30+
pydantic.TypeAdapter(type(result)).dump_python(result, mode="json"),
31+
)
32+
33+
@override
34+
def decode_json(
35+
self, encoded: JSONValue, expected_type: TypeHint[Any]
36+
) -> object:
37+
return cast(
38+
"object", pydantic.TypeAdapter(expected_type).validate_python(encoded)
39+
)
40+
3841
@fn(codec=PydanticCodec())
3942
async def activity(ctx: Context) -> PydanticPoint:
4043
def new_pt() -> PydanticPoint:

0 commit comments

Comments
 (0)