brightway-projects

Management of projects in the Brightway Life Cycle Asssessment framework


Keywords
bw3, life-cycle-assessment, python
License
BSD-1-Clause
Install
pip install brightway-projects==0.1.dev1

Documentation

bw_projects

PyPI Status Python Version License

Tests Codecov

pre-commit Black

This is a library to manage subdirectories, so that work on a project can be isolated from other projects. It is designed for use with the Brightway life cycle assessment software framework, but has no dependencies on Brightway and can be used on its own.

Project metadata is stored in SQLite using the Peewee ORM. The SQLite file is in the base_directory, and project data is stored in subdirectories. By default, platformdirs is used to create the base_directory, though this can be overridden.

Installation

Via pip or conda (conda-forge channel).

Depends on:

Usage

Initializing the ProjectsManager

from bw_projects import ProjectsManager  # This doesn't create anything yet


projects_manager = ProjectsManager()  # This gets default config and initializes directories and database

Overriding defaults

## You can override default directory by providing a base directory in constructor
## You can also override the default database name
from bw_projects import ProjectsManager

projects_manager = ProjectsManager(dir_base_data="<path/to/your/base/directory>", database_name="projects.db")
## You can also override configurations of default directory
from bw_projects import Configuration, ProjectsManager

config = Configuration(
 			app_name: str = "Brightway3",
        	app_author: str = "pycla",
		)
projects_manager = ProjectsManager(config=config)

Callbacks

## You can setup callbacks on projects creation, activation and deletion
from bw_projects import ProjectsManager

def callback_activate_project(manager: ProjectsManager, name: str, attributes: Dict[str, str], dir_path: str):
	print(f"Manager with {len(manager)} projects activated project {name} with {attributes} and {dir_path}.")

projects_manager = ProjectsManager(callbacks_activate_project=callback_activate_project)

Project management

❗ Project names may be changed when creating projects
## Before calling any project-management feature, the project name is slugified
## You can get the new name of the project by running:
project = projects_manager.get_clean_directory_name("Компьютер")
project
>> kompiuter
## Create a project without activating it:
projects_manager.create_project("<project_name>")
## Create a project and activate it:
projects_manager.create_project("<project_name>", activate=True)
## Iterate over projects:
for project in projects_manager:
	print(project.name, project.attributes)
## Activate a project:
projects_manager.activate("<project_name>")
## Delete a project from SQLite database and deleting the directory:
projects_manager.delete_project("<project_name>")
## Delete a project from SQLite database without deleting the directory:
projects_manager.delete_project("<project_name>", delete_dir=False)

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the BSD-2-Clause license, bw_projects is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.