Git#

Define and manage NWB namespaces in external repositories

pydantic model NamespaceRepo#

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.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Fields:
field name: str [Required]#

Short name used to refer to this namespace (usually equivalent to the name field within a namespaces NWB list)

field path: Path [Required]#

Relative path from the repository root to the namespace file

field repository: Url | Path [Required]#

URL or local absolute path to the root repository

field versions: List[str] [Optional]#

Known versions for this namespace repository, correspond to commit hashes or git tags that can be checked out by GitRepo

provide_from_git(commit: str | None = None) Path#
exception GitError#
class GitRepo(namespace: NamespaceRepo, commit: str | None = None, path: Path | None = None)#

Manage a temporary git repository that provides the NWB yaml files

Parameters:
  • namespace (NamespaceRepo) – The namespace repository to clone!

  • commit (str) – A specific commit or tag to check out

  • path (pathlib.Path) – A directory to clone to - if None, use git_dir / NamespaceRepo.name

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 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 = "gec0a879"
>>> 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)#

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)#

Clone the repository into the temporary directory

Parameters:

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

Raises:

.GitError