Skip to content

Commit

Permalink
Merge pull request Avaiga#1913 from Avaiga/feature/Avaiga#398-databri…
Browse files Browse the repository at this point in the history
…cks-poc

feature/enterprise/Avaiga#398 external services integration preparation
  • Loading branch information
toan-quach authored Oct 18, 2024
2 parents f77210c + 3f9b02d commit c7ce574
Showing 1 changed file with 52 additions and 29 deletions.
81 changes: 52 additions & 29 deletions taipy/common/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

""" The `taipy.common.config` package provides features to configure a Taipy application.
"""The `taipy.common.config` package provides features to configure a Taipy application.
Its main class is the `Config^` singleton. It exposes various static methods
and attributes to configure the Taipy application and retrieve the configuration values.
Expand Down Expand Up @@ -45,6 +45,8 @@
"""

import os
from inspect import signature
from typing import List

from ._init import Config
Expand All @@ -55,40 +57,55 @@
from .unique_section import UniqueSection


def _config_doc(func):
def func_with_doc(section, attr_name, default, configuration_methods, add_to_unconflicted_sections=False):
import os

if os.environ.get("GENERATING_TAIPY_DOC", None) and os.environ["GENERATING_TAIPY_DOC"] == "true":
with (open("config_doc.txt", "a") as f):
from inspect import signature

# Add the documentation for configure methods
for exposed_configuration_method, configuration_method in configuration_methods:
annotation = " @staticmethod\n"
sign = " def " + exposed_configuration_method + str(signature(configuration_method)) + ":\n"
doc = ' """' + configuration_method.__doc__ + '"""\n'
content = " pass\n\n"
f.write(annotation + sign + doc + content)

# Add the documentation for the attribute
annotation = ' @property\n'
sign = f" def {attr_name} (self) -> {section.__name__}:\n"
if issubclass(section, UniqueSection):
doc = f' """The configured {section.__name__} section."""\n'
elif issubclass(section, Section):
doc = f' """The configured {section.__name__} sections ."""\n'
else:
print(f" ERROR - Invalid section class: {section.__name__}") # noqa: T201
return
def __write_method_to_doc(configuration_methods):
if os.environ.get("GENERATING_TAIPY_DOC", None) and os.environ["GENERATING_TAIPY_DOC"] == "true":
with open("config_doc.txt", "a") as f:
from inspect import signature

# Add the documentation for configure methods
for exposed_configuration_method, configuration_method in configuration_methods:
annotation = " @staticmethod\n"
sign = " def " + exposed_configuration_method + str(signature(configuration_method)) + ":\n"
doc = ' """' + configuration_method.__doc__ + '"""\n'
content = " pass\n\n"
f.write(annotation + sign + doc + content)
return func(section, attr_name, default, configuration_methods, add_to_unconflicted_sections)


def __write_section_to_doc(section, attr_name):
if os.environ.get("GENERATING_TAIPY_DOC", None) and os.environ["GENERATING_TAIPY_DOC"] == "true":
with open("config_doc.txt", "a") as f:
# Add the documentation for the attribute
annotation = " @property\n"
sign = f" def {attr_name} (self) -> {section.__name__}:\n"
if issubclass(section, UniqueSection):
doc = f' """The configured {section.__name__} section."""\n'
elif issubclass(section, Section):
doc = f' """The configured {section.__name__} sections ."""\n'
else:
print(f" ERROR - Invalid section class: {section.__name__}") # noqa: T201
return
content = " pass\n\n"
f.write(annotation + sign + doc + content)


def _config_doc_for_section(func):
def func_with_doc(section, attribute_name, default, configuration_methods, add_to_unconflicted_sections=False):
__write_section_to_doc(section, attribute_name)
__write_method_to_doc(configuration_methods)
return func(section, attribute_name, default, configuration_methods, add_to_unconflicted_sections)

return func_with_doc


@_config_doc
def _config_doc_for_method(func):
def func_with_doc(configuration_methods):
__write_method_to_doc(configuration_methods)
return func(configuration_methods)

return func_with_doc


@_config_doc_for_section
def _inject_section(
section_clazz,
attribute_name: str,
Expand All @@ -110,3 +127,9 @@ def _inject_section(

for exposed_configuration_method, configuration_method in configuration_methods:
setattr(Config, exposed_configuration_method, configuration_method)


@_config_doc_for_method
def _inject_method(configuration_methods: List[tuple]):
for exposed_configuration_method, configuration_method in configuration_methods:
setattr(Config, exposed_configuration_method, configuration_method)

0 comments on commit c7ce574

Please sign in to comment.