Skip to content

Commit

Permalink
Merge branch 'absolute-imports' (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvgoncalves committed Sep 5, 2024
2 parents 3e5874a + a5f2ba9 commit 2ab5587
Show file tree
Hide file tree
Showing 30 changed files with 156 additions and 174 deletions.
32 changes: 16 additions & 16 deletions bw2data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

__version__ = (4, 0, "dev52")

from .configuration import config, labels
from .project import projects
from .utils import set_data_dir
from .meta import (
from bw2data.configuration import config, labels
from bw2data.project import projects
from bw2data.utils import set_data_dir
from bw2data.meta import (
dynamic_calculation_setups,
calculation_setups,
databases,
Expand Down Expand Up @@ -66,21 +66,21 @@
# Backwards compatibility - preferable to access ``preferences`` directly
config.p = preferences

from .serialization import JsonWrapper
from .database import DatabaseChooser as Database
from .utils import get_activity, get_node
from .data_store import DataStore, ProcessedDataStore
from .method import Method
from .search import Searcher, IndexManager
from .weighting_normalization import Weighting, Normalization
from .backends import convert_backend, get_id, Node, Edge
from .compat import prepare_lca_inputs, Mapping, get_multilca_data_objs
from .backends.wurst_extraction import extract_brightway_databases
from bw2data.serialization import JsonWrapper
from bw2data.database import DatabaseChooser as Database
from bw2data.utils import get_activity, get_node
from bw2data.data_store import DataStore, ProcessedDataStore
from bw2data.method import Method
from bw2data.search import Searcher, IndexManager
from bw2data.weighting_normalization import Weighting, Normalization
from bw2data.backends import convert_backend, get_id, Node, Edge
from bw2data.compat import prepare_lca_inputs, Mapping, get_multilca_data_objs
from bw2data.backends.wurst_extraction import extract_brightway_databases

mapping = Mapping()

from .updates import Updates
from .parameters import parameters
from bw2data.updates import Updates
from bw2data.parameters import parameters

Updates.check_status()

Expand Down
14 changes: 7 additions & 7 deletions bw2data/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os

from .. import config
from ..project import projects
from ..sqlite import SubstitutableDatabase
from .schema import ActivityDataset, ExchangeDataset, get_id
from bw2data import config
from bw2data.project import projects
from bw2data.sqlite import SubstitutableDatabase
from bw2data.backends.schema import ActivityDataset, ExchangeDataset, get_id

sqlite3_lci_db = SubstitutableDatabase(
projects.dir / "lci" / "databases.db",
[ActivityDataset, ExchangeDataset],
)

from .base import SQLiteBackend
from .proxies import Activity, Exchange
from .utils import convert_backend
from bw2data.backends.base import SQLiteBackend
from bw2data.backends.proxies import Activity, Exchange
from bw2data.backends.utils import convert_backend

config.sqlite3_databases.append(
(
Expand Down
28 changes: 14 additions & 14 deletions bw2data/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
from peewee import JOIN, DoesNotExist, fn
from tqdm import tqdm

from .. import config, databases, geomapping
from ..configuration import labels
from ..data_store import ProcessedDataStore
from ..errors import (
from bw2data import config, databases, geomapping
from bw2data.configuration import labels
from bw2data.data_store import ProcessedDataStore
from bw2data.errors import (
DuplicateNode,
InvalidExchange,
UnknownObject,
UntypedExchange,
WrongDatabase,
)
from ..query import Query
from ..search import IndexManager, Searcher
from ..utils import as_uncertainty_dict, get_geocollection, get_node
from . import sqlite3_lci_db
from .proxies import Activity
from .schema import ActivityDataset, ExchangeDataset, get_id
from .typos import (
from bw2data.query import Query
from bw2data.search import IndexManager, Searcher
from bw2data.utils import as_uncertainty_dict, get_geocollection, get_node
from bw2data.backends import sqlite3_lci_db
from bw2data.backends.proxies import Activity
from bw2data.backends.schema import ActivityDataset, ExchangeDataset, get_id
from bw2data.backends.typos import (
check_activity_keys,
check_activity_type,
check_exchange_keys,
check_exchange_type,
)
from .utils import (
from bw2data.backends.utils import (
check_exchange,
dict_as_activitydataset,
dict_as_exchangedataset,
Expand Down Expand Up @@ -757,7 +757,7 @@ def delete(self, keep_params=False, warn=True, vacuum=True):
IndexManager(self.filename).delete_database()

if not keep_params:
from ..parameters import (
from bw2data.parameters import (
ActivityParameter,
DatabaseParameter,
ParameterizedExchange,
Expand Down Expand Up @@ -1096,7 +1096,7 @@ def edges_to_dataframe(
Returns a pandas ``DataFrame``.
"""
from .wurst_extraction import extract_brightway_databases
from bw2data.backends.wurst_extraction import extract_brightway_databases

result = []

Expand Down
2 changes: 1 addition & 1 deletion bw2data/backends/iotable/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .backend import IOTableBackend
from bw2data.backends.iotable.backend import IOTableBackend
14 changes: 6 additions & 8 deletions bw2data/backends/iotable/backend.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import datetime
import functools
import itertools

import numpy as np
import pandas as pd
from bw_processing import clean_datapackage_name, create_datapackage
from fsspec.implementations.zip import ZipFileSystem
from tqdm import tqdm

from ... import config, databases, geomapping
from ...configuration import labels
from .. import SQLiteBackend
from .proxies import IOTableActivity, IOTableExchanges
from bw2data import config, databases, geomapping
from bw2data.configuration import labels
from bw2data.backends import SQLiteBackend
from bw2data.backends.iotable.proxies import IOTableActivity, IOTableExchanges


class IOTableBackend(SQLiteBackend):
Expand Down Expand Up @@ -146,11 +144,11 @@ def edges_to_dataframe(self) -> pd.DataFrame:
Returns a pandas ``DataFrame``.
"""
from ... import get_activity
from bw2data import get_node

@functools.lru_cache(10000)
def cached_lookup(id_):
return get_activity(id=id_)
return get_node(id=id_)

print("Retrieving metadata")
activities = {o.id: o for o in self}
Expand Down
10 changes: 5 additions & 5 deletions bw2data/backends/iotable/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import numpy as np
from bw_processing import Datapackage

from ...configuration import labels
from ...errors import InvalidDatapackage
from ...utils import get_node
from ..proxies import Activity, Exchange, Exchanges
from bw2data.configuration import labels
from bw2data.errors import InvalidDatapackage
from bw2data.utils import get_node
from bw2data.backends.proxies import Activity, Exchange, Exchanges


class ReadOnlyExchange(Mapping):
Expand Down Expand Up @@ -259,7 +259,7 @@ def rp_exchange(self):
raise ValueError("Not defined for IO Table activities")

def _get_correct_db_backend(self):
from ...database import DatabaseChooser
from bw2data.database import DatabaseChooser

db = DatabaseChooser(self["database"])
if db.backend != "iotable":
Expand Down
30 changes: 15 additions & 15 deletions bw2data/backends/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

import pandas as pd

from .. import databases, geomapping
from ..configuration import labels
from ..errors import ValidityError
from ..proxies import ActivityProxyBase, ExchangeProxyBase
from ..search import IndexManager
from . import sqlite3_lci_db
from .schema import ActivityDataset, ExchangeDataset
from .typos import (
from bw2data import databases, geomapping
from bw2data.configuration import labels
from bw2data.errors import ValidityError
from bw2data.proxies import ActivityProxyBase, ExchangeProxyBase
from bw2data.search import IndexManager
from bw2data.backends import sqlite3_lci_db
from bw2data.backends.schema import ActivityDataset, ExchangeDataset
from bw2data.backends.typos import (
check_activity_keys,
check_activity_type,
check_exchange_keys,
check_exchange_type,
)
from .utils import dict_as_activitydataset, dict_as_exchangedataset
from bw2data.backends.utils import dict_as_activitydataset, dict_as_exchangedataset


class Exchanges(Iterable):
Expand Down Expand Up @@ -254,8 +254,8 @@ def key(self):
return (self.get("database"), self.get("code"))

def delete(self):
from .. import Database
from ..parameters import ActivityParameter, ParameterizedExchange
from bw2data import Database
from bw2data.parameters import ActivityParameter, ParameterizedExchange

try:
ap = ActivityParameter.get(database=self[0], code=self[1])
Expand Down Expand Up @@ -299,7 +299,7 @@ def save(self):
>>> activity.save()
Saves the activity if it's valid, otherwise raises ValidityError.
"""
from .. import Database
from bw2data import Database

if not self.valid():
raise ValidityError(
Expand Down Expand Up @@ -355,7 +355,7 @@ def _change_code(self, new_code):
).execute()

if databases[self["database"]].get("searchable"):
from .. import Database
from bw2data import Database

IndexManager(Database(self["database"]).filename).delete_dataset(self)
self._data["code"] = new_code
Expand Down Expand Up @@ -385,7 +385,7 @@ def _change_database(self, new_database):
).execute()

if databases[self["database"]].get("searchable"):
from .. import Database
from bw2data import Database

IndexManager(Database(self["database"]).filename).delete_dataset(self)
self._data["database"] = new_database
Expand Down Expand Up @@ -533,7 +533,7 @@ def save(self):
self._document.save()

def delete(self):
from ..parameters import ParameterizedExchange
from bw2data.parameters import ParameterizedExchange

ParameterizedExchange.delete().where(
ParameterizedExchange.exchange == self._document.id
Expand Down
4 changes: 2 additions & 2 deletions bw2data/backends/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from peewee import DoesNotExist, Model, TextField

from ..errors import UnknownObject
from ..sqlite import PickleField
from bw2data.errors import UnknownObject
from bw2data.sqlite import PickleField


class ActivityDataset(Model):
Expand Down
4 changes: 2 additions & 2 deletions bw2data/backends/typos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import partial
from typing import Iterable

from ..configuration import typo_settings
from bw2data.configuration import typo_settings

try:
from rapidfuzz.distance import DamerauLevenshtein
Expand All @@ -13,7 +13,7 @@
# https://github.com/rapidfuzz/RapidFuzz/tree/main?tab=readme-ov-file#with-pip
# Rapidfuzz is not currently available on Emscripten
# https://github.com/brightway-lca/brightway-live/issues/59
from ..string_distance import damerau_levenshtein
from bw2data.string_distance import damerau_levenshtein


def _check_type(type_value: str, kind: str, valid: Iterable[str]) -> None:
Expand Down
14 changes: 7 additions & 7 deletions bw2data/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import numpy as np

from .. import config
from ..configuration import labels
from ..errors import InvalidExchange, UntypedExchange
from ..meta import databases, methods
from .schema import get_id
from bw2data import config
from bw2data.configuration import labels
from bw2data.errors import InvalidExchange, UntypedExchange
from bw2data.meta import databases, methods
from bw2data.backends.schema import get_id


def get_csv_data_dict(ds):
Expand All @@ -31,7 +31,7 @@ def convert_backend(database_name, backend):
if database_name not in databases:
print("Can't find database {}".format(database_name))

from ..database import Database
from bw2data.database import Database

db = Database(database_name)
if db.backend == backend:
Expand Down Expand Up @@ -88,7 +88,7 @@ def replace_cfs(old_key, new_key):
"""Replace ``old_key`` with ``new_key`` in characterization factors.
Returns list of modified methods."""
from ..method import Method
from bw2data.method import Method

altered_methods = []
for name in methods:
Expand Down
6 changes: 3 additions & 3 deletions bw2data/backends/wurst_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from tqdm import tqdm

from ..configuration import labels
from ..database import DatabaseChooser
from . import ActivityDataset, ExchangeDataset, SQLiteBackend
from bw2data.configuration import labels
from bw2data.database import DatabaseChooser
from bw2data.backends import ActivityDataset, ExchangeDataset, SQLiteBackend


def _list_or_dict(obj):
Expand Down
8 changes: 4 additions & 4 deletions bw2data/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from bw_processing.datapackage import DatapackageBase

from . import (
from bw2data import (
Database,
Method,
Normalization,
Expand All @@ -14,9 +14,9 @@
projects,
weightings,
)
from .backends.schema import ActivityDataset as AD
from .backends.schema import get_id
from .errors import Brightway2Project, UnknownObject
from bw2data.backends.schema import ActivityDataset as AD
from bw2data.backends.schema import get_id
from bw2data.errors import Brightway2Project, UnknownObject


class Mapping:
Expand Down
6 changes: 3 additions & 3 deletions bw2data/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
)
from fsspec.implementations.zip import ZipFileSystem

from . import projects
from .errors import MissingIntermediateData, UnknownObject
from .fatomic import open as atomic_open
from bw2data import projects
from bw2data.errors import MissingIntermediateData, UnknownObject
from bw2data.fatomic import open as atomic_open


class DataStore:
Expand Down
Loading

0 comments on commit 2ab5587

Please sign in to comment.