Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions .github/workflows/build-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,8 @@ jobs:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install git-annex ubuntu
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install git-annex

- name: Install git-annex macos
if: matrix.os == 'macos-latest'
run: brew install git-annex

- name: Install git-annex windows
if: matrix.os == 'windows-latest'
uses: crazy-max/ghaction-chocolatey@v3
with:
args: install git-annex --yes --ignore-checksums
continue-on-error: true # This can fail for stupid reasons ¯\_(ツ)_/¯
- name: Install git-annex
run: uv tool install git-annex

- name: Show software versions
run: |
Expand Down
28 changes: 19 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"bidsschematools >=1.0",
"attrs >=24.1",
"bidsschematools >= 1.0.10",
]

[project.optional-dependencies]
test = [
"pytest >=8",
"pytest-cov >=5",
"coverage[toml] >=7.2",
"datalad >=1.1",
]
cli = [
"typer >=0.15",
]
Expand Down Expand Up @@ -97,7 +92,10 @@ exclude = ".*"

[tool.ruff]
line-length = 99
extend-exclude = ["_version.py"]
extend-exclude = [
"_version.py",
"tests/data",
]

[tool.ruff.lint]
extend-select = [
Expand Down Expand Up @@ -136,7 +134,19 @@ inline-quotes = "single"

[tool.ruff.lint.extend-per-file-ignores]
"setup.py" = ["D"]
"*/test_*.py" = ["S101"]
"*/test_*.py" = [
"S101",
"D",
]

[tool.ruff.format]
quote-style = "single"

[dependency-groups]
test = [
"pytest >=8",
"pytest-cov >=5",
"coverage[toml] >=7.2",
"datalad >=1.1",
"cattrs>=24.1.3",
]
19 changes: 19 additions & 0 deletions src/bids_validator/types/_typings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
__all__ = (
'Self',
'TYPE_CHECKING',
'Any',
)

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any, Self
else:

def __getattr__(name: str):
if name in __all__:
import typing

return getattr(typing, name)

msg = f'Module {__name__!r} has no attribute {name!r}'
raise AttributeError(msg)
18 changes: 10 additions & 8 deletions src/bids_validator/types/files.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""Types for working with file trees."""

from __future__ import annotations

import os
import posixpath
import stat
from functools import cached_property
from pathlib import Path
from typing import Union

import attrs
from typing_extensions import Self # PY310

from . import _typings as t

__all__ = ('FileTree',)

Expand Down Expand Up @@ -58,7 +60,7 @@ def is_symlink(self) -> bool:
return stat.S_ISLNK(_stat.st_mode)


def as_direntry(obj: os.PathLike) -> Union[os.DirEntry, UserDirEntry]:
def as_direntry(obj: os.PathLike) -> os.DirEntry | UserDirEntry:
"""Convert PathLike into DirEntry-like object."""
if isinstance(obj, os.DirEntry):
return obj
Expand All @@ -69,10 +71,10 @@ def as_direntry(obj: os.PathLike) -> Union[os.DirEntry, UserDirEntry]:
class FileTree:
"""Represent a FileTree with cached metadata."""

direntry: Union[os.DirEntry, UserDirEntry] = attrs.field(repr=False, converter=as_direntry)
parent: Union['FileTree', None] = attrs.field(repr=False, default=None)
direntry: os.DirEntry | UserDirEntry = attrs.field(repr=False, converter=as_direntry)
parent: FileTree | None = attrs.field(repr=False, default=None)
is_dir: bool = attrs.field(default=False)
children: dict[str, 'FileTree'] = attrs.field(repr=False, factory=dict)
children: dict[str, FileTree] = attrs.field(repr=False, factory=dict)
name: str = attrs.field(init=False)

def __attrs_post_init__(self):
Expand All @@ -85,8 +87,8 @@ def __attrs_post_init__(self):
def read_from_filesystem(
cls,
direntry: os.PathLike,
parent: Union['FileTree', None] = None,
) -> Self:
parent: FileTree | None = None,
) -> t.Self:
"""Read a FileTree from the filesystem.

Uses :func:`os.scandir` to walk the directory tree.
Expand Down
2 changes: 0 additions & 2 deletions tests/types/test_files.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# ruff: noqa: D100

import attrs

from bids_validator.types.files import FileTree
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ pass_env =
CLICOLOR
CLICOLOR_FORCE
extras =
test
cli
dependency_groups =
test
uv_resolution =
min: lowest-direct
deps =
Expand Down
Loading