Skip to content

Commit 227dcc8

Browse files
authored
(fix) Move methods data in appabuild module (#48)
* (fix) Data is a module in appabuild
1 parent a922b64 commit 227dcc8

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

appabuild/data/__init__.py

Whitespace-only changes.
File renamed without changes.

appabuild/database/databases.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import csv
99
import json
1010
import os
11+
import pkgutil
1112
import re
13+
from io import StringIO
14+
from pathlib import Path
1215
from typing import Optional
1316

1417
import bw2data as bd
@@ -25,7 +28,7 @@
2528
from appabuild.exceptions import BwDatabaseError, SerializedDataError
2629
from appabuild.logger import log_validation_error, logger
2730

28-
PATH_TO_METHODS = "data/methods/ecoinvent_3.11_methods.csv"
31+
DATA_MODULE = "appabuild.data"
2932

3033

3134
class Database:
@@ -105,21 +108,21 @@ def import_in_project(self) -> None:
105108
ei_bio_database = bd.Database(self.biosphere_name)
106109

107110
if not self.with_ecoinvent:
108-
with open(PATH_TO_METHODS, newline="") as csvfile:
109-
reader = csv.reader(csvfile, delimiter=";")
110-
for row in reader:
111-
method, category, indicator, unit = row
112-
key = self.name, method, category, indicator
113-
# todo add all empty methods
114-
# key = self.name = tuple csv
115-
if key not in bd.methods:
116-
method = bd.Method(key)
117-
method.register(
118-
unit=unit,
119-
filepath=PATH_TO_METHODS,
120-
ecoinvent_version="3.11",
121-
database=self.name,
122-
)
111+
data = pkgutil.get_data(DATA_MODULE, "methods/ecoinvent_3.11_methods.csv")
112+
reader = csv.reader(StringIO(data.decode()), delimiter=";")
113+
for row in reader:
114+
method, category, indicator, unit = row
115+
key = self.name, method, category, indicator
116+
# todo add all empty methods
117+
# key = self.name = tuple csv
118+
if key not in bd.methods:
119+
method = bd.Method(key)
120+
method.register(
121+
unit=unit,
122+
filepath="methods/ecoinvent_3.11_methods.csv",
123+
ecoinvent_version="3.11",
124+
database=self.name,
125+
)
123126

124127
for method in bd.methods:
125128
bio_dataset = {

0 commit comments

Comments
 (0)