Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #168 from benoit-dubreuil/feature/#166/export-deco…
Browse files Browse the repository at this point in the history
…rator-for-public-api

Feature/#166/export decorator for public api
  • Loading branch information
benoit-dubreuil committed Apr 18, 2021
2 parents 55a7d83 + 21cfce8 commit e990885
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/script/src/utils/meta_prog/encapsulation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .export import *
22 changes: 22 additions & 0 deletions conf/script/src/utils/meta_prog/encapsulation/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import inspect
import typing

__all__ = ['export']


def export(func: typing.Callable):
attribute_name_all: typing.Final[str] = '__all__'
module_api: list[str]

module = inspect.getmodule(func)
func_api = func.__qualname__

if not hasattr(module, attribute_name_all):
module_api = []
setattr(module, attribute_name_all, module_api)
else:
module_api = getattr(module, attribute_name_all)

module_api.append(func_api)

return func

0 comments on commit e990885

Please sign in to comment.