Skip to content

Commit

Permalink
- added docstrings
Browse files Browse the repository at this point in the history
- fixed soem more codacy issues
  • Loading branch information
Moritz Franz committed Nov 12, 2024
1 parent e03a071 commit 30a5d12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/pandapipes/component_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


# every high level Component from pandapipes should be initialized here
# if pandapipes implements a new component, it needs to be added to the COMPONENT_LIST

COMPONENT_LIST = [Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, MassStorage,
CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer,
Expand Down
18 changes: 18 additions & 0 deletions src/pandapipes/component_models/component_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@


class ComponentRegistry(object):
"""
Container for all pandapipes and custom components. Internal pandapipes components are added
during class initialization, while custom components are added during class creation via the
@register_component method.
The registry holds all instances of components in a singleton style and is accessible with
either the table_name (e.g. 'pipe') or the class name (e.g. Pipe, Pipe needs to be imported).
If other components methods are needed in a component, the 'get' method enables lazy-loading
of the component instance.
"""

registry = dict()

Expand All @@ -18,6 +27,9 @@ def __init__(self, comp_list):

@classmethod
def register(cls):
"""
Adds custom component to the component registry.
"""
def wrapper(wrapped_class):
wrapped_class.__iscustom__ = True
wrapped_class.__path_from_home__ = os.path.relpath(__file__, os.path.expanduser("~"))
Expand All @@ -29,7 +41,13 @@ def wrapper(wrapped_class):

@classmethod
def get(cls, comp):
"""
Useful for lazy-loading component instances.
"""
return cls.registry.get(comp, None)

def register_component(cls):
"""
Adds a custom component to the component registry.
"""
return ComponentRegistry.register()(cls)
5 changes: 1 addition & 4 deletions src/pandapipes/component_models/mass_storage_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

from pandapipes.component_models._const_flow_models import ConstFlow

class MassStorage(ConstFlow):
"""

"""
class MassStorage(ConstFlow):
@property
def table_name(self):
return "mass_storage"
Expand All @@ -18,7 +16,6 @@ def table_name(self):
def sign(self):
return 1

@classmethod
def get_component_input(self):
"""
Expand Down
1 change: 0 additions & 1 deletion src/pandapipes/utils/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class PipeflowNotConverged(ppException):
"""
Exception being raised in case pipeflow did not converge.
"""
pass


def get_net_option(net, option_name):
Expand Down

0 comments on commit 30a5d12

Please sign in to comment.