polychron.models.Project
Module
Project
dataclass
MVP Model representing a polychron project.
name
instance-attribute
name: str
The name of the project, which is the same as the final element of the path and must be unique within the projects directory
path
instance-attribute
path: Path
The directory representing this project on disk
models
class-attribute
instance-attribute
models: dict[str, Model | None] = field(default_factory=dict)
A dictionary of models within this project, with their name as the key
create_dir
create_dir() -> None
Create the project directory if it does not already exist.
Raises:
Type | Description |
---|---|
OSError
|
Propagated from |
NotADirectoryError
|
Propagated from |
has_model
has_model(name: str) -> bool
Cheeck if a model exists within the project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the model to check for |
required |
Returns:
Type | Description |
---|---|
bool
|
Boolean indicating if the model exist or not (i.e. the model directory exists as a minimum) |
get_model
get_model(name: str) -> Model | None
Get a model from within the project, loading from disk if it has not yet been loaded
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the model to attempt to fetch |
required |
Returns:
Type | Description |
---|---|
Model | None
|
The |
Raises:
Type | Description |
---|---|
RuntimeWarning
|
when the model could not be loaded, but in a recoverable way. I.e. the directory exits but no files are contained (so allow the model to be "loaded") |
RuntimeError
|
when the model could not be loaded, but use of this model directory should be prevented? |
get_or_create_model
get_or_create_model(name: str, other: Model | None = None) -> Model
Get or create a model within this Project, copying a reference model if provided
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the model to be fetched or created |
required |
other
|
Model | None
|
An optional model to copy from |
None
|
Returns:
Type | Description |
---|---|
Model
|
The existing or new model with the specified model name |
Raises:
Type | Description |
---|---|
RuntimeWarning
|
when the model could not be loaded, but in a recoverable way. I.e. the directory exits but no files are contained (so allow the model to be "loaded") |
RuntimeError
|
when the model could not be loaded, but use of this model directory should be prevented? |
RuntimeError
|
if the model already exists or an invalid name is provided. |
OSError
|
if the model directories could not be created, e.g. due to permissions or avialable space. |
NotADirectoryError
|
Propagated from |
create_model
create_model(name: str, other: Model | None = None) -> Model
Create a new model within the project with the provided name , copying a reference model if provided
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the model to be created |
required |
other
|
Model | None
|
An optional model to copy from |
None
|
Returns:
Type | Description |
---|---|
Model
|
The new Model |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the model already exists or an invalid name is provided. |
OSError
|
if the model directories could not be created, e.g. due to permissions or available space. |
NotADirectoryError
|
Propagated from |
load_model_from_disk
load_model_from_disk(name: str) -> None
Load a single model from disk by it's name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the model to load. |
required |
Raises:
Type | Description |
---|---|
RuntimeWarning
|
when the model could not be loaded, but in a recoverable way. I.e. the directory exits but no files are contained (so allow the model to be "loaded") |
RuntimeError
|
when the model could not be loaded, but use of this model directory should be prevented? |
lazy_load
lazy_load() -> None
Lazily load all models from disk within this project.
This update the models dictionary to ensure that each model which could be loaded from disk is listed as a model, without performing the (relatively) expensive disk operations. This does not guarantee the model will be loadable.
I.e. any non-empty directory within the project directory is considered to be a model.
load
load() -> None
Load all models within this project from disk.
Raises:
Type | Description |
---|---|
RuntimeWarning
|
when the model could not be loaded, but in a recoverable way. I.e. the directory exits but no files are contained (so allow the model to be "loaded") |
RuntimeError
|
when the model could not be loaded, but use of this model directory should be prevented? |