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)¶
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.
- 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)]¶
- 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]] = {'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:
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 - ifNone, usegit_dir/NamespaceRepo.name
- property commit: str | None¶
The intended commit to check out.
If
None: ifNamespaceRepo.versions, use the last version. Otherwise useHEADShould match
active_commit, differs semantically in that it is used to set the active_commit, whileactive_commitreads 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:
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:
Trueif in detached head mode,Falseotherwise- Return type:
- check() bool¶
Check if the repository is already cloned and checked out
- Returns:
(bool) True if present, False if not