rcds.project — Projects

class rcds.Project(root: Path, docker_client: DockerClient | None = None)[source]

An rCDS project; the context that all actions are done within

rcds.project.config - Config loading

Functions for loading project config files

rcds.project.config.check_config(config_file: Path) Tuple[Dict[str, Any] | None, Iterable[ValidationError] | None][source]

Load and validate a config file, returning any errors encountered.

If the config file is valid, the tuple returned contains the loaded config as the first element, and the second element is None. Otherwise, the second element is an iterable of errors that occurred during validation

This method wraps parse_config().

Parameters:

config_file (pathlib.Path) – The challenge config to load

rcds.project.config.load_config(config_file: Path) Dict[str, Any][source]

Loads a config file, or throw an exception if it is not valid

This method wraps check_config(), and throws the first error returned if there are any errors.

Parameters:

config_file (pathlib.Path) – The challenge config to load

Returns:

The loaded config

rcds.project.config.parse_config(config_file: Path) Iterable[ValidationError | Dict[str, Any]][source]

Load and validate a config file, returning both the config and any errors encountered.

Parameters:

config_file (pathlib.Path) – The challenge config to load

Returns:

Iterable containing any errors (all instances of rcds.errors.ValidationError) and the parsed config. The config will always be last.

rcds.project.assets - Asset management

class rcds.project.assets.AssetManager(project: rcds.Project)[source]

Class for managing assets from challenges that are provided to competitors

This class manages all assets under a given project.

create_context(name: str) AssetManagerContext[source]

Create a subcontext within the AssetManager

Parameters:

name (str) – The name of the context (challenge id)

Raises:

ValueError – if the context name is not valid

list_context_names() Iterable[str][source]

List the names of all subcontexts within this AssetManager

Returns:

The contexts’ names. Call create_context() on a name to obtain a AssetManagerContext object

class rcds.project.assets.AssetManagerContext(asset_manager: AssetManager, name: str)[source]

A subcontext within an AssetManager

Represents a namespace within the AssetManager, essentially a subdirectory. The context holds assets for a challenge with the same id

This class is not meant to be constructed directly, use AssetManager.create_context()

clear() None[source]

Clear all files in this context

exists(name: str) bool[source]

Queries if an asset exists

Parameters:

name (str) – The name of the asset

Returns:

Whether or not it exists

get(name: str) Path[source]

Retrieves the asset

Parameters:

name (str) – The name of the asset

Returns:

The asset

get_mtime(name: str) float[source]

Retrieves the time an asset was modified

Parameters:

name (str) – The name of the asset

Returns:

The time the asset was modified (:attr`os.stat_result.st_mtime`)

ls() Iterable[str][source]

List all files within this context

Returns:

The list of asset names

sync(*, check: bool = True)[source]

Syncs the manifest for this context to disk

Parameters:

check (bool) – If true (default), check to make sure all files in the manifest exist, and that there are no extra files

transaction() AssetManagerTransaction[source]

Create a AssetManagerTransaction.

Only one transaction can be created at a time.

Returns:

The transaction

Raises:

RuntimeError – when attempting to create a transaction while one already exists

class rcds.project.assets.AssetManagerTransaction(asset_manager_context: AssetManagerContext)[source]

A transaction within an AssetManagerContext

This class manages declarative transactional updates to a context, allowing you to declare the files that should exist in the context, the last time that file was modified, and a callable to run to get the file, should it be out-of-date in the cache. The transaction starts in a blank state; without adding anything by calling add(), commit() will clear the context. No actions are performed until commit() is called.

This classs is not meant to be constructed directly, use AssetManagerContext.transaction()

add(name: str, mtime: float, contents: BinaryIO | Path | bytes | Callable[[], BinaryIO | Path | bytes]) None[source]

Add a file to the context

Parameters:
  • name (str) – The name of the asset to add

  • mtime (float) – The time the asset to add was modified (os.stat_result.st_mtime)

  • contents (File or Callable[[], File]) – The contents of the file - this can either be the contents directly as a File, or a thunk function that, when calls, returns the contents

Raises:
  • RuntimeError – if the transaction has already been committed

  • ValueError – if the asset name is not valid

add_file(name: str, file: Path)[source]

Add an already-existing file on disk to the context

This wraps add()

Parameters:
  • name (str) – The name of the asset to add

  • file (Path) – The path to the asset on disk

commit() None[source]

Commit the transaction.

This transaction can no longer be used after commit() is called.

rcds.project.assets.File

Something that the asset manager can interpret as a file (contents only)

Valid types:

alias of BinaryIO | Path | bytes