1- from typing import Optional , Union
2- from logging import getLogger
1+ from typing import Optional
2+
3+ from loguru import logger
34
45from bw2data import databases , get_node , labels
5- from bw2data .backends import ExchangeDataset
66from bw2data .errors import UnknownObject , ValidityError
77from bw2data .backends .proxies import Activity , ActivityDataset
88
99from .edge_classes import MFExchanges , MFExchange
1010
11- log = getLogger (__name__ )
12-
1311
1412INHERITED_FIELDS = [
1513 "database" ,
@@ -41,7 +39,7 @@ def save(self, signal: bool = True, data_already_set: bool = False, force_insert
4139 data_already_set (bool, optional): Whether the data is already set. Defaults to False.
4240 force_insert (bool, optional): Whether to force an insert operation. Defaults to False.
4341 """
44- log .debug (f"Saving { self .__class__ .__name__ } : { self } " )
42+ logger .debug (f"Saving { self .__class__ .__name__ } : { self } " )
4543 super ().save (signal , data_already_set , force_insert )
4644
4745 def delete (self , signal : bool = True ):
@@ -53,7 +51,7 @@ def delete(self, signal: bool = True):
5351 Args:
5452 signal (bool, optional): Whether to send a signal after deletion. Defaults to True.
5553 """
56- log .debug (f"Deleting { self .__class__ .__name__ } : { self } " )
54+ logger .debug (f"Deleting { self .__class__ .__name__ } : { self } " )
5755 super ().delete (signal )
5856
5957 @property
@@ -206,7 +204,7 @@ def save(self, signal: bool = True, data_already_set: bool = False, force_insert
206204 self .allocate ()
207205
208206 if changed_fields := [field for field in INHERITED_FIELDS if self .get (field ) != old .data .get (field )]:
209- log .info (f"Updating inherited fields { changed_fields } for products of process { self } " )
207+ logger .info (f"Updating inherited fields { changed_fields } for products of process { self } " )
210208 for product in self .products ():
211209 for field in changed_fields :
212210 product ._set_inherited (field , self .get (field ))
@@ -305,7 +303,7 @@ def property_template(self, name: str, amount=1.0) -> dict:
305303 normalize = set (prop .get ("normalize" , True ) for prop in properties )
306304
307305 if len (units ) > 1 or len (normalize ) > 1 :
308- log .warning (f"Property { name } has inconsistent units or normalization across products." )
306+ logger .warning (f"Property { name } has inconsistent units or normalization across products." )
309307
310308 return {
311309 "unit" : units .pop () if units else "unitless" ,
@@ -360,7 +358,7 @@ def allocate(self, strategy_label: Optional[str] = None) -> None:
360358 ValueError: If no allocation strategy is found.
361359 """
362360 if self .get ("skip_allocation" ):
363- log .debug (f"Skipping allocation for { repr (self )} (id: { self .id } )" )
361+ logger .debug (f"Skipping allocation for { repr (self )} (id: { self .id } )" )
364362 return
365363
366364 from . import allocation_strategies , property_allocation
@@ -376,7 +374,7 @@ def allocate(self, strategy_label: Optional[str] = None) -> None:
376374 "Can't find `default_allocation` in input arguments, or process/database metadata."
377375 )
378376
379- log .debug (f"Allocating { repr (self )} (id: { self .id } ) with strategy { strategy_label } " )
377+ logger .debug (f"Allocating { repr (self )} (id: { self .id } ) with strategy { strategy_label } " )
380378
381379 alloc_function = allocation_strategies .get (strategy_label , property_allocation (strategy_label ))
382380 alloc_function (self )
@@ -439,7 +437,7 @@ def save(self, signal: bool = True, data_already_set: bool = False, force_insert
439437
440438 # Check if the `processor` is the same as the one in the production edge otherwise update it
441439 if not created and edge .output != self ["processor" ]:
442- log .info (f"Switching processor for { self } " )
440+ logger .info (f"Switching processor for { self } " )
443441 edge .output = self ["processor" ]
444442 edge .save ()
445443
@@ -500,7 +498,7 @@ def processing_edge(self) -> MFExchange | None:
500498 excs = self .exchanges (kinds = ["production" ], reverse = True )
501499
502500 if len (excs ) > 1 :
503- log .warning (f"Multiple processing edges found for product { self ['code' ]} ." )
501+ logger .warning (f"Multiple processing edges found for product { self ['code' ]} ." )
504502 return None
505503 if len (excs ) == 0 :
506504 return None
0 commit comments