bw2data.project#

Attributes#

Classes#

Functions#

add_full_hash_column(→ None)

add_sourced_columns(→ None)

lockable()

signal_dispatcher(→ Union[int, None])

Not sure why this is necessary, but fails silently if call add_revision directly

signal_dispatcher_generic_no_diff(→ int)

signal_dispatcher_on_database_write(→ int)

signal_dispatcher_on_update_formula_parameter_name(→ int)

writable_project(wrapped, instance, args, kwargs)

Module Contents#

class bw2data.project.ProjectDataset[source]#

Bases: peewee.Model

_check_local_versus_remote_revision(local: str | None, remote: str | None) None[source]#
_fast_forward(graph: bw2data.revisions.RevisionGraph, revision: bw2data.revisions.ID)[source]#

Moves the current head forward, if necessary.

_load_revisions(head: bw2data.revisions.ID | None = None) Tuple[bw2data.revisions.ID, Sequence[bw2data.revisions.Revision]] | None[source]#

Reads all revisions from disk.

_rebase(graph: bw2data.revisions.RevisionGraph) collections.abc.Iterable[bw2data.revisions.Revision][source]#

Rebases current revision list on top of remote head, if necessary.

In a trivial fast-forward merge, this function will simply return the revisions which need to be applied. If a rebase is necessary, it will: - move the head to the merge base - return the (remote) revision range to be applied on top of it - move the head of the graph to the rebased head, the project head can

be fast-forwarded to it after the application of the remote revisions

_write_head(head: bw2data.revisions.ID | None = None)[source]#

Write starting revision to disk.

_write_revision(revision: bw2data.revisions.Revision)[source]#

Write revision to disk.

add_revision(delta: Sequence[bw2data.revisions.Delta], metadata: dict[str, Any] | None = None) int | None[source]#

Add a revision to the project changing the state of one or more objects.

{
“metadata”: {

“revision”: <this-revision-id> “parent_revision”: <parent-revision-id> “title”: “<optional>” “description”: “<optional>” “authors”: “<optional>” (maybe shouldn’t be optional)

}, “data”: [

{

“type”: “database object type” (e.g. “activity”, “exchange”, “parameter”), “id”: “database object id” (e.g. “foo”, “bar”, “baz”), “delta”: <difference between revisions>

}, …

]

}

apply_revision(revision: dict) None[source]#

Load a patch generated from a previous add_revision into the project.

load_revisions(head: int | None = None) None[source]#

Load all revisions unapplied for this project.

set_sourced() None[source]#

Set the project to be event sourced.

data[source]#
property dir[source]#
full_hash[source]#
is_sourced[source]#
name[source]#
revision[source]#
class bw2data.project.ProjectManager[source]#

Bases: collections.abc.Iterable

_create_base_directories()[source]#
_do_automatic_updates()[source]#

Run any available automatic updates

_get_base_directories()[source]#
_project_dir(p: ProjectDataset | None = None) pathlib.Path[source]#
_reset_meta()[source]#
_reset_sqlite3_databases()[source]#
change_base_directories(base_dir: pathlib.Path, base_logs_dir: pathlib.Path | None = None, project_name: str | None = 'default', update: bool | None = True) None[source]#
copy_project(new_name, switch=True)[source]#

Copy current project to a new project named new_name. If switch, switch to new project.

create_project(name=None, **kwargs)[source]#
delete_project(name=None, delete_dir=False)[source]#

Delete project name, or the current project.

name is the project to delete. If name is not provided, delete the current project.

By default, the underlying project directory is not deleted; only the project name is removed from the list of active projects. If delete_dir is True, then also delete the project directory.

If deleting the current project, this function sets the current directory to default if it exists, or to a random project.

Returns the current project.

migrate_project_25()[source]#

Migrate project to Brightway 2.5.

Reprocesses all databases and LCIA objects.

purge_deleted_directories()[source]#

Delete project directories for projects which are no longer registered.

Returns number of directories deleted.

rename_project(new_name: str) None[source]#

Rename current project, and switch to the new project.

report()[source]#

Give a report on current projects, including installed databases and file sizes.

Returns tuples of (project name, number of databases, size of all databases (GB)).

request_directory(name)[source]#

Return the absolute path to the subdirectory dirname, creating it if necessary.

Returns False if directory can’t be created.

set_current(name, writable=True, update=True)[source]#
use_full_hash()[source]#
use_short_hash()[source]#
_basic_directories = ('backups', 'intermediate', 'lci', 'processed', 'revisions')[source]#
_is_temp_dir = False[source]#
property current[source]#
db[source]#
property dir[source]#
property logs_dir[source]#
property output_dir[source]#

Get directory for output files.

Uses environment variable BRIGHTWAY2_OUTPUT_DIR; preferences['output_dir']; or directory output in current project.

Returns output directory path.

read_only = False[source]#
property twofive[source]#
bw2data.project.add_full_hash_column(base_data_dir: pathlib.Path, db: peewee.SqliteDatabase) None[source]#
bw2data.project.add_sourced_columns(base_data_dir: pathlib.Path, db: peewee.SqliteDatabase) None[source]#
bw2data.project.lockable()[source]#
bw2data.project.signal_dispatcher(sender, old: Any | None = None, new: Any | None = None, operation: str | None = None) int | None[source]#

Not sure why this is necessary, but fails silently if call add_revision directly

bw2data.project.signal_dispatcher_generic_no_diff(sender, name: str, verb: str, prefix: str, obj_type: str) int[source]#
bw2data.project.signal_dispatcher_on_database_write(sender, name: str) int[source]#
bw2data.project.signal_dispatcher_on_update_formula_parameter_name(sender, old: str, new: str, kind: str, extra: str = '') int[source]#
bw2data.project.writable_project(wrapped, instance, args, kwargs)[source]#
bw2data.project.READ_ONLY_PROJECT = Multiline-String[source]#
Show Value
"""
***Read only project***

This project is being used by another process and no writes can be made until:
    1. You close the other program, or switch to a different project, *and*
    2. You call `projects.enable_writes` *and* get the response `True`.

    If you are **sure** that this warning is incorrect, call
    `projects.enable_writes(force=True)` to enable writes.
"""
bw2data.project.projects[source]#
bw2data.project.signal_dispatcher_on_activity_code_change[source]#
bw2data.project.signal_dispatcher_on_activity_database_change[source]#
bw2data.project.signal_dispatcher_on_activity_parameter[source]#
bw2data.project.signal_dispatcher_on_activity_parameter_recalculate[source]#
bw2data.project.signal_dispatcher_on_activity_parameter_recalculate_exchanges[source]#
bw2data.project.signal_dispatcher_on_activity_parameter_update_formula_activity_parameter_name[source]#
bw2data.project.signal_dispatcher_on_activity_parameter_update_formula_database_parameter_name[source]#
bw2data.project.signal_dispatcher_on_activity_parameter_update_formula_project_parameter_name[source]#
bw2data.project.signal_dispatcher_on_database[source]#
bw2data.project.signal_dispatcher_on_database_delete[source]#
bw2data.project.signal_dispatcher_on_database_metadata_change[source]#
bw2data.project.signal_dispatcher_on_database_parameter[source]#
bw2data.project.signal_dispatcher_on_database_parameter_recalculate[source]#
bw2data.project.signal_dispatcher_on_database_parameter_update_formula_database_parameter_name[source]#
bw2data.project.signal_dispatcher_on_database_parameter_update_formula_project_parameter_name[source]#
bw2data.project.signal_dispatcher_on_database_reset[source]#
bw2data.project.signal_dispatcher_on_project_parameter[source]#
bw2data.project.signal_dispatcher_on_project_parameter_recalculate[source]#
bw2data.project.signal_dispatcher_on_project_parameter_update_formula_parameter_name[source]#