Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Create Poetry package #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import model.utils as _utils
__all__ = _utils.import_submodules(__name__).keys()
2 changes: 2 additions & 0 deletions experiments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import model.utils as _utils
__all__ = _utils.import_submodules(__name__).keys()
2 changes: 2 additions & 0 deletions model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import model.utils as _utils
__all__ = _utils.import_submodules(__name__).keys()
17 changes: 17 additions & 0 deletions model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"""

import copy
import sys
import importlib
import pkgutil
from dataclasses import field
from functools import partial

Expand Down Expand Up @@ -43,3 +46,17 @@ def local_variables(_locals):

def default(obj):
return field(default_factory=lambda: copy.copy(obj))


def import_submodules(package_name):
""" Import all submodules of a module, recursively

:param package_name: Package name
:type package_name: str
:rtype: dict[types.ModuleType]
"""
package = sys.modules[package_name]
return {
name: importlib.import_module(package_name + '.' + name)
for loader, name, is_pkg in pkgutil.walk_packages(package.__path__)
}
8 changes: 8 additions & 0 deletions package/cadlabs_ethereum_economic_model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
CADLabs Ethereum Economic Model package & version
"""
__version__ = "1.1.1"

import cadlabs_ethereum_economic_model.model as model
import cadlabs_ethereum_economic_model.experiments as experiments
import cadlabs_ethereum_economic_model.data as data
17 changes: 17 additions & 0 deletions package/cadlabs_ethereum_economic_model/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
import importlib
import pkgutil


def import_submodules(package_name):
""" Import all submodules of a module, recursively

:param package_name: Package name
:type package_name: str
:rtype: dict[types.ModuleType]
"""
package = sys.modules[package_name]
return {
name: importlib.import_module(package_name + '.' + name)
for loader, name, is_pkg in pkgutil.walk_packages(package.__path__)
}
4 changes: 4 additions & 0 deletions package/cadlabs_ethereum_economic_model/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys
import data

sys.modules['cadlabs_ethereum_economic_model.data'] = data
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys
import experiments

sys.modules['cadlabs_ethereum_economic_model.experiments'] = experiments
4 changes: 4 additions & 0 deletions package/cadlabs_ethereum_economic_model/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys
import model

sys.modules['cadlabs_ethereum_economic_model.model'] = model
Loading