craftr.core.project

craftr.core.project.project

Project Objects

class Project()

A project is a collection of tasks, usually populated through a build script, tied to a directory. Projects can have sub projects and there is usually only one root project in build.

__init__

 | __init__(context: 'Context', parent: t.Optional['Project'] = None, directory: t.Union[None, str, Path] = None) -> None

Create a new project. If no directory is specified, it will default to the parent directory of the caller. If the given context does not have a root project defined yet, the project will be promoted to the root project.

task

 | task(name: str, task_class: t.Optional[t.Type[T_Task]] = None) -> T_Task

Create a new task of type task_class (defaulting to Task) and add it to the project. The task name must be unique within the project.

tasks

 | @property
 | tasks() -> 'TaskContainer'

Returns the TaskContainer object for this project.

subproject

 | subproject(directory: str) -> 'Project'

Reference a subproject by a path relative to the project directory. If the project has not been loaded yet, it will be created and initialized.

get_subproject_by_name

 | get_subproject_by_name(name: str) -> 'Project'

Returns a sub project of this project by it's name. Raises a ValueError if no sub project with the specified name exists in the project.

subprojects

 | @t.overload
 | subprojects() -> t.List['Project']

Returns a list of the project's loaded subprojects.

subprojects

 | @t.overload
 | subprojects(closure: t.Callable[['Project'], None]) -> None

Call closure for every subproject currently loaded in the project..

on_apply

 | on_apply(func: Closure) -> None

Register a function to call when the project is applied using apply from_project: <project>.

apply

 | apply(plugin_name: t.Optional[str] = None, from_project: t.Union[None, str, 'Project'] = None, merge: bool = True) -> Namespace

Loads a plugin and applies it to the project. Plugins are loaded via Context.plugin_loader and applied to the project immediately after. The default implementation for loading plugins uses Python package entrypoints as configured in the Context.

Returns the extension namespace created for the plugin. The extension is also merged into the Project.ext namespace unless the merge parameter is set to False.

glob

 | glob(pattern: str) -> t.List[Path]

Apply the specified glob pattern relative to the project directory and return a list of the matched files.

craftr.core.project.loader

craftr.core.project.loader.default

Implements the default project loader which loads build.craftr.py files and executes them as a plain Python script providing the current Project in the global scope.

craftr.core.project.loader.api

craftr.core.project.loader.delegate

DelegateProjectLoader Objects

class DelegateProjectLoader(IProjectLoader,  IHasFromSettings)

Delegates the project loading process to a sequence of other loaders. Returns the first project loaded by any loader.

If created from configuration, the craftr.plugin.loader.delegates option is respected, which must be a comma-separated list of fully qualified lodaer names. A loader name may be trailed by a question mark to ignore if the loader name cannot be resolved.