From d8183996f159a56b750c1e9b80b2996db9730913 Mon Sep 17 00:00:00 2001 From: Emerson Rocha Date: Wed, 31 Mar 2021 04:55:16 -0300 Subject: [PATCH] HXlm._DT (#5): inicial draft as internal HXLm library --- hxlm/core/__init__.py | 6 ++++-- hxlm/core/_dt/__init__.py | 3 +++ hxlm/core/_dt/test.py | 6 ++++++ hxlm/core/hdp/project.py | 41 ++++++++++++++++++++++++++++----------- setup.cfg | 1 + 5 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 hxlm/core/_dt/__init__.py create mode 100644 hxlm/core/_dt/test.py diff --git a/hxlm/core/__init__.py b/hxlm/core/__init__.py index fca6cd8..8c6895a 100644 --- a/hxlm/core/__init__.py +++ b/hxlm/core/__init__.py @@ -42,7 +42,9 @@ HDATUM_UDHR ) -import hxlm.core.hdp as HDP # noqa: F401 - import hxlm.core.localization as L10N # noqa: F401 import hxlm.core.util as util # noqa: F401 + + +import hxlm.core.hdp as HDP # noqa: F401 +import hxlm.core._dt as _DT # noqa: F401 diff --git a/hxlm/core/_dt/__init__.py b/hxlm/core/_dt/__init__.py new file mode 100644 index 0000000..4cf2615 --- /dev/null +++ b/hxlm/core/_dt/__init__.py @@ -0,0 +1,3 @@ +"""hxlm.core._dt +""" +import hxlm.core._dt.test # noqa: F401 diff --git a/hxlm/core/_dt/test.py b/hxlm/core/_dt/test.py new file mode 100644 index 0000000..228e4bd --- /dev/null +++ b/hxlm/core/_dt/test.py @@ -0,0 +1,6 @@ +"""hxlm.core._dt.test +""" + + +def test(): + print('test test test') diff --git a/hxlm/core/hdp/project.py b/hxlm/core/hdp/project.py index 97bdfcd..217facf 100644 --- a/hxlm/core/hdp/project.py +++ b/hxlm/core/hdp/project.py @@ -3,7 +3,7 @@ >>> import hxlm.core as HXLm >>> # Loading single file ->>> hp = HXLm.HDP.project(HXLm.HDATUM_UDHR) +>>> hp = HXLm.HDP.project(HXLm.HDATUM_UDHR).load() >>> hp.ok True @@ -82,6 +82,8 @@ class HDPProject: _entrypoint: str + _entrypoint_str: str + _l10n: L10NContext """Current active user context.""" @@ -103,17 +105,18 @@ class HDPProject: allow user correct in running time) """ + policy_loader: HDPPolicyLoad + """An HDP policy about what rules could be loaded + (ex.: restrict domains)""" + def __init__(self, entrypoint: Any, user_l10n: L10NContext, - policy: HDPPolicyLoad): - # self._entry_point = entrypoint + policy_loader: HDPPolicyLoad): + self._entrypoint_str = entrypoint self._l10n = user_l10n - self._parse_entrypoint(entrypoint) + self.policy_loader = policy_loader - if is_not_acceptable_load_this(entrypoint, policy): - raise SyntaxError('[' + entrypoint + - '] ¬ is_acceptable_load_this [' + - str(policy) + ']') + # return self def _parse_entrypoint(self, entrypoint: Any): """Generic parser for the initial entrypoint @@ -199,8 +202,22 @@ def info(self, dotted_key: str = None) -> str: return info + def load(self): + if is_not_acceptable_load_this(self._entrypoint_str, + self.policy_loader): + raise SyntaxError('[' + self._entrypoint_str + + '] ¬ is_acceptable_load_this [' + + str(self.policy_loader) + ']') + self._parse_entrypoint(self._entrypoint_str) + + return self + + def reload(self): + self.load() + return self + -def project(entry_point: str) -> HDPProject: +def project(entrypoint: str) -> HDPProject: """Initialize an HDP project (load collections of HDP files) Args: @@ -213,6 +230,8 @@ def project(entry_point: str) -> HDPProject: # TODO: eventually the policy should be configurable also on startup # not only when running - policy = get_policy_HDSL1() - result = HDPProject(entry_point, user_l10n=user_l10n, policy=policy) + policy_loader = get_policy_HDSL1() + result = HDPProject(entrypoint, + user_l10n=user_l10n, + policy_loader=policy_loader) return result diff --git a/setup.cfg b/setup.cfg index e730f22..8cf5942 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,6 +46,7 @@ install_requires = namespace_packages = hxlm packages = hxlm.core + hxlm.core._dt hxlm.core.bin hxlm.core.hdp hxlm.core.htype