Skip to content

Commit 3f20eb2

Browse files
authored
chore: basedpyright -> ty, + flake.nix (#85)
1 parent 4ea5066 commit 3f20eb2

30 files changed

+256
-172
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ config/*
2020
# lockfiles
2121
uv.lock
2222

23-
.basedpyright
24-
2523
.ipynb_checkpoints
2624

27-
.dprint.json
25+
# env
26+
.direnv
27+
.envrc

.pre-commit-config.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ repos:
1111
- id: pyupgrade
1212

1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.12.7
14+
rev: v0.13.0
1515
hooks:
1616
- id: ruff-check
1717
args: [--fix]
1818
- id: ruff-format
1919

20-
- repo: https://github.com/DetachHead/basedpyright-pre-commit-mirror
21-
rev: 1.31.1
20+
- repo: local
21+
# TODO: replace once available
2222
hooks:
23-
- id: basedpyright
23+
- id: ty
24+
name: ty check
25+
entry: uvx ty@latest check
26+
language: system
27+
always_run: true
28+
pass_filenames: false
2429

2530
- repo: https://github.com/tombi-toml/tombi-pre-commit
26-
rev: v0.4.42
31+
rev: v0.6.4
2732
hooks:
2833
- id: tombi-format
2934
- id: tombi-lint

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
3+
inputs.flake-utils.url = "github:numtide/flake-utils";
4+
5+
outputs = {
6+
nixpkgs,
7+
flake-utils,
8+
...
9+
}:
10+
flake-utils.lib.eachDefaultSystem (
11+
system: let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
in {
14+
devShells.default = with pkgs;
15+
mkShell {
16+
packages =
17+
[
18+
git
19+
git-lfs
20+
uv
21+
ytt
22+
just
23+
]
24+
++ lib.optional stdenv.isDarwin [ffmpeg];
25+
26+
shellHook = lib.optionalString stdenv.isDarwin ''
27+
export DYLD_FALLBACK_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [pkgs.ffmpeg]}
28+
'';
29+
};
30+
}
31+
);
32+
}

hatch_build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515

1616
@final
17-
class BuildYaakIdlProtosHook(BuildHookInterface): # pyright: ignore[reportMissingTypeArgument]
18-
PLUGIN_NAME = "build-yaak-idl-protos" # pyright: ignore[reportIncompatibleUnannotatedOverride]
17+
class BuildYaakIdlProtosHook(BuildHookInterface):
18+
PLUGIN_NAME = "build-yaak-idl-protos"
1919

2020
YAAK_IDL_PROTO_PATH = (
2121
Path(__file__).resolve().parent
@@ -63,7 +63,7 @@ def _build_yaak_idl_protos(cls) -> None:
6363
*cls.YAAK_IDL_PROTOS,
6464
]
6565

66-
if protoc.main(protoc_cmd) != 0: # pyright: ignore[reportUnknownMemberType]
66+
if protoc.main(protoc_cmd) != 0:
6767
msg = f"error: {protoc_cmd} failed"
6868
raise RuntimeError(msg)
6969

justfile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@ _default:
99
sync:
1010
uv sync --all-extras --all-groups
1111

12-
install-tools:
13-
uv tool install --force --upgrade ruff
14-
uv tool install --force --upgrade basedpyright
15-
uv tool install --force --upgrade pre-commit --with pre-commit-uv
16-
1712
install-duckdb-extensions:
1813
uv run python -c "import duckdb; duckdb.connect().install_extension('spatial')"
1914

20-
setup: sync install-tools install-duckdb-extensions
15+
setup: sync install-duckdb-extensions
2116
git submodule update --init --recursive --force --remote
2217
git lfs pull
23-
uvx pre-commit install --install-hooks
18+
uvx --with=pre-commit-uv pre-commit install --install-hooks
2419

2520
build:
2621
uv build
@@ -32,10 +27,10 @@ lint *ARGS:
3227
uvx ruff check {{ ARGS }}
3328

3429
typecheck *ARGS:
35-
uvx basedpyright {{ ARGS }}
30+
uvx ty@latest check {{ ARGS }}
3631

3732
pre-commit *ARGS: build
38-
uvx pre-commit run --all-files --color=always {{ ARGS }}
33+
uvx --with=pre-commit-uv pre-commit run --all-files --color=always {{ ARGS }}
3934

4035
generate-config:
4136
ytt --ignore-unknown-comments \

pyproject.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@ test = [
7474
requires = ["hatchling>=1.27.0"]
7575
build-backend = "hatchling.build"
7676

77-
[tool.basedpyright]
78-
typeCheckingMode = "all"
79-
enableTypeIgnoreComments = true
80-
reportMissingTypeStubs = "none"
81-
reportAny = "none"
82-
reportExplicitAny = "none"
83-
reportIgnoreCommentWithoutRule = "error"
84-
venvPath = "."
85-
venv = ".venv"
86-
include = ["src/"]
87-
ignore = ["src/**/*_pb2.py", "**/*.pyi"]
88-
8977
[tool.hatch.metadata]
9078
allow-direct-references = true
9179

@@ -132,7 +120,6 @@ ignore = [
132120
"CPY",
133121
"COM812",
134122
"F722",
135-
"PD901",
136123
"ISC001",
137124
"TD",
138125
"TC006",

src/rbyte/batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from torch import Tensor
55

66

7-
class BatchMeta(TensorClass, autocast=True): # pyright: ignore[reportGeneralTypeIssues, reportCallIssue]
7+
class BatchMeta(TensorClass, autocast=True):
88
sample_idx: Tensor | None = None
99
input_id: NonTensorData | None = None
1010

1111

12-
class Batch(TensorClass, autocast=True): # pyright: ignore[reportGeneralTypeIssues, reportCallIssue]
13-
data: TensorDict | None = None # pyright: ignore[reportIncompatibleMethodOverride]
12+
class Batch(TensorClass, autocast=True):
13+
data: TensorDict | None = None
1414
meta: BatchMeta | None = None
1515

1616

src/rbyte/dataset.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040

4141
class SourceConfig(BaseModel):
42-
source: HydraConfig[TensorSource] # pyright: ignore[reportMissingTypeArgument]
42+
source: HydraConfig[TensorSource]
4343
index_column: str
4444

4545

@@ -83,7 +83,7 @@ class BasePipelineConfig(BaseModel):
8383
def _validate_inputs(
8484
cls, value: Sequence[dict[str, Any]]
8585
) -> Sequence[dict[str, Any]]:
86-
if not mit.all_equal(map(tree_structure, value)): # pyright: ignore[reportArgumentType]
86+
if not mit.all_equal(map(tree_structure, value)): # ty: ignore[invalid-argument-type]
8787
msg = "inputs have different structures"
8888
raise ValueError(msg)
8989

@@ -171,7 +171,7 @@ def get_batch(
171171
self,
172172
index: int | Sequence[int] | slice | range,
173173
*,
174-
keys: BatchKeys = BATCH_KEYS_DEFAULT,
174+
keys: BatchKeys = BATCH_KEYS_DEFAULT, # ty: ignore[invalid-parameter-default]
175175
) -> Batch:
176176
subkeys: dict[Literal["data", "meta"], set[_ALL_TYPE | str]] = {
177177
"data": set(),
@@ -217,7 +217,7 @@ def get_batch(
217217

218218
source_data = {
219219
row[Column.source_id]: torch.stack([
220-
self._get_source(source)[idxs] # pyright: ignore[reportUnknownMemberType]
220+
self._get_source(source)[idxs]
221221
for (source, idxs) in zip(
222222
row[Column.source_config],
223223
row[Column.source_idxs],
@@ -232,7 +232,7 @@ def get_batch(
232232
sample_data_cols = (
233233
pl.all()
234234
if _ALL in subkeys_data
235-
else pl.col(subkeys_data - source_data.keys()) # pyright: ignore[reportArgumentType]
235+
else pl.col(subkeys_data - source_data.keys())
236236
).exclude(Column.sample_idx, Column.input_id)
237237

238238
samples_subset = samples.select(sample_data_cols.to_physical())
@@ -242,7 +242,7 @@ def get_batch(
242242
except TypeError:
243243
sample_data = samples_subset.to_dict(as_series=False)
244244

245-
data = TensorDict(source_data | sample_data, batch_size=batch_size) # pyright: ignore[reportArgumentType]
245+
data = TensorDict(source_data | sample_data, batch_size=batch_size)
246246

247247
else:
248248
data = None
@@ -277,8 +277,8 @@ def __len__(self) -> int:
277277
return len(self.samples)
278278

279279
@cache # noqa: B019
280-
def _get_source(self, config: str) -> TensorSource: # pyright: ignore[reportUnknownParameterType, reportMissingTypeArgument] # noqa: PLR6301
281-
return HydraConfig[TensorSource].model_validate_json(config).instantiate() # pyright: ignore[reportUnknownVariableType, reportMissingTypeArgument]
280+
def _get_source(self, config: str) -> TensorSource: # noqa: PLR6301
281+
return HydraConfig[TensorSource].model_validate_json(config).instantiate()
282282

283283
@classmethod
284284
def _build_samples(
@@ -293,33 +293,33 @@ def _build_samples(
293293

294294
case PipelineHydraConfig():
295295
pipeline = samples.pipeline.instantiate()
296-
executor: Executor | dict[OUTPUT_TYPE, Executor] | None = tree_map( # pyright: ignore[reportAssignmentType]
296+
executor: Executor | dict[OUTPUT_TYPE, Executor] | None = tree_map( # ty: ignore[invalid-assignment]
297297
HydraConfig[Executor].instantiate,
298-
samples.executor, # pyright: ignore[reportArgumentType]
298+
samples.executor, # ty: ignore[invalid-argument-type]
299299
)
300300

301301
pipeline.print_documentation()
302-
inputs = tree_transpose( # pyright: ignore[reportUnknownVariableType]
303-
tree_structure(list(range(len(samples.inputs)))), # pyright: ignore[reportArgumentType]
304-
tree_structure(samples.inputs[0]), # pyright: ignore[reportArgumentType]
305-
samples.inputs, # pyright: ignore[reportArgumentType]
302+
inputs = tree_transpose(
303+
tree_structure(list(range(len(samples.inputs)))), # ty: ignore[invalid-argument-type]
304+
tree_structure(samples.inputs[0]), # ty: ignore[invalid-argument-type]
305+
samples.inputs, # ty: ignore[invalid-argument-type]
306306
)
307307

308308
results = pipeline.map(
309-
inputs=inputs, # pyright: ignore[reportArgumentType]
309+
inputs=inputs, # ty: ignore[invalid-argument-type]
310310
executor=executor,
311311
**samples.model_dump(exclude={"pipeline", "inputs", "executor"}),
312312
)
313313

314314
if pipeline.profile:
315315
pipeline.print_profiling_stats()
316316

317-
output_name: str = pipeline.unique_leaf_node.output_name # pyright: ignore[reportUnknownMemberType, reportAssignmentType]
317+
output_name: str = pipeline.unique_leaf_node.output_name
318318

319319
result: pl.DataFrame = (
320320
results[output_name].output
321321
if results
322-
else load_outputs(output_name, run_folder=samples.run_folder) # pyright: ignore[reportArgumentType]
322+
else load_outputs(output_name, run_folder=samples.run_folder) # ty: ignore[invalid-argument-type]
323323
)
324324

325325
return (
@@ -346,7 +346,7 @@ def _build_sources(cls, sources: SourcesConfig) -> pl.DataFrame:
346346
source_cfg.model_dump(exclude={"source"})
347347
| {
348348
"id": source_id,
349-
"config": source_cfg.source.model_dump_json( # pyright: ignore[reportUnknownMemberType]
349+
"config": source_cfg.source.model_dump_json(
350350
by_alias=True
351351
),
352352
}
@@ -357,8 +357,8 @@ def _build_sources(cls, sources: SourcesConfig) -> pl.DataFrame:
357357
],
358358
schema_overrides={Column.input_id: input_id_enum},
359359
)
360-
.explode(k)
361-
.unnest(k)
362-
.select(Column.input_id, pl.exclude(Column.input_id).name.prefix(f"{k}."))
360+
.explode(k) # ty: ignore[unresolved-reference]
361+
.unnest(k) # ty: ignore[unresolved-reference]
362+
.select(Column.input_id, pl.exclude(Column.input_id).name.prefix(f"{k}.")) # ty: ignore[unresolved-reference]
363363
.rechunk()
364364
)

src/rbyte/io/_duckdb/dataframe_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@final
1010
class DuckDbDataFrameBuilder:
11-
__name__ = __qualname__
11+
__name__ = __qualname__ # ty: ignore[unresolved-reference]
1212

1313
@validate_call
1414
def __call__(self, *, query: str, path: PathLike[str]) -> pl.DataFrame:

0 commit comments

Comments
 (0)