Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Dec 5, 2023
2 parents 0a64eaf + da2f208 commit abc2f04
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# this workflow re-uses the workflow 'github_action_trigger_submodule_pull_main.yml' in the brightway-documentation repository
name: Create Workflow Dispatch (Trigger Submodule Pull), Re-Use Workflow
# This workflow re-uses the workflow 'trigger_submodule_update_main.yml'
# from the brightway-documentation repository.
name: Re-Use Workflow - Create Workflow Dispatch (Trigger Submodule Update)

on:
push:
Expand All @@ -10,5 +11,5 @@ on:
jobs:
re-use_workflow:
uses:
brightway-lca/brightway-documentation/.github/workflows/github_action_trigger_submodule_pull_main.yml@main
secrets: inherit # https://docs.github.com/en/actions/using-workflows/reusing-workflows#passing-secrets-to-nested-workflows
brightway-lca/brightway-documentation/.github/workflows/trigger_submodule_update_main.yml@main
secrets: inherit # https://docs.github.com/en/actions/using-workflows/reusing-workflows#passing-secrets-to-nested-workflows
4 changes: 2 additions & 2 deletions bw2io/extractors/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CSVExtractor(object):
"""

@classmethod
def extract(cls, filepath, encoding="utf-8-sig"):
def extract(cls, filepath, encoding="utf-8-sig", **kwargs):
"""
Extracts CSV file data from the filepath.
Expand Down Expand Up @@ -47,4 +47,4 @@ def extract(cls, filepath, encoding="utf-8-sig"):
with open(filepath, encoding=encoding) as f:
reader = csv.reader(f)
data = [row for row in reader]
return [os.path.basename(filepath), data]
return [os.path.basename(filepath), data]
2 changes: 1 addition & 1 deletion bw2io/extractors/ecospold1_lcia.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Ecospold1LCIAExtractor(object):
"""

@classmethod
def extract(cls, path):
def extract(cls, path, **kwargs):
"""
Extracts ecospold XML file data.
Expand Down
6 changes: 3 additions & 3 deletions bw2io/extractors/ecospold2.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ def extract_activity(cls, dirpath, filename, db_name):
"Included activities start: ",
getattr2(
stem.activityDescription.activity, "includedActivitiesStart"
).get("text"),
)
),
(
"Included activities end: ",
getattr2(
stem.activityDescription.activity, "includedActivitiesEnd"
).get("text"),
)
),
(
"Geography: ",
Expand All @@ -264,7 +264,7 @@ def extract_activity(cls, dirpath, filename, db_name):
]
comment = "\n".join(
[
(" ".join(x) if isinstance(x, tuple) else x)
(" ".join(str(i) for i in x) if isinstance(x, tuple) else x)
for x in comments
if (x[1] if isinstance(x, tuple) else x)
]
Expand Down
2 changes: 1 addition & 1 deletion bw2io/extractors/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ExcelExtractor:
>>> data = extractor.extract(filepath)
"""
@classmethod
def extract(cls, filepath: Path):
def extract(cls, filepath: Path, **kwargs):
"""
Extract data from an Excel file.
Expand Down
2 changes: 1 addition & 1 deletion bw2io/extractors/json_ld.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class JSONLDExtractor(object):
Directories to ignore when extracting JSON-LD data.
"""
@classmethod
def extract(cls, filepath, add_filename=True):
def extract(cls, filepath, add_filename=True, **kwargs):
"""
Extracts JSON-LD data from the filepath.
Expand Down
2 changes: 1 addition & 1 deletion bw2io/extractors/simapro_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class SimaProCSVExtractor(object):
"""

@classmethod
def extract(cls, filepath, delimiter=";", name=None, encoding="cp1252"):
def extract(cls, filepath, delimiter=";", name=None, encoding="cp1252", **kwargs):
"""
Extract data from a SimaPro export file (.csv) and returns a list of datasets, global parameters, and project metadata.
Expand Down
2 changes: 1 addition & 1 deletion bw2io/extractors/simapro_lcia_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SimaProLCIACSVExtractor(object):
"""

@classmethod
def extract(cls, filepath, delimiter=";", encoding="cp1252"):
def extract(cls, filepath, delimiter=";", encoding="cp1252", **kwargs):
assert os.path.exists(filepath), "Can't find file %s" % filepath
log, logfile = get_io_logger("SimaPro-LCIA-extractor")

Expand Down
4 changes: 2 additions & 2 deletions bw2io/strategies/lcia.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def add_subcategories(obj, mapping):
)

for method in data:
already_have = {(obj["name"], obj["categories"]) for obj in method["exchanges"]}
already_have = {(obj["name"], tuple(obj["categories"])) for obj in method["exchanges"]}

new_cfs = []
for obj in method["exchanges"]:
Expand All @@ -313,7 +313,7 @@ def add_subcategories(obj, mapping):
subcat_cfs = [
x
for x in add_subcategories(obj, mapping)
if (x["name"], x["categories"]) not in already_have
if (x["name"], tuple(x["categories"])) not in already_have
]
if subcat_cfs and remove and not obj.get("input"):
obj["remove_me"] = True
Expand Down
6 changes: 3 additions & 3 deletions tests/ecospold2/ecospold2_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_extraction_without_synonyms():
"ei",
)
expected = {
"comment": "Things and stuff and whatnot\nTechnology: typical technology for ze Germans!",
"comment": "Things and stuff and whatnot\nIncluded activities start: Includes start stuff\nIncluded activities end: Includes end stuff\nTechnology: typical technology for ze Germans!",
"classifications": [
("EcoSpold01Categories", "construction materials/concrete"),
(
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_extraction_without_synonyms():
"flow": "075e433b-4be4-448e-9510-9a5029c1ce94",
"type": "biosphere",
"chemical formula": "h2o2",
'formula': 'does_it_hurt_when_dropped_on_foot * 2',
"formula": "does_it_hurt_when_dropped_on_foot * 2",
"variable name": "it_is_boring_to_do_this_manually",
"name": "Water",
"classifications": {"CPC": []},
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_extraction_with_synonyms():
"ei",
)
expected = {
"comment": "Things and stuff and whatnot\nTechnology: typical technology for ze Germans!",
"comment": "Things and stuff and whatnot\nIncluded activities end: Includes some stuff\nTechnology: typical technology for ze Germans!",
"classifications": [
("EcoSpold01Categories", "construction materials/concrete"),
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<activityDescription>
<activity id="c40e3c0a-292f-45a5-88cd-ed18265cb7d7" activityNameId="06ffc039-f73b-440c-a5a0-8dc7393a5e71" parentActivityId="0fcbe58d-60b6-46d9-86bf-183d14732a4d" inheritanceDepth="-1" type="1" specialActivityType="0" energyValues="0">
<activityName xml:lang="en">concrete block production</activityName>
<includedActivitiesStart xml:lang="en" />
<includedActivitiesEnd xml:lang="en">Includes some stuff</includedActivitiesEnd>
<includedActivitiesStart xml:lang="en">Includes start stuff</includedActivitiesStart>
<includedActivitiesEnd xml:lang="en">Includes end stuff</includedActivitiesEnd>
<generalComment>
<text xml:lang="en" index="1">Things and stuff and whatnot</text>
</generalComment>
Expand Down
15 changes: 15 additions & 0 deletions tests/strategies/lcia.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,21 @@ def test_match_subcategories_makes_copies(self):
self.assertEqual(cf["amount"], 2)


def test_categories_as_list():
""" issues/212
"""
data = [
{
"name": "Method 1",
"exchanges": [
{"categories": ["air",], "name": "Emission", "unit": "kg", "amount": 1.0},
],
}
]
biosphere_db_name = "example_biosphere"
match_subcategories(data, biosphere_db_name) # should pass without traceback


def test_rationalize_method_names_no_remove_lt():
given = [
{"name": ("aw/o LT", "b", "c w/o LT")},
Expand Down

0 comments on commit abc2f04

Please sign in to comment.