Git

Define and manage NWB namespaces in external repositories

class NamespaceRepo(*, name: str, repository: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['http', 'https'], host_required=None, default_host=None, default_port=None, default_path=None)] | Annotated[Path, PathType(path_type=dir)], path: Path, versions: List[str] = None, imports: dict[str, Path] | None = None)

Definition of one NWB namespaces file to import from a git repository

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

name: str
repository: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['http', 'https'], host_required=None, default_host=None, default_port=None, default_path=None)] | Annotated[Path, PathType(path_type=dir)]
path: Path
versions: List[str]
imports: dict[str, Path] | None
provide_from_git(commit: str | None = None) Path

Provide a namespace file from a git repo

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'imports': FieldInfo(annotation=Union[dict[str, Path], NoneType], required=False, default=None, description='Any named imports that are included eg. as submodules within their repository. Dict mapping schema name (used in the namespace field) to the namespace file relative to the directory containing the **namespace.yaml file** (not the repo root)'), 'name': FieldInfo(annotation=str, required=True, description='Short name used to refer to this namespace (usually equivalent to the name field within a namespaces NWB list)'), 'path': FieldInfo(annotation=Path, required=True, description='Relative path from the repository root to the namespace file'), 'repository': FieldInfo(annotation=Union[Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['http', 'https'], host_required=None, default_host=None, default_port=None, default_path=None)], Annotated[Path, PathType]], required=True, description='URL or local absolute path to the root repository'), 'versions': FieldInfo(annotation=List[str], required=False, default_factory=list, description='Known versions for this namespace repository, correspond to commit hashes or git tags that can be checked out by :class:`.GitRepo`')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

exception GitError

Exceptions caused by git!

class GitRepo(namespace: NamespaceRepo, commit: str | None = None, path: Path | None = None)

Manage a temporary git repository that provides the NWB yaml files

Parameters:
property temp_directory: Path

Temporary directory where this repository will be cloned to

property remote: str

URL for “origin” remote

property active_commit: str

Currently checked out commit

property namespace_file: Path

Local path to the indicated namespace file.

property import_namespaces: dict[str, Path]

Absolute location of each of the imported namespaces specified in NamespaceRepo.imports

property commit: str | None

The intended commit to check out.

If None: if NamespaceRepo.versions, use the last version. Otherwise use HEAD

Should match active_commit, differs semantically in that it is used to set the active_commit, while active_commit reads what commit is actually checked out

property tag: str

Get/set the currently checked out repo tag.

Returns:

the result of git describe --tags, which is equal to the tag if it is checked out, otherwise it is the tag plus some number of revisions and the short hash.

Return type:

str

Examples

>>> repo = GitRepo(NWB_CORE_REPO)
>>> repo.clone()
>>> # Check out a tag specifically
>>> repo.tag = "2.6.0"
>>> repo.tag
'2.6.0'
>>> # Now check out a commit some number after the tag.
>>> repo.commit = "ec0a879"
>>> repo.tag
'2.6.0-5-gec0a879'
property default_branch: str

Default branch as configured for this repository

Gotten from git symbolic-ref

property detached_head: bool

Detect if repo is in detached HEAD state that might need to be undone before checking out eg. a HEAD commit.

Returns:

True if in detached head mode, False otherwise

Return type:

bool

check() bool

Check if the repository is already cloned and checked out

Returns:

(bool) True if present, False if not

cleanup(force: bool = False) None

Delete contents of temporary directory

If the temp_directory is outside the system temporary directory or

Parameters:

force (bool) – If True, remove git directory no matter where it is

clone(force: bool = False) None

Clone the repository into the temporary directory

Parameters:

force (bool) – If files are present in the temp directory, delete them

Raises:

.GitError