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 independently.
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.
Via pip or conda (conda-forge
channel).
Depends on:
from bw_projects import ProjectsManager # This doesn't create anything yet
projects_manager = ProjectsManager() # This gets default config and initializes directories and database
## 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="<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",
dir_relative_logs: str = "logs",
)
projects_manager = ProjectsManager(config=config)
## 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 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_project_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)
Contributions are very welcome. To learn more, see the Contributor Guide.
Distributed under the terms of the BSD-2-Clause license, bw_projects is free and open source software.
If you encounter any problems, please file an issue along with a detailed description.