Skip to content

Commit

Permalink
ci: add type stubs for datalad_core
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-monch committed Oct 28, 2024
1 parent 8e59457 commit 0f3f987
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 0 deletions.
8 changes: 8 additions & 0 deletions resources/type_stubs/datalad_core/config/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .defaults import ImplementationDefaults as ImplementationDefaults, get_defaults as get_defaults
from .git import DataladBranchConfig as DataladBranchConfig, GitConfig as GitConfig, GlobalGitConfig as GlobalGitConfig, LocalGitConfig as LocalGitConfig, SystemGitConfig as SystemGitConfig, WorktreeGitConfig as WorktreeGitConfig
from .gitenv import GitEnvironment as GitEnvironment
from .item import ConfigItem as ConfigItem
from .manager import ConfigManager as ConfigManager, get_manager as get_manager
from datasalad.settings import UnsetValue as UnsetValue

__all__ = ['ConfigItem', 'ConfigManager', 'GitConfig', 'SystemGitConfig', 'GlobalGitConfig', 'LocalGitConfig', 'DataladBranchConfig', 'WorktreeGitConfig', 'GitEnvironment', 'ImplementationDefaults', 'UnsetValue', 'get_defaults', 'get_manager']
7 changes: 7 additions & 0 deletions resources/type_stubs/datalad_core/config/defaults.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from datasalad.settings import Defaults

class ImplementationDefaults(Defaults): ...

def get_defaults() -> ImplementationDefaults: ...
def register_defaults_gitcfg(defaults: ImplementationDefaults) -> None: ...
def anything2bool(val): ...
31 changes: 31 additions & 0 deletions resources/type_stubs/datalad_core/config/git.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import abc
from _typeshed import Incomplete
from collections.abc import Hashable
from datalad_core.config.item import ConfigItem as ConfigItem
from datalad_core.consts import DATALAD_BRANCH_CONFIG_RELPATH as DATALAD_BRANCH_CONFIG_RELPATH
from datalad_core.runners import CommandError as CommandError, call_git as call_git, call_git_oneline as call_git_oneline, iter_git_subproc as iter_git_subproc
from datasalad.settings import CachingSource, Setting as Setting
from os import PathLike

lgr: Incomplete

class GitConfig(CachingSource, metaclass=abc.ABCMeta):
def __init__(self) -> None: ...
def __contains__(self, key: Hashable) -> bool: ...

class SystemGitConfig(GitConfig): ...
class GlobalGitConfig(GitConfig): ...

class LocalGitConfig(GitConfig):
def __init__(self, path: PathLike) -> None: ...

class WorktreeGitConfig(GitConfig):
def __init__(self, path: PathLike) -> None: ...

class DataladBranchConfig(LocalGitConfig):
def __init__(self, path: PathLike) -> None: ...
@property
def is_writable(self): ...

cfg_k_regex: Incomplete
cfg_kv_regex: Incomplete
8 changes: 8 additions & 0 deletions resources/type_stubs/datalad_core/config/gitenv.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from collections.abc import Generator, Hashable
from datalad_core.config.item import ConfigItem as ConfigItem
from datalad_core.config.utils import get_gitconfig_items_from_env as get_gitconfig_items_from_env, set_gitconfig_items_in_env as set_gitconfig_items_in_env
from datasalad.settings import Setting as Setting, WritableMultivalueSource

class GitEnvironment(WritableMultivalueSource):
item_type = ConfigItem
def overrides(self, overrides: dict[Hashable, Setting | tuple[Setting, ...]]) -> Generator[None]: ...
3 changes: 3 additions & 0 deletions resources/type_stubs/datalad_core/config/item.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from datasalad.settings import Setting

class ConfigItem(Setting): ...
16 changes: 16 additions & 0 deletions resources/type_stubs/datalad_core/config/manager.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from collections.abc import Generator, Hashable
from datalad_core.config.defaults import ImplementationDefaults as ImplementationDefaults, get_defaults as get_defaults
from datalad_core.config.git import GlobalGitConfig as GlobalGitConfig, SystemGitConfig as SystemGitConfig
from datalad_core.config.gitenv import GitEnvironment as GitEnvironment
from datalad_core.config.item import ConfigItem as ConfigItem
from datasalad.settings import Setting as Setting, Settings, Source as Source
from typing import Any

class ConfigManager(Settings):
def __init__(self, defaults: ImplementationDefaults, sources: dict[str, Source] | None = None) -> None: ...
def overrides(self, overrides: dict[Hashable, Setting | tuple[Setting, ...]]) -> Generator[ConfigManager]: ...
def get(self, key: Hashable, default: Any = None) -> Setting: ...
def get_from_protected_sources(self, key: Hashable, default: Any = None) -> Setting: ...
def declare_source_protected(self, key: str): ...

def get_manager() -> ConfigManager: ...
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ..defaults import anything2bool as anything2bool, get_defaults as get_defaults

def test_implementationdefaults() -> None: ...
def test_anything2bool() -> None: ...
12 changes: 12 additions & 0 deletions resources/type_stubs/datalad_core/config/tests/test_git.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from ..git import DataladBranchConfig as DataladBranchConfig, GlobalGitConfig as GlobalGitConfig, LocalGitConfig as LocalGitConfig
from ..item import ConfigItem as ConfigItem
from datalad_core.consts import DATALAD_BRANCH_CONFIG_RELPATH as DATALAD_BRANCH_CONFIG_RELPATH
from datalad_core.runners import call_git_oneline as call_git_oneline

def test_global_git_config() -> None: ...
def test_global_git_config_pure(cfgman) -> None: ...
def test_local_git_config_norepo(tmp_path) -> None: ...
def test_local_git_config(gitrepo) -> None: ...
def test_datalad_branch_config(gitrepo) -> None: ...
def test_datalad_branch_shorthand(gitrepo) -> None: ...
def test_gitcfg_rec_to_keyvalue() -> None: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ..gitenv import GitEnvironment as GitEnvironment
from datalad_core.runners import call_git_lines as call_git_lines, call_git_oneline as call_git_oneline

def test_gitenv_singlevalue() -> None: ...
def test_gitenv_multivalue() -> None: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from datalad_core.config import ConfigItem as ConfigItem, UnsetValue as UnsetValue, get_manager as get_manager
from datalad_core.repo import Repo as Repo, Worktree as Worktree
from datalad_core.tests.fixtures import magic_marker as magic_marker

def test_manager_setup() -> None: ...
def test_manager_overrides() -> None: ...
def test_manager_fordataset(gitrepo) -> None: ...
def test_manager_forbaredataset(baregitrepo) -> None: ...
def test_manager_protected_query(gitrepo) -> None: ...
6 changes: 6 additions & 0 deletions resources/type_stubs/datalad_core/config/tests/test_utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .. import utils as utils
from ..utils import get_gitconfig_items_from_env as get_gitconfig_items_from_env, set_gitconfig_items_in_env as set_gitconfig_items_in_env

def test_get_gitconfig_items_from_env(monkeypatch) -> None: ...
def test_set_gitconfig_items_in_env(monkeypatch) -> None: ...
def test_get_set_gitconfig_env_roundtrip(monkeypatch) -> None: ...
4 changes: 4 additions & 0 deletions resources/type_stubs/datalad_core/config/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from collections.abc import Mapping

def get_gitconfig_items_from_env() -> dict[str, str | tuple[str, ...]]: ...
def set_gitconfig_items_in_env(items: Mapping[str, str | tuple[str, ...]]): ...

0 comments on commit 0f3f987

Please sign in to comment.