Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bw2data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"weightings",
]

__version__ = "4.6.2"
__version__ = "4.7"

from bw2data.configuration import config, labels
from bw2data.project import projects
Expand Down
1 change: 1 addition & 0 deletions bw2data/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ def process(self, csv=False):
name=clean_datapackage_name(self.name + " activity metadata"),
)

dp.metadata["database_dependencies"] = sorted(dependents)
dp.finalize_serialization()

self.metadata["depends"] = sorted(dependents)
Expand Down
9 changes: 9 additions & 0 deletions bw2data/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class Updates:
"automatic": True,
"explanation": "bw2data 4.0 release switched to a new database search implementation",
},
"4.7 database dependencies in datapackage": {
"method": "expire_all_processed_data_47",
"automatic": True,
"explanation": "bw2data 4.7 adds database_dependencies to datapackage metadata; all databases must be reprocessed",
},
}

@classmethod
Expand Down Expand Up @@ -226,6 +231,10 @@ def processed_data_format_change_23(cls):
def expire_all_processed_data_40(cls):
cls._reprocess_all()

@classmethod
def expire_all_processed_data_47(cls):
cls._reprocess_all()

@classmethod
def fix_migrations_filename(cls):
""" "Fix migration data filenames to use shorter hash.
Expand Down
57 changes: 57 additions & 0 deletions tests/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,63 @@ def test_processed_array():
assert array[0]["uncertainty_type"] == 7


@bw2test
def test_process_writes_database_dependencies_to_datapackage():
Database("other database").write(
{
("other database", "x"): {
"type": "process",
"exchanges": [
{"input": ("other database", "x"), "amount": 1, "type": "production"}
],
}
}
)
db_a = Database("a database")
db_a.write(
{
("a database", "1"): {
"type": "process",
"exchanges": [
{
"input": ("a database", "1"),
"amount": 1,
"type": "production",
},
{
"input": ("other database", "x"),
"amount": 0.5,
"type": "technosphere",
},
],
}
}
)
package = db_a.datapackage()
assert package.metadata["database_dependencies"] == ["other database"]


@bw2test
def test_process_writes_empty_database_dependencies_when_no_external_inputs():
db = Database("a database")
db.write(
{
("a database", "1"): {
"type": "process",
"exchanges": [
{
"input": ("a database", "1"),
"amount": 1,
"type": "production",
}
],
}
}
)
package = db.datapackage()
assert package.metadata["database_dependencies"] == []


@bw2test
def test_processed_array_with_metadata():
database = Database("a database")
Expand Down
Loading