|
8 | 8 | import csv |
9 | 9 | import json |
10 | 10 | import os |
| 11 | +import pkgutil |
11 | 12 | import re |
| 13 | +from io import StringIO |
| 14 | +from pathlib import Path |
12 | 15 | from typing import Optional |
13 | 16 |
|
14 | 17 | import bw2data as bd |
|
25 | 28 | from appabuild.exceptions import BwDatabaseError, SerializedDataError |
26 | 29 | from appabuild.logger import log_validation_error, logger |
27 | 30 |
|
28 | | -PATH_TO_METHODS = "data/methods/ecoinvent_3.11_methods.csv" |
| 31 | +DATA_MODULE = "appabuild.data" |
29 | 32 |
|
30 | 33 |
|
31 | 34 | class Database: |
@@ -105,21 +108,21 @@ def import_in_project(self) -> None: |
105 | 108 | ei_bio_database = bd.Database(self.biosphere_name) |
106 | 109 |
|
107 | 110 | 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 | + ) |
123 | 126 |
|
124 | 127 | for method in bd.methods: |
125 | 128 | bio_dataset = { |
|
0 commit comments