From f5f382372787c5527fd5dc46cf35d1004915cc52 Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Mon, 9 Oct 2023 23:46:40 +0200 Subject: [PATCH 1/9] Add some basic work on 2.5 compat --- docs/conf.py | 2 +- premise/utils.py | 56 ++++++++++++++++++++++++++++++++++++++++++++---- setup.py | 2 +- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f5ad4890..b42eb4df 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -42,7 +42,7 @@ autodoc_mock_imports = [ "numpy", "wurst==0.3.3", - "bw2io==0.8.7", + "bw2io", "pandas", "bw2data", "xarray", diff --git a/premise/utils.py b/premise/utils.py index d4803177..ee04f26e 100644 --- a/premise/utils.py +++ b/premise/utils.py @@ -2,16 +2,18 @@ Various utils functions. """ -import os -import sys +from copy import copy from functools import lru_cache from pathlib import Path from typing import List +import itertools +import os +import sys import pandas as pd import xarray as xr import yaml -from bw2data import databases +from bw2data import databases, Database from bw2io.importers.base_lci import LCIImporter from country_converter import CountryConverter from prettytable import ALL, PrettyTable @@ -275,9 +277,55 @@ def __init__(self, db_name, data): # to allow existing databases # to be overwritten def write_database(self): + def no_exchange_generator(data): + for ds in data: + cp = copy(ds) + cp['exchanges'] = [] + yield cp + if self.db_name in databases: print(f"Database {self.db_name} already exists: " "it will be overwritten.") - super().write_database() + super().write_database(list(no_exchange_generator(self.data)), backend="iotable") + + dependents = {exc['input'][0] for ds in self.data for exc in ds['exchanges']} + lookup = {obj.key: obj.id for obj in itertools.chain(*[Database(label) for label in dependents])} + + def technosphere_generator(data, lookup): + for ds in data: + target = lookup[(ds['database'], ds['code'])] + for exc in ds['exchanges']: + if exc['type'] in ('substitution', 'production', 'generic production'): + yield { + "row": lookup[exc['input']], + "col": target, + "amount": exc['amount'], + "flip": False + } + elif exc['type'] == 'technosphere': + yield { + "row": lookup[exc['input']], + "col": target, + "amount": exc['amount'], + "flip": True + } + + def biosphere_generator(data, lookup): + for ds in data: + target = lookup[(ds['database'], ds['code'])] + for exc in ds['exchanges']: + if exc['type'] == 'biosphere': + yield { + "row": lookup[exc['input']], + "col": target, + "amount": exc['amount'], + "flip": False + } + + Database(self.db_name).write_exchanges( + technosphere_generator(self.data, lookup), + biosphere_generator(self.data, lookup), + list(dependents) + ) def clean_up(exc): diff --git a/setup.py b/setup.py index 61d1184c..645b59e4 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def package_files(directory): install_requires=[ "numpy", "wurst==0.3.3", - "bw2io==0.8.7", + "bw2io", "pandas==1.5.3", "bw2data", "xarray", From 47988054ace9f91142127ae22eaaa4eea166febd Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Wed, 11 Oct 2023 21:13:12 +0200 Subject: [PATCH 2/9] Separate out Brightway functionality --- premise/brightway2.py | 9 +++++ premise/brightway25.py | 79 ++++++++++++++++++++++++++++++++++++++++++ premise/utils.py | 78 ----------------------------------------- 3 files changed, 88 insertions(+), 78 deletions(-) create mode 100644 premise/brightway2.py create mode 100644 premise/brightway25.py diff --git a/premise/brightway2.py b/premise/brightway2.py new file mode 100644 index 00000000..d46676c9 --- /dev/null +++ b/premise/brightway2.py @@ -0,0 +1,9 @@ +def write_brightway2_database(data, name, reset_codes=False): + # Restore parameters to Brightway2 format + # which allows for uncertainty and comments + change_db_name(data, name) + if reset_codes: + reset_all_codes(data) + link_internal(data) + check_internal_linking(data) + PremiseImporter(name, data).write_database() diff --git a/premise/brightway25.py b/premise/brightway25.py new file mode 100644 index 00000000..adbacc3e --- /dev/null +++ b/premise/brightway25.py @@ -0,0 +1,79 @@ +from wurst.linking import change_db_name, check_internal_linking, link_internal +from .utils import reset_all_codes +from bw2data import Database, databases +from bw2io.importers.base_lci import LCIImporter +from copy import copy +import itertools + + +class BW25Importer(LCIImporter): + def __init__(self, db_name, data): + self.db_name = db_name + self.data = data + for act in self.data: + act["database"] = self.db_name + + # we override `write_database` + # to allow existing databases + # to be overwritten + def write_database(self): + def no_exchange_generator(data): + for ds in data: + cp = copy(ds) + cp['exchanges'] = [] + yield cp + + if self.db_name in databases: + print(f"Database {self.db_name} already exists: " "it will be overwritten.") + super().write_database(list(no_exchange_generator(self.data)), backend="iotable") + + dependents = {exc['input'][0] for ds in self.data for exc in ds['exchanges']} + lookup = {obj.key: obj.id for obj in itertools.chain(*[Database(label) for label in dependents])} + + def technosphere_generator(data, lookup): + for ds in data: + target = lookup[(ds['database'], ds['code'])] + for exc in ds['exchanges']: + if exc['type'] in ('substitution', 'production', 'generic production'): + yield { + "row": lookup[exc['input']], + "col": target, + "amount": exc['amount'], + "flip": False + } + elif exc['type'] == 'technosphere': + yield { + "row": lookup[exc['input']], + "col": target, + "amount": exc['amount'], + "flip": True + } + + def biosphere_generator(data, lookup): + for ds in data: + target = lookup[(ds['database'], ds['code'])] + for exc in ds['exchanges']: + if exc['type'] == 'biosphere': + yield { + "row": lookup[exc['input']], + "col": target, + "amount": exc['amount'], + "flip": False + } + + Database(self.db_name).write_exchanges( + technosphere_generator(self.data, lookup), + biosphere_generator(self.data, lookup), + list(dependents) + ) + + +def write_brightway25_database(data, name, reset_codes=False): + # Restore parameters to Brightway2 format + # which allows for uncertainty and comments + change_db_name(data, name) + if reset_codes: + reset_all_codes(data) + link_internal(data) + check_internal_linking(data) + BW25Importer(name, data).write_database() diff --git a/premise/utils.py b/premise/utils.py index 0dfc5f4a..bb80dc1c 100644 --- a/premise/utils.py +++ b/premise/utils.py @@ -2,8 +2,6 @@ Various utils functions. """ -from copy import copy -import itertools import os import sys import uuid @@ -14,11 +12,8 @@ import pandas as pd import xarray as xr import yaml -from bw2data import databases, Database -from bw2io.importers.base_lci import LCIImporter from country_converter import CountryConverter from prettytable import ALL, PrettyTable -from wurst.linking import change_db_name, check_internal_linking, link_internal from wurst.searching import equals, get_many from . import __version__ @@ -267,68 +262,6 @@ def hide_messages(): print("NewDatabase(..., quiet=True)") -class PremiseImporter(LCIImporter): - def __init__(self, db_name, data): - self.db_name = db_name - self.data = data - for act in self.data: - act["database"] = self.db_name - - # we override `write_database` - # to allow existing databases - # to be overwritten - def write_database(self): - def no_exchange_generator(data): - for ds in data: - cp = copy(ds) - cp['exchanges'] = [] - yield cp - - if self.db_name in databases: - print(f"Database {self.db_name} already exists: " "it will be overwritten.") - super().write_database(list(no_exchange_generator(self.data)), backend="iotable") - - dependents = {exc['input'][0] for ds in self.data for exc in ds['exchanges']} - lookup = {obj.key: obj.id for obj in itertools.chain(*[Database(label) for label in dependents])} - - def technosphere_generator(data, lookup): - for ds in data: - target = lookup[(ds['database'], ds['code'])] - for exc in ds['exchanges']: - if exc['type'] in ('substitution', 'production', 'generic production'): - yield { - "row": lookup[exc['input']], - "col": target, - "amount": exc['amount'], - "flip": False - } - elif exc['type'] == 'technosphere': - yield { - "row": lookup[exc['input']], - "col": target, - "amount": exc['amount'], - "flip": True - } - - def biosphere_generator(data, lookup): - for ds in data: - target = lookup[(ds['database'], ds['code'])] - for exc in ds['exchanges']: - if exc['type'] == 'biosphere': - yield { - "row": lookup[exc['input']], - "col": target, - "amount": exc['amount'], - "flip": False - } - - Database(self.db_name).write_exchanges( - technosphere_generator(self.data, lookup), - biosphere_generator(self.data, lookup), - list(dependents) - ) - - def reset_all_codes(data): """ Re-generate all codes in each dataset of a database @@ -345,17 +278,6 @@ def reset_all_codes(data): return data -def write_brightway2_database(data, name, reset_codes=False): - # Restore parameters to Brightway2 format - # which allows for uncertainty and comments - change_db_name(data, name) - if reset_codes: - reset_all_codes(data) - link_internal(data) - check_internal_linking(data) - PremiseImporter(name, data).write_database() - - def delete_log(): """ Delete log file. From 12e68c1ff738de81582c7f4b9697b3a0a9fa450c Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Thu, 12 Oct 2023 10:20:48 +0200 Subject: [PATCH 3/9] Experimental support for both bw2 and bw25 --- premise/brightway2.py | 27 +++++++++- premise/brightway25.py | 63 ++++++++++++---------- premise/ecoinvent_modification.py | 16 ++++-- pyproject.toml | 86 +++++++++++++++++++++++++++++++ pytest.ini | 7 --- readthedocs.yml | 6 ++- setup.py | 83 ----------------------------- 7 files changed, 163 insertions(+), 125 deletions(-) create mode 100644 pyproject.toml delete mode 100644 pytest.ini delete mode 100644 setup.py diff --git a/premise/brightway2.py b/premise/brightway2.py index d46676c9..7a572080 100644 --- a/premise/brightway2.py +++ b/premise/brightway2.py @@ -1,4 +1,27 @@ -def write_brightway2_database(data, name, reset_codes=False): +from bw2data import databases +from bw2io.importers.base_lci import LCIImporter +from wurst.linking import change_db_name, check_internal_linking, link_internal + +from .utils import reset_all_codes + + +class BW2Importer(LCIImporter): + def __init__(self, db_name, data): + self.db_name = db_name + self.data = data + for act in self.data: + act["database"] = self.db_name + + # we override `write_database` + # to allow existing databases + # to be overwritten + def write_database(self): + if self.db_name in databases: + print(f"Database {self.db_name} already exists: it will be overwritten.") + super().write_database() + + +def write_brightway_database(data, name, reset_codes=False): # Restore parameters to Brightway2 format # which allows for uncertainty and comments change_db_name(data, name) @@ -6,4 +29,4 @@ def write_brightway2_database(data, name, reset_codes=False): reset_all_codes(data) link_internal(data) check_internal_linking(data) - PremiseImporter(name, data).write_database() + BW2Importer(name, data).write_database() diff --git a/premise/brightway25.py b/premise/brightway25.py index adbacc3e..8b9feaee 100644 --- a/premise/brightway25.py +++ b/premise/brightway25.py @@ -1,9 +1,11 @@ -from wurst.linking import change_db_name, check_internal_linking, link_internal -from .utils import reset_all_codes +import itertools +from copy import copy + from bw2data import Database, databases from bw2io.importers.base_lci import LCIImporter -from copy import copy -import itertools +from wurst.linking import change_db_name, check_internal_linking, link_internal + +from .utils import reset_all_codes class BW25Importer(LCIImporter): @@ -20,55 +22,64 @@ def write_database(self): def no_exchange_generator(data): for ds in data: cp = copy(ds) - cp['exchanges'] = [] + cp["exchanges"] = [] yield cp if self.db_name in databases: print(f"Database {self.db_name} already exists: " "it will be overwritten.") - super().write_database(list(no_exchange_generator(self.data)), backend="iotable") + super().write_database( + list(no_exchange_generator(self.data)), backend="iotable" + ) - dependents = {exc['input'][0] for ds in self.data for exc in ds['exchanges']} - lookup = {obj.key: obj.id for obj in itertools.chain(*[Database(label) for label in dependents])} + dependents = {exc["input"][0] for ds in self.data for exc in ds["exchanges"]} + lookup = { + obj.key: obj.id + for obj in itertools.chain(*[Database(label) for label in dependents]) + } def technosphere_generator(data, lookup): for ds in data: - target = lookup[(ds['database'], ds['code'])] - for exc in ds['exchanges']: - if exc['type'] in ('substitution', 'production', 'generic production'): + target = lookup[(ds["database"], ds["code"])] + for exc in ds["exchanges"]: + if exc["type"] in ( + "substitution", + "production", + "generic production", + ): yield { - "row": lookup[exc['input']], + "row": lookup[exc["input"]], "col": target, - "amount": exc['amount'], - "flip": False + "amount": exc["amount"], + "flip": False, } - elif exc['type'] == 'technosphere': + elif exc["type"] == "technosphere": yield { - "row": lookup[exc['input']], + "row": lookup[exc["input"]], "col": target, - "amount": exc['amount'], - "flip": True + "amount": exc["amount"], + "flip": True, } def biosphere_generator(data, lookup): for ds in data: - target = lookup[(ds['database'], ds['code'])] - for exc in ds['exchanges']: - if exc['type'] == 'biosphere': + target = lookup[(ds["database"], ds["code"])] + for exc in ds["exchanges"]: + if exc["type"] == "biosphere": yield { - "row": lookup[exc['input']], + "row": lookup[exc["input"]], "col": target, - "amount": exc['amount'], - "flip": False + "amount": exc["amount"], + "flip": False, } Database(self.db_name).write_exchanges( technosphere_generator(self.data, lookup), biosphere_generator(self.data, lookup), - list(dependents) + list(dependents), ) -def write_brightway25_database(data, name, reset_codes=False): +def write_brightway_database(data, name, reset_codes=False): # Restore parameters to Brightway2 format # which allows for uncertainty and comments change_db_name(data, name) diff --git a/premise/ecoinvent_modification.py b/premise/ecoinvent_modification.py index 90033eb2..75a75c66 100644 --- a/premise/ecoinvent_modification.py +++ b/premise/ecoinvent_modification.py @@ -49,9 +49,15 @@ load_constants, print_version, warning_about_biogenic_co2, - write_brightway2_database, ) +try: + import bw_processing + from .brightway25 import write_brightway_database +except ImportError: + from .brightway2 import write_brightway_database + + FILEPATH_OIL_GAS_INVENTORIES = INVENTORY_DIR / "lci-ESU-oil-and-gas.xlsx" FILEPATH_CARMA_INVENTORIES = INVENTORY_DIR / "lci-Carma-CCS.xlsx" FILEPATH_CO_FIRING_INVENTORIES = INVENTORY_DIR / "lci-co-firing-power-plants.xlsx" @@ -1358,7 +1364,7 @@ def write_superstructure_db_to_brightway( scenario_list=list_scenarios, ) - write_brightway2_database( + write_brightway_database( data=self.database, name=name, reset_codes=True, @@ -1371,7 +1377,7 @@ def write_superstructure_db_to_brightway( def write_db_to_brightway(self, name: [str, List[str]] = None): """ - Register the new database into an open brightway2 project. + Register the new database into an open brightway project. :param name: to give a (list) of custom name(s) to the database. Should either be a string if there's only one database to export. Or a list of strings if there are several databases. @@ -1405,7 +1411,7 @@ def write_db_to_brightway(self, name: [str, List[str]] = None): "The number of databases does not match the number of `name` given." ) - print("Write new database(s) to Brightway2.") + print("Write new database(s) to Brightway.") cache = {} @@ -1438,7 +1444,7 @@ def write_db_to_brightway(self, name: [str, List[str]] = None): ) for scen, scenario in enumerate(self.scenarios): - write_brightway2_database( + write_brightway_database( scenario["database"], name[scen], ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..6c6ff8d0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,86 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "premise" +authors = [ + { name="Romain Sacchi", email="romain.sacchi@psi.ch" }, + { name="Alois Dirnaichner", email="dirnaichner@pik-potsdam.de" }, + { name=" Chris Mutel", email="cmutel@gmail.com" } +] +maintainers = [ + { name="Romain Sacchi", email="romain.sacchi@psi.ch" } +] +description = "Coupling IAM output to ecoinvent LCA database ecoinvent for prospective LCA" +readme = "README.md" +dynamic = ["dependencies", "version"] +classifiers = [ + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Natural Language :: English", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering", +] +requires-python = ">=3.9,<3.11" + +[project.urls] +source = "https://github.com/polca/premise" +homepage = "https://github.com/polca/premise" +tracker = "https://github.com/polca/premise/issues" + +[project.optional-dependencies] +testing = [ + "setuptools", + "pytest", + "pytest-cov", +] + +docs = [ + "sphinx-rtd-theme" +] +bw25 = [ + "bw2analyzer >=0.11.4", + "bw2calc >=2.0.dev13", + "bw2data >=4.0.dev31", + "bw2io >=0.9.dev23", + "bw_processing >=0.8.2", + "matrix_utils >=0.2.5" +] + +[tool.setuptools] +license-files = ["LICENSE"] +include-package-data = true +packages = ["premise"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +version = {attr = "premise.__version__"} + +[tool.pytest.ini_options] +markers = [ + # marks tests that require ecoinvent (to be disabled on Travis) + "ecoinvent", + "serial" +] +norecursedirs = [ + "dist", + "build", + ".tox" +] +testpaths = ["tests/*.py"] + +[tool.flake8] +# Some sane defaults for the code style checker flake8 +max_line_length = 88 +extend_ignore = ["E203", "W503"] +# ^ Black-compatible +# E203 and W503 have edge cases handled by black +exclude = [ + ".tox", + "build", + "dist", + ".eggs", + "docs/conf.py", +] diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 75d45bbf..00000000 --- a/pytest.ini +++ /dev/null @@ -1,7 +0,0 @@ -[pytest] -testpaths = tests -python_files = tests/*.py -norecursedirs = venv, manual -markers = - ecoinvent: marks tests that require ecoinvent (to be disabled on Travis) - serial \ No newline at end of file diff --git a/readthedocs.yml b/readthedocs.yml index 96a6e064..e38adad2 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -25,5 +25,7 @@ formats: all # Optionally set the version of Python and requirements required to build your docs python: install: - - requirements: docs/requirements.txt - - requirements: requirements.txt \ No newline at end of file + - method: pip + path: . + extra_requirements: + - docs diff --git a/setup.py b/setup.py deleted file mode 100644 index 1f9990cb..00000000 --- a/setup.py +++ /dev/null @@ -1,83 +0,0 @@ -import os -from pathlib import Path - -from setuptools import setup - -packages = [] -root_dir = os.path.dirname(__file__) -if root_dir: - os.chdir(root_dir) - -# read the contents of your README file -this_directory = Path(__file__).parent -README = (this_directory / "README.md").read_text() - -# Probably should be changed, __init__.py is no longer required for Python 3 -for dirpath, dirnames, filenames in os.walk("premise"): - # Ignore dirnames that start with '.' - if "__init__.py" in filenames: - pkg = dirpath.replace(os.path.sep, ".") - if os.path.altsep: - pkg = pkg.replace(os.path.altsep, ".") - packages.append(pkg) - - -def package_files(directory): - paths = [] - for path, directories, filenames in os.walk(directory): - for filename in filenames: - paths.append(os.path.join("..", path, filename)) - return paths - - -setup( - name="premise", - version="1.7.8", - python_requires=">=3.9,<3.11", - packages=packages, - author="Romain Sacchi , Alois Dirnaichner , Chris Mutel " - "", - license=open("LICENSE").read(), - # Only if you have non-python data (CSV, etc.). Might need to change the directory name as well. - include_package_data=True, - install_requires=[ - "bottleneck", - "bw2data", - "bw2io >=0.8.10", - "constructive_geometries>=0.8.2", - "cryptography", - "datapackage", - "numpy", - "pandas", - "platformdirs", - "premise_gwp", - "prettytable", - "pyarrow", - "pycountry", - "pyYaml", - "requests", - "schema", - "sparse>=0.14.0", - "wurst", - "xarray", - ], - url="https://github.com/polca/premise", - description="Coupling IAM output to ecoinvent LCA database ecoinvent for prospective LCA", - long_description_content_type="text/markdown", - long_description=README, - classifiers=[ - "Intended Audience :: End Users/Desktop", - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", - "Topic :: Scientific/Engineering :: Information Analysis", - "Topic :: Scientific/Engineering :: Mathematics", - "Topic :: Scientific/Engineering :: Visualization", - ], -) From 77a1d84f54cf14fc412ff36a06eee5b2f78c4cde Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Thu, 12 Oct 2023 08:21:35 +0000 Subject: [PATCH 4/9] Black reformating --- premise/ecoinvent_modification.py | 1 + 1 file changed, 1 insertion(+) diff --git a/premise/ecoinvent_modification.py b/premise/ecoinvent_modification.py index 75a75c66..a7f54276 100644 --- a/premise/ecoinvent_modification.py +++ b/premise/ecoinvent_modification.py @@ -53,6 +53,7 @@ try: import bw_processing + from .brightway25 import write_brightway_database except ImportError: from .brightway2 import write_brightway_database From 423335b485aab14530315323089cb1f2c398dc16 Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Thu, 12 Oct 2023 16:42:17 +0200 Subject: [PATCH 5/9] Remove 3.11 restriction --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6c6ff8d0..d0108747 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ "Operating System :: OS Independent", "Topic :: Scientific/Engineering", ] -requires-python = ">=3.9,<3.11" +requires-python = ">=3.9" [project.urls] source = "https://github.com/polca/premise" From cfc8877d0b9f7016db08f3c343545b75c78f4d44 Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Thu, 12 Oct 2023 16:42:42 +0200 Subject: [PATCH 6/9] Add log message on BW 2 or 2.5 --- premise/ecoinvent_modification.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/premise/ecoinvent_modification.py b/premise/ecoinvent_modification.py index 75a75c66..e2f7b6f9 100644 --- a/premise/ecoinvent_modification.py +++ b/premise/ecoinvent_modification.py @@ -14,6 +14,7 @@ from multiprocessing.pool import ThreadPool as Pool from pathlib import Path from typing import List, Union +import logging import datapackage import yaml @@ -51,11 +52,15 @@ warning_about_biogenic_co2, ) +logger = logging.getLogger("module") + try: import bw_processing from .brightway25 import write_brightway_database + logger.info("Using Brightway 2.5") except ImportError: from .brightway2 import write_brightway_database + logger.info("Using Brightway 2") FILEPATH_OIL_GAS_INVENTORIES = INVENTORY_DIR / "lci-ESU-oil-and-gas.xlsx" From a0bbf1d1a925fe3388b158de98db27b0e39b34ea Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Thu, 12 Oct 2023 16:49:53 +0200 Subject: [PATCH 7/9] Use docs section in CI config --- .github/workflows/main.yml | 11 ++--------- pyproject.toml | 1 + 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e64fb6da..6aa936a5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,10 +77,7 @@ jobs: run: | pip install pathlib pip install -r requirements.txt --upgrade pip - pip install -e . - pip install pytest - pip install pytest-cov - pip install coveralls + pip install -e .[test] - name: Run tests run: | @@ -114,10 +111,6 @@ jobs: run: >- python -m build - --sdist - --wheel - --outdir dist/ - . - name: Publish distribution 📦 to PyPI if Release if: startsWith(github.ref, 'refs/tags') @@ -229,4 +222,4 @@ jobs: conda install bottleneck pytest -m "not ecoinvent" env: - IAM_FILES_KEY: ${{ secrets.IAM_FILES_KEY }} \ No newline at end of file + IAM_FILES_KEY: ${{ secrets.IAM_FILES_KEY }} diff --git a/pyproject.toml b/pyproject.toml index d0108747..66c73351 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ testing = [ "setuptools", "pytest", "pytest-cov", + "coveralls" ] docs = [ From 0c4a6162c988c7efd10bba2773d3c3291cc8c664 Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Thu, 12 Oct 2023 17:15:17 +0200 Subject: [PATCH 8/9] Don't install on 3.12 The dependency `sparse` is broken, it imports `Iterable` from collections which doesn't work. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 66c73351..8f4a48ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ "Operating System :: OS Independent", "Topic :: Scientific/Engineering", ] -requires-python = ">=3.9" +requires-python = ">=3.9,<3.12" [project.urls] source = "https://github.com/polca/premise" From eeb3d953c20aaad8b14c550aa10a45a919c76494 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Thu, 12 Oct 2023 15:20:27 +0000 Subject: [PATCH 9/9] Black reformating --- premise/ecoinvent_modification.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/premise/ecoinvent_modification.py b/premise/ecoinvent_modification.py index 086cec1d..64830182 100644 --- a/premise/ecoinvent_modification.py +++ b/premise/ecoinvent_modification.py @@ -5,6 +5,7 @@ """ import copy +import logging import multiprocessing import os import pickle @@ -14,7 +15,6 @@ from multiprocessing.pool import ThreadPool as Pool from pathlib import Path from typing import List, Union -import logging import datapackage import yaml @@ -58,9 +58,11 @@ import bw_processing from .brightway25 import write_brightway_database + logger.info("Using Brightway 2.5") except ImportError: from .brightway2 import write_brightway_database + logger.info("Using Brightway 2")