droidoc 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
droidoc/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ import os
2
+
3
+ from ._version import __author__
4
+ from ._version import __author_email__
5
+ from ._version import __copyright__
6
+ from ._version import __description__
7
+ from ._version import __license__
8
+ from ._version import __name_soft__
9
+ from ._version import __title__
10
+ from ._version import __url__
11
+ from ._version import __version__
droidoc/__main__.py ADDED
@@ -0,0 +1,120 @@
1
+ import argparse
2
+ import signal
3
+ import sys
4
+
5
+ from loguru import logger
6
+
7
+ from .droidoc import DroidocLib
8
+ from droidoc import __author__
9
+ from droidoc import __copyright__
10
+ from droidoc import __description__
11
+ from droidoc import __version__
12
+
13
+
14
+ class SmartFormatter(argparse.HelpFormatter):
15
+ """Smart formatter for argparse - The lines are split for long text"""
16
+
17
+ def _split_lines(self, text, width):
18
+ if text.startswith("R|"):
19
+ return text[2:].splitlines()
20
+ # this is the RawTextHelpFormatter._split_lines
21
+ return argparse.HelpFormatter._split_lines( # pylint: disable=protected-access
22
+ self, text, width
23
+ )
24
+
25
+
26
+ class SigintHandler: # pylint: disable=too-few-public-methods
27
+ """Handles the signal"""
28
+
29
+ def __init__(self):
30
+ self.SIGINT = False # pylint: disable=invalid-name
31
+
32
+ def signal_handler(self, sig: int, frame):
33
+ """Trap the signal
34
+
35
+ Args:
36
+ sig (int): the signal number
37
+ frame: the current stack frame
38
+ """
39
+ # pylint: disable=unused-argument
40
+ logger.error("You pressed Ctrl+C")
41
+ self.SIGINT = True
42
+ sys.exit(2)
43
+
44
+
45
+ def str2bool(string_to_test: str) -> bool:
46
+ """Checks if a given string is a boolean
47
+
48
+ Args:
49
+ string_to_test (str): string to test
50
+
51
+ Returns:
52
+ bool: True when the string is a boolean otherwise False
53
+ """
54
+ return string_to_test.lower() in ("yes", "true", "True", "t", "1")
55
+
56
+
57
+ def parse_cli() -> argparse.Namespace:
58
+ """Parse command line inputs.
59
+
60
+ Returns
61
+ -------
62
+ argparse.Namespace
63
+ Command line options
64
+ """
65
+ parser = argparse.ArgumentParser(
66
+ description=__description__,
67
+ formatter_class=SmartFormatter,
68
+ epilog=__author__ + " - " + __copyright__,
69
+ )
70
+ parser.add_argument(
71
+ "-v", "--version", action="version", version="%(prog)s " + __version__
72
+ )
73
+
74
+ parser.add_argument(
75
+ "--conf_file",
76
+ default="conf/droidoc.conf",
77
+ help="The location of the configuration file (default: %(default)s)",
78
+ )
79
+
80
+ parser.add_argument(
81
+ "--directory",
82
+ default="/app",
83
+ help="The base directory where the data products are read and saved (default: %(default)s)",
84
+ )
85
+
86
+ parser.add_argument(
87
+ "--level",
88
+ choices=[
89
+ "INFO",
90
+ "DEBUG",
91
+ "WARNING",
92
+ "ERROR",
93
+ "CRITICAL",
94
+ "TRACE",
95
+ ],
96
+ default="INFO",
97
+ help="set Level log (default: %(default)s)",
98
+ )
99
+
100
+ return parser.parse_args()
101
+
102
+
103
+ def run():
104
+ """Main function that instanciates the library."""
105
+ handler = SigintHandler()
106
+ signal.signal(signal.SIGINT, handler.signal_handler)
107
+ try:
108
+ options_cli = parse_cli()
109
+
110
+ droidoc = DroidocLib(**vars(options_cli))
111
+ droidoc.run()
112
+ sys.exit(0)
113
+ except Exception as error: # pylint: disable=broad-except
114
+ logger.exception(error)
115
+ sys.exit(1)
116
+
117
+
118
+ if __name__ == "__main__":
119
+ # execute only if run as a script
120
+ run()
droidoc/_version.py ADDED
@@ -0,0 +1,13 @@
1
+ from importlib.metadata import metadata
2
+
3
+ pkg_metadata = metadata("droidoc")
4
+
5
+ __name_soft__ = pkg_metadata.get("name", "unknown")
6
+ __version__ = pkg_metadata.get("version", "0.0.0")
7
+ __title__ = pkg_metadata.get("name", "unknown")
8
+ __description__ = pkg_metadata.get("summary", "")
9
+ __url__ = pkg_metadata.get("homepage", "")
10
+ __author__ = pkg_metadata.get("authors", "unknown")
11
+ __author_email__ = pkg_metadata.get("author-email", "unknown")
12
+ __license__ = pkg_metadata.get("license", "")
13
+ __copyright__ = "2026, (Dinil Bose Palakkatharappil )"
File without changes
droidoc/droidoc.py ADDED
@@ -0,0 +1,99 @@
1
+ import configparser
2
+ import sys
3
+ from typing import Any
4
+ from typing import Dict
5
+
6
+ from loguru import logger
7
+
8
+ from ._version import __name_soft__
9
+
10
+
11
+ class DroidocLib:
12
+ """The library"""
13
+
14
+ def __init__(self, **kwargs):
15
+ # pylint: disable=unused-argument
16
+ path_to_conf = kwargs.get("conf_file", "conf/droidoc.conf")
17
+ self.__config: configparser.ConfigParser = configparser.ConfigParser()
18
+ self.__config.optionxform = str # type: ignore
19
+ self.__config.read(path_to_conf)
20
+
21
+ self.__directory: str = kwargs.get("directory", "/app")
22
+ self.__level: str = kwargs.get("level", "INFO")
23
+ DroidocLib._parse_level(self.__level)
24
+
25
+ @staticmethod
26
+ def _parse_level(level: str):
27
+ """Parse level name and set the rigt level for the logger.
28
+ If the level is not known, the INFO level is set
29
+
30
+ Args:
31
+ level (str): level name
32
+ """
33
+ if level == "INFO":
34
+ loguru_level = "INFO"
35
+ elif level == "DEBUG":
36
+ loguru_level = "DEBUG"
37
+ elif level == "WARNING":
38
+ loguru_level = "WARNING"
39
+ elif level == "ERROR":
40
+ loguru_level = "ERROR"
41
+ elif level == "CRITICAL":
42
+ loguru_level = "CRITICAL"
43
+ elif level == "TRACE":
44
+ loguru_level = "TRACE"
45
+ else:
46
+ loguru_level = "INFO"
47
+ logger.log(
48
+ loguru_level,
49
+ f"Unknown level name : {level} - setting level to INFO",
50
+ )
51
+
52
+ logger.remove()
53
+ logger.add(sys.stdout, level=loguru_level)
54
+
55
+ @property
56
+ def config(self) -> configparser.ConfigParser:
57
+ """The configuration file.
58
+
59
+ :getter: Returns the configuration file
60
+ :type: configparser.ConfigParser
61
+ """
62
+ return self.__config
63
+
64
+ @property
65
+ def directory(self) -> str:
66
+ """The Base directory.
67
+
68
+ :getter: Returns the base directory
69
+ :type: str
70
+ """
71
+ return self.__directory
72
+
73
+ @directory.setter
74
+ def directory(self, value: str):
75
+ self.__directory = value
76
+
77
+ def sample_function(input: str):
78
+ """
79
+ Decorator to log the inputs and/or outputs of a function, with a configurable log level.
80
+
81
+ Args:
82
+ input (bool, optional): Indicates whether to log the inputs of the function. Defaults to `True`.
83
+
84
+ Returns:
85
+ Callable: The decorated function that logs its inputs and/or outputs.
86
+
87
+ Usage:
88
+ This decorator allows you to log the inputs and/or outputs of a function with a configurable log level.
89
+ It can be used for debugging or monitoring function execution by tracking the values of arguments and results.
90
+
91
+ Example usage:
92
+ In this example, only the inputs will be logged at the `DEBUG` level, and the output will not be logged.
93
+
94
+ Notes:
95
+ - The `input` and `output` parameters allow fine-grained control over whether the function's arguments or results are logged.
96
+
97
+ """
98
+ output = "nothing"
99
+ return output
droidoc/monitoring.py ADDED
@@ -0,0 +1,146 @@
1
+ """Some Utilities."""
2
+
3
+ import os
4
+ import time
5
+ import tracemalloc
6
+ from functools import partial
7
+ from functools import wraps
8
+
9
+ from loguru import logger
10
+
11
+
12
+ class UtilsMonitoring: # noqa: R0205
13
+ """Some Utilities."""
14
+
15
+ # pylint: disable:invalid_name
16
+ @staticmethod
17
+ def io_display(
18
+ func=None, input=True, output=True, level="TRACE"
19
+ ): # pylint: disable=W0622
20
+ """
21
+ Decorator to log the inputs and/or outputs of a function, with a configurable log level.
22
+
23
+ Args:
24
+ func (Callable, optional): Function to decorate. Defaults to `None`, which allows the decorator to be used with parameters.
25
+ input (bool, optional): Indicates whether to log the inputs of the function. Defaults to `True`.
26
+ output (bool, optional): Indicates whether to log the outputs of the function. Defaults to `True`.
27
+ level (str, optional): The log level used for logging messages. Defaults to "TRACE". Can be any of the log levels supported by `loguru` ("TRACE", "DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL").
28
+
29
+ Returns:
30
+ Callable: The decorated function that logs its inputs and/or outputs.
31
+
32
+ Usage:
33
+ This decorator allows you to log the inputs and/or outputs of a function with a configurable log level.
34
+ It can be used for debugging or monitoring function execution by tracking the values of arguments and results.
35
+
36
+ Example usage:
37
+
38
+ @UtilsMonitoring.io_display(input=True, output=False, level="DEBUG")
39
+ def add(a, b):
40
+ return a + b
41
+
42
+ add(3, 4)
43
+
44
+ In this example, only the inputs will be logged at the `DEBUG` level, and the output will not be logged.
45
+
46
+ Notes:
47
+ - If `func` is `None`, the decorator is configured with the given parameters.
48
+ - The `input` and `output` parameters allow fine-grained control over whether the function's arguments or results are logged.
49
+ - The `level` parameter must be a valid log level in `loguru` and is converted to uppercase before use.
50
+
51
+ """
52
+
53
+ def decorator(func):
54
+ @wraps(func)
55
+ def wrapper(*args, **kwargs):
56
+ # Obtenir le logger avec le niveau configuré
57
+ log_level = level.upper()
58
+
59
+ # Logger les entrées si configuré
60
+ if input:
61
+ logger.log(
62
+ log_level,
63
+ f"Input in the function '{func.__name__}' with args={args}, kwargs={kwargs}",
64
+ )
65
+
66
+ # Execute the function
67
+ result = func(*args, **kwargs)
68
+
69
+ # Log the outputs if configured
70
+ if output:
71
+ logger.log(
72
+ log_level,
73
+ f"Output in the function '{func.__name__}' with result={result}",
74
+ )
75
+
76
+ return result
77
+
78
+ return wrapper
79
+
80
+ return decorator
81
+
82
+ @staticmethod
83
+ def time_spend(func=None, level="DEBUG", threshold_in_ms=1000):
84
+ """Monitor the performances of a function.
85
+
86
+ Parameters
87
+ ----------
88
+ func: func
89
+ Function to monitor (default: {None})
90
+ level: int
91
+ Level from which the monitoring starts (default: {logging.DEBUG})
92
+ threshold_in_ms: int
93
+ an alert is sent at any level when the function duration >
94
+ threshold_in_ms (default: {1000})
95
+
96
+ Returns
97
+ -------
98
+ object : the result of the function
99
+ """
100
+ if func is None:
101
+ return partial(UtilsMonitoring.time_spend, level=level)
102
+
103
+ @wraps(func)
104
+ def newfunc(*args, **kwargs):
105
+ start_time = time.time()
106
+ result = func(*args, **kwargs)
107
+ elapsed_time = time.time() - start_time
108
+ logger.log(
109
+ level,
110
+ "function [{}] finished in {:.2f} ms".format(
111
+ func.__qualname__, elapsed_time * 1000
112
+ ),
113
+ )
114
+ return result
115
+
116
+ return newfunc
117
+
118
+ @staticmethod
119
+ def measure_memory(func=None, level="DEBUG"):
120
+ """Measure the memory of the function
121
+
122
+ Args:
123
+ func (func, optional): Function to measure. Defaults to None.
124
+ level (int, optional): Level of the log. Defaults to DEBUG.
125
+
126
+ Returns:
127
+ object : the result of the function
128
+ """
129
+ if func is None:
130
+ return partial(UtilsMonitoring.measure_memory, level=level)
131
+
132
+ @wraps(func)
133
+ def newfunc(*args, **kwargs):
134
+ tracemalloc.start()
135
+ result = func(*args, **kwargs)
136
+ current, peak = tracemalloc.get_traced_memory()
137
+ msg = f"""
138
+ \033[37mFunction Name :\033[35;1m {func.__name__}\033[0m
139
+ \033[37mCurrent memory usage:\033[36m {current / 10 ** 6}MB\033[0m
140
+ \033[37mPeak :\033[36m {peak / 10 ** 6}MB\033[0m
141
+ """
142
+ logger.log(level, msg)
143
+ tracemalloc.stop()
144
+ return result
145
+
146
+ return newfunc
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: droidoc
3
+ Version: 0.0.1
4
+ Summary: Droids Documentation fo Humanoids
5
+ License-Expression: MIT
6
+ License-File: AUTHORS.rst
7
+ License-File: LICENSE
8
+ Author: Dinil Bose Palakkatharappil
9
+ Author-email: dinilbose@gmail.com
10
+ Requires-Python: >=3.12
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Requires-Dist: loguru (>=0.7.2,<0.8.0)
17
+ Requires-Dist: toml (>=0.10.2,<0.11.0)
18
+ Description-Content-Type: text/x-rst
19
+
20
+ ===============================
21
+ droidoc
22
+ ===============================
23
+
24
+ .. image:: https://img.shields.io/badge/Maintained%3F-yes-green.svg
25
+ :target: https://gitlab.com/dinilbose/droidoc/-/network/main
26
+ .. image:: https://img.shields.io/badge/MIT-green
27
+
28
+ Droids Documentation fo Humanoids
29
+
30
+
31
+ Stable release
32
+ --------------
33
+
34
+ To install droidoc, run this command in your terminal:
35
+
36
+ .. code-block:: console
37
+
38
+ $ pip install git+https://gitlab.com/dinilbose/droidoc.git
39
+
40
+ This is the preferred method to install droidoc, as it will always install the most recent stable release.
41
+
42
+ If you don't have `pip`_ installed, this `Python installation guide`_ can guide
43
+ you through the process.
44
+
45
+ .. _pip: https://pip.pypa.io
46
+ .. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
47
+
48
+
49
+ From sources
50
+ ------------
51
+
52
+ The sources for droidoc can be downloaded from the `Gitlab repo`_.
53
+
54
+ You can either clone the public repository:
55
+
56
+ .. code-block:: console
57
+
58
+ $ git clone https://gitlab.com/dinilbose/droidoc.git
59
+
60
+ Or download the `tarball`_:
61
+
62
+ .. code-block:: console
63
+
64
+ $ curl -OJL https://gitlab.com/dinilbose/droidoc/tarball/main
65
+
66
+ Once you have a copy of the source, you can install it with:
67
+
68
+ .. code-block:: console
69
+
70
+ $ make # install in the system root
71
+ $ make user # or Install for non-root usage
72
+
73
+
74
+ .. _Gitlab repo: https://gitlab.com/dinilbose/droidoc
75
+ .. _tarball: https://gitlab.com/dinilbose/droidoc/tarball/main
76
+
77
+
78
+
79
+ Development
80
+ -----------
81
+
82
+ .. code-block:: console
83
+
84
+ $ git clone droidoc.git
85
+ $ cd droidoc
86
+ $ make prepare-dev
87
+ $ source .droidoc
88
+ $ make install-dev
89
+
90
+
91
+ To get more information about the preconfigured tasks:
92
+
93
+ .. code-block:: console
94
+
95
+ $ make help
96
+
97
+ Usage
98
+ -----
99
+
100
+ To use droidoc in a project::
101
+
102
+ import droidoc
103
+
104
+
105
+ With the docker:
106
+
107
+ .. code-block:: console
108
+
109
+ $ docker run -u $(id -u):$(id -g) -v $(pwd):/app --rm droidoc_image droidoc
110
+
111
+
112
+
113
+
114
+ Run tests
115
+ ---------
116
+
117
+ .. code-block:: console
118
+
119
+ $make tests
120
+
121
+
122
+ Documentation
123
+ -------------
124
+ The documentation is automatically deployed on https://gitlab.com/dinilbose/droidoc based on main branch
125
+
126
+ Container
127
+ ---------
128
+ A container is automatically created on https://gitlab.com/dinilbose/droidoc/container_registry
129
+
130
+
131
+ Author
132
+ ------
133
+ 👤 **Dinil Bose Palakkatharappil**
134
+
135
+
136
+
137
+ 🤝 Contributing
138
+ ---------------
139
+ Contributions, issues and feature requests are welcome!
140
+
141
+ Feel free to check `issues page <https://gitlab.com/dinilbose/droidoc/issues>`_. You can also take a look at the `contributing guide <https://gitlab.com/dinilbose/droidoc/blob/main/CONTRIBUTING.rst>`_
142
+
143
+
144
+ 📝 License
145
+ ----------
146
+ This project is `MIT <https://gitlab.com/dinilbose/droidoc/blob/main/LICENSE>`_ licensed.
147
+
@@ -0,0 +1,12 @@
1
+ droidoc/__init__.py,sha256=8HSSvwahpvEqgQUukcKd75s3fAcvALSz2sA-NblNkGg,323
2
+ droidoc/__main__.py,sha256=aruWo6XMqXrmixmr_GjfmmgslIsdlx1Yut_EhUve4Xo,3052
3
+ droidoc/_version.py,sha256=Vz1prWfBLSoexX2EV3EcTeKcUj_YCADCzYi-LlvcoFU,537
4
+ droidoc/conf/droidoc.conf,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ droidoc/droidoc.py,sha256=T5as23hbS5E1roHz5SOhFvtRfak8NZElQBGi8a4LHTE,3073
6
+ droidoc/monitoring.py,sha256=BmT6VtBVYay_B-sWP3qh61wET6wxLTHmfsbv0Rf6mPM,5148
7
+ droidoc-0.0.1.dist-info/METADATA,sha256=0JLzrUpO7j4iep6o_IGRWLE9s-ZNUoR72gYIfmwWxgM,3342
8
+ droidoc-0.0.1.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
9
+ droidoc-0.0.1.dist-info/entry_points.txt,sha256=18LF0rOYXsgxbalXzOGLmx_PQA7evhrXc5j1PoakYSA,48
10
+ droidoc-0.0.1.dist-info/licenses/AUTHORS.rst,sha256=bmXXV1kKC0oIeS2qrV3ipV8DLeywqk9YYn2xUOaZU64,150
11
+ droidoc-0.0.1.dist-info/licenses/LICENSE,sha256=NxurTJqckso6NgPqJb1N6RI4DrZRPyT-rryPF77LhU8,1062
12
+ droidoc-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.5.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ droidoc=droidoc.__main__:run
3
+
@@ -0,0 +1,13 @@
1
+ =======
2
+ Credits
3
+ =======
4
+
5
+ Development Lead
6
+ ----------------
7
+
8
+ * Dinil Bose Palakkatharappil <dinilbose@gmail.com>
9
+
10
+ Contributors
11
+ ------------
12
+
13
+ None yet.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2026] [-]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.