Skip to content

Commit b768a44

Browse files
Switch from Pydantic to msgspec (#65)
1 parent 34a469f commit b768a44

File tree

5 files changed

+42
-187
lines changed

5 files changed

+42
-187
lines changed

pixi_kernel/env.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from pathlib import Path
33

4-
from pydantic import ValidationError
4+
import msgspec
55

66
from .compatibility import run_pixi
77
from .types import PixiInfo
@@ -20,8 +20,8 @@ async def envs_from_path(path: Path) -> list[str]:
2020
return [DEFAULT_ENVIRONMENT]
2121

2222
try:
23-
pixi_info = PixiInfo.model_validate_json(stdout, strict=True)
24-
except ValidationError:
23+
pixi_info = msgspec.json.decode(stdout, type=PixiInfo)
24+
except msgspec.MsgspecError:
2525
return [DEFAULT_ENVIRONMENT]
2626

2727
if len(pixi_info.environments) == 0:

pixi_kernel/readiness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from pathlib import Path
44

5-
from pydantic import ValidationError
5+
import msgspec
66
from returns.result import Failure, Result, Success
77

88
from .compatibility import has_compatible_pixi, run_pixi
@@ -48,8 +48,8 @@ async def verify_env_readiness(
4848
return Failure(f"Failed to run 'pixi info': {stderr}")
4949

5050
try:
51-
pixi_info = PixiInfo.model_validate_json(stdout, strict=True)
52-
except ValidationError as exception:
51+
pixi_info = msgspec.json.decode(stdout, type=PixiInfo)
52+
except msgspec.MsgspecError as exception:
5353
return Failure(f"Failed to parse 'pixi info' output: {stdout}\n{exception}")
5454

5555
if pixi_info.project is None:

pixi_kernel/types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
from typing import Optional
44

5-
from pydantic import BaseModel, Field
5+
import msgspec
66

77

8-
class PixiInfo(BaseModel):
9-
environments: list[Environment] = Field(alias="environments_info")
10-
project: Optional[Project] = Field(alias="project_info")
8+
class PixiInfo(msgspec.Struct, frozen=True, kw_only=True):
9+
environments: list[Environment] = msgspec.field(name="environments_info")
10+
project: Optional[Project] = msgspec.field(name="project_info")
1111

1212

13-
class Environment(BaseModel):
13+
class Environment(msgspec.Struct, frozen=True, kw_only=True):
1414
name: str
1515
dependencies: list[str]
1616
pypi_dependencies: list[str]
1717
prefix: str
1818

1919

20-
class Project(BaseModel):
20+
class Project(msgspec.Struct, frozen=True, kw_only=True):
2121
manifest_path: str

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ requires-python = ">=3.9,<4.0"
3535
dependencies = [
3636
"ipykernel>=6",
3737
"jupyter-client>=7",
38-
"jupyter_server>=2.4.0",
39-
"pydantic>=2",
38+
"jupyter_server>=2.4",
39+
"msgspec>=0.18",
4040
"returns>=0.23",
4141
"tomli>=2; python_version<'3.11'",
4242
]
@@ -50,7 +50,7 @@ Repository = "https://github.com/renan-r-santos/pixi-kernel"
5050
dev-dependencies = [
5151
"jupyter-kernel-test>=0.7",
5252
"jupyterlab>=4",
53-
"msgspec[toml]>=0.19.0",
53+
"msgspec[toml]>=0.18",
5454
"mypy>=1",
5555
"pytest>=8",
5656
"pytest-asyncio>=1",

0 commit comments

Comments
 (0)