From 7b1f0741ac770d48689fbf1a68787654dd26825c Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Wed, 4 Sep 2024 12:31:30 +0200 Subject: [PATCH] Allow custom output path for `write_lci_matching` --- bw2io/export/excel.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bw2io/export/excel.py b/bw2io/export/excel.py index 51a39b7..ecc2865 100644 --- a/bw2io/export/excel.py +++ b/bw2io/export/excel.py @@ -1,3 +1,5 @@ +from pathlib import Path +from typing import Optional, List import collections import numbers import os @@ -287,7 +289,7 @@ def write_lci_excel(database_name, objs=None, sections=None, dirpath=None): def write_lci_matching( - db, database_name, only_unlinked=False, only_activity_names=False + db: List[dict], database_name: str, only_unlinked: bool=False, only_activity_names: bool=False, output_dir: Optional[Path] = None ): """ Write matched and unmatched exchanges to Excel file @@ -353,10 +355,9 @@ def write_row(sheet, row, data, exc=True): ) safe_name = safe_filename(database_name, False) - suffix = "-unlinked" if only_unlinked else "-names" if only_activity_names else "" - filepath = os.path.join( - projects.output_dir, "db-matching-" + safe_name + suffix + ".xlsx" - ) + suffix = "-unlinked" if only_unlinked else ("-names" if only_activity_names else "") + + filepath = Path(output_dir or projects.output_dir) / f"db-matching-{safe_name}{suffix}.xlsx" workbook = xlsxwriter.Workbook(filepath) bold = workbook.add_format({"bold": True})