Repository¶
Repositories are used for storing, packaging and loading different types of resources that can be used by Topwrap.
An example of the implementation of a concrete repository is the topwrap.repo.user_repo.UserRepo class.
Its user interface is documented in Constructing, configuring and loading repositories.
API reference¶
- class Resource(name: str)¶
Base class for representing a resource in a repository. Each derived resource should define its own structure.
- name : str¶
Name of the resource
- class ResourceHandler¶
Base for classes that can perform various operations on resources of a given type.
The main responsibilities of a resource handler are saving and loading resources of a given type in a repository.
-
add_resource(resources: dict[str, ResourceType], res: ResourceType, exists_strategy: ExistsStrategy =
ExistsStrategy.RAISE)¶ Custom behavior for adding a resource to a loaded repository :raises ResourceExistsException: Resource already exists in the repository
- abstract load(repo_path: Path) Iterator[ResourceType]¶
Loads list of resources from the repo_path repository
- remove_resource(resources: dict[str, ResourceType], res: ResourceType)¶
Custom behavior for removing a resource from a loaded repository :raises ResourceNotFoundException: Could not find that resource
- resource_type : Type[ResourceType]¶
For which resource type this handler is responsible
-
add_resource(resources: dict[str, ResourceType], res: ResourceType, exists_strategy: ExistsStrategy =
- class Repo(resource_handlers: list[ResourceHandler[Resource]], name: str)¶
Base class for implementing repositories. A repository is a container for resources of various types.
Derived classes should be associated with a set of supported resource handlers that define what types of resources can be stored in the repo. An example of such derived repo is
UserRepo-
add_files(handler: FileHandler, exist_strategy: ExistsStrategy =
ExistsStrategy.RAISE) None¶ Parses resources available in files and adds them to the repository
- Parameters:¶
- handler: FileHandler¶
Handler that contains sources
- exist_strategy: ExistsStrategy =
ExistsStrategy.RAISE¶ What to do if resource exists in repo already
- Raises:¶
ResourceExistsException – Raised when exist_strategy is set to RAISE
ResourceNotSupportedException – Raised when handler returns resources not supported by repo
-
add_resource(resource: Resource, exist_strategy: ExistsStrategy =
ExistsStrategy.RAISE) None¶ Adds a single resource to the repository
- get_resource(resource_type: type[ResourceType], name: str) ResourceType¶
Searches for resource with given type in repository
- Raises:¶
ResourceNotFoundException – Raised when resource with given name isn’t present
ResourceNotSupportedException – Raised when resource is not supported by repo implementation
- get_resources(type: type[ResourceType]) list[ResourceType]¶
Implements the same operation as self.resources[type] but gives correct hints to the typechecker
- name : str¶
Name of the repository
-
add_files(handler: FileHandler, exist_strategy: ExistsStrategy =
- class FileHandler(files: Iterable[File])¶
Base class for file handlers. A file handler is used to extract repository resources from a set of given files.