diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index d41468a..7702a51 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -55,7 +55,7 @@ jobs: # install testing - name: Install package and test deps run: | - pip install .[testing] # install the package and the testing deps + pip install .[multifunctional,testing] # install the package and the testing deps - name: Test with pytest run: | diff --git a/bw2io/__init__.py b/bw2io/__init__.py index c0a13ae..c59e629 100644 --- a/bw2io/__init__.py +++ b/bw2io/__init__.py @@ -40,7 +40,6 @@ "restore_project_directory", "SimaProCSVImporter", "SimaProLCIACSVImporter", - "SimaProBlockCSVImporter", "SingleOutputEcospold1Importer", "SingleOutputEcospold2Importer", "unlinked_data", @@ -84,7 +83,6 @@ Exiobase3HybridImporter, Exiobase3MonetaryImporter, MultiOutputEcospold1Importer, - SimaProBlockCSVImporter, SimaProCSVImporter, SimaProLCIACSVImporter, SingleOutputEcospold1Importer, @@ -97,6 +95,12 @@ from .unlinked_data import UnlinkedData, unlinked_data from .utils import activity_hash, es2_activity_hash, load_json_data_file +try: + from .importers import SimaProBlockCSVImporter + __all__.append("SimaProBlockCSVImporter") +except ImportError: + pass + try: from .ecoinvent import import_ecoinvent_release except ImportError: diff --git a/bw2io/importers/__init__.py b/bw2io/importers/__init__.py index bfe73c1..e150c8e 100644 --- a/bw2io/importers/__init__.py +++ b/bw2io/importers/__init__.py @@ -11,14 +11,11 @@ from .excel_lcia import CSVLCIAImporter, ExcelLCIAImporter from .exiobase3_hybrid import Exiobase3HybridImporter from .exiobase3_monetary import Exiobase3MonetaryImporter -from .simapro_block_csv import SimaProBlockCSVImporter from .simapro_csv import SimaProCSVImporter from .simapro_lcia_csv import SimaProLCIACSVImporter -""" -This module provides classes for importing Life Cycle Impact Assessment (LCIA) data -from different file formats. - -""" - -# Import classes for LCIA data import +try: + from .simapro_block_csv import SimaProBlockCSVImporter +except ImportError: + from bw2data.logs import stdout_feedback_logger + stdout_feedback_logger.warning("Can't import `SimaProBlockCSVImporter` - please install `bw2io` with `pip install bw2io[multifunctional]` or install `multifunctional` and `bw_simapro_csv` manually.") diff --git a/bw2io/importers/base_lci.py b/bw2io/importers/base_lci.py index 3fe1c5d..0ef1472 100644 --- a/bw2io/importers/base_lci.py +++ b/bw2io/importers/base_lci.py @@ -275,11 +275,15 @@ def _write_activity_parameters(self, activity_parameters: List[dict]) -> None: def database_class( self, db_name: str, requested_backend: str = "sqlite" ) -> ProcessedDataStore: - from multifunctional import MultifunctionalDatabase + try: + from multifunctional import MultifunctionalDatabase - if self.needs_multifunctional_database: - return MultifunctionalDatabase(db_name) - else: + if self.needs_multifunctional_database: + return MultifunctionalDatabase(db_name) + else: + return Database(db_name, backend=requested_backend) + + except ImportError: return Database(db_name, backend=requested_backend) def write_database( diff --git a/bw2io/importers/simapro_block_csv.py b/bw2io/importers/simapro_block_csv.py index dd68c95..69172a7 100644 --- a/bw2io/importers/simapro_block_csv.py +++ b/bw2io/importers/simapro_block_csv.py @@ -65,15 +65,21 @@ def __init__( override_process_name_using_single_functional_exchange, drop_unspecified_subcategories, split_simapro_name_geo, - create_products_as_new_nodes, - link_technosphere_based_on_name_unit_location, + ] + if not separate_products: + self.strategies.extend([ + create_products_as_new_nodes, + link_technosphere_based_on_name_unit_location, + ]) + self.strategies.extend([ functools.partial( link_iterable_by_fields, other=Database(biosphere_database_name or config.biosphere), edge_kinds=labels.biosphere_edge_types, + fields=("name", "categories", "unit", "location") ), match_internal_simapro_simapro_with_unit_conversion, - ] + ]) def create_regionalized_biosphere_proxies(self, database_name: str) -> None: """ diff --git a/pyproject.toml b/pyproject.toml index 36814c8..20e7328 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,23 +34,21 @@ classifiers = [ ] requires-python = ">=3.9" dependencies = [ - "bw2calc>=2.0.dev14", - "bw2data>=4.0.dev47", + "bw2calc>=2.0", + "bw2data>=4.3", "bw2parameters>=1.1.0", "bw_migrations>=0.2", - "bw_processing>=0.8.5", - "bw_simapro_csv>=0.2.3", + "bw_processing>=1.0", "lxml", "mrio_common_metadata", - "multifunctional>=0.5", - "numpy", + "numpy<2", "openpyxl", "platformdirs", "pydantic", "SPARQLWrapper", "pyecospold", - "randonneur>=0.4", - "randonneur_data", + "randonneur>=0.6", + "randonneur_data>=0.5.4", "requests", "scipy", "stats_arrays>=0.6.5", @@ -69,6 +67,11 @@ tracker = "https://github.com/brightway-lca/brightway2-io/issues" [project.optional-dependencies] # Getting recursive dependencies to work is a pain, this # seems to work, at least for now +multifunctional = [ + "bw2io", + "multifunctional>=1.0", + "bw_simapro_csv>=0.3.2", +] testing = [ "bw2io", "pytest", diff --git a/tests/simapro_block.py b/tests/simapro_block.py index dfc7d37..3c9a4b3 100644 --- a/tests/simapro_block.py +++ b/tests/simapro_block.py @@ -1,17 +1,22 @@ +import pytest + from bw2data import Database, get_node from bw2data.tests import bw2test -from bw2io.importers import SimaProBlockCSVImporter - - -class Mock(SimaProBlockCSVImporter): - # Mock to skip CSV extraction - def __init__(self): - return +try: + from bw2io.importers import SimaProBlockCSVImporter +except ImportError: + SimaProBlockCSVImporter = None +@pytest.mark.skipif(not SimaProBlockCSVImporter, reason="Dependencies for this test not installed") @bw2test def test_create_regionalized_biosphere_proxies(): + class Mock(SimaProBlockCSVImporter): + # Mock to skip CSV extraction + def __init__(self): + return + importer = Mock() importer.db_name = "database-name" importer.data = [