openbb-cli 1.0.0__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.
Files changed (42) hide show
  1. openbb_cli/__init__.py +1 -0
  2. openbb_cli/argparse_translator/__init__.py +0 -0
  3. openbb_cli/argparse_translator/argparse_class_processor.py +148 -0
  4. openbb_cli/argparse_translator/argparse_translator.py +627 -0
  5. openbb_cli/argparse_translator/obbject_registry.py +94 -0
  6. openbb_cli/assets/routines/routine_example.openbb +21 -0
  7. openbb_cli/assets/styles/default/Consolas.ttf +0 -0
  8. openbb_cli/assets/styles/default/dark.mpfstyle.json +47 -0
  9. openbb_cli/assets/styles/default/dark.mplrc.json +7 -0
  10. openbb_cli/assets/styles/default/dark.mplstyle +96 -0
  11. openbb_cli/assets/styles/default/dark.pltstyle.json +132 -0
  12. openbb_cli/assets/styles/default/dark.richstyle.json +9 -0
  13. openbb_cli/assets/styles/default/light.mpfstyle.json +47 -0
  14. openbb_cli/assets/styles/default/light.mplrc.json +7 -0
  15. openbb_cli/assets/styles/default/light.mplstyle +95 -0
  16. openbb_cli/assets/styles/default/light.pltstyle.json +871 -0
  17. openbb_cli/assets/styles/default/light.richstyle.json +9 -0
  18. openbb_cli/assets/styles/default/tables.pltstyle.json +102 -0
  19. openbb_cli/assets/styles/user/openbb.richstyle.json +9 -0
  20. openbb_cli/cli.py +20 -0
  21. openbb_cli/config/__init__.py +1 -0
  22. openbb_cli/config/completer.py +427 -0
  23. openbb_cli/config/console.py +93 -0
  24. openbb_cli/config/constants.py +80 -0
  25. openbb_cli/config/menu_text.py +165 -0
  26. openbb_cli/config/setup.py +11 -0
  27. openbb_cli/config/style.py +108 -0
  28. openbb_cli/controllers/base_controller.py +941 -0
  29. openbb_cli/controllers/base_platform_controller.py +349 -0
  30. openbb_cli/controllers/choices.py +324 -0
  31. openbb_cli/controllers/cli_controller.py +946 -0
  32. openbb_cli/controllers/hub_service.py +107 -0
  33. openbb_cli/controllers/platform_controller_factory.py +58 -0
  34. openbb_cli/controllers/script_parser.py +488 -0
  35. openbb_cli/controllers/settings_controller.py +373 -0
  36. openbb_cli/controllers/utils.py +967 -0
  37. openbb_cli/models/settings.py +73 -0
  38. openbb_cli/session.py +92 -0
  39. openbb_cli-1.0.0.dist-info/METADATA +91 -0
  40. openbb_cli-1.0.0.dist-info/RECORD +42 -0
  41. openbb_cli-1.0.0.dist-info/WHEEL +4 -0
  42. openbb_cli-1.0.0.dist-info/entry_points.txt +3 -0
openbb_cli/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """Package init"""
File without changes
@@ -0,0 +1,148 @@
1
+ import inspect
2
+ from typing import Any, Dict, Optional, Type
3
+
4
+ # TODO: this needs to be done differently
5
+ from openbb_core.app.static.container import Container
6
+
7
+ from openbb_cli.argparse_translator.argparse_translator import (
8
+ ArgparseTranslator,
9
+ ReferenceToCustomArgumentsProcessor,
10
+ )
11
+
12
+
13
+ class ArgparseClassProcessor:
14
+ """
15
+ Process a target class to create ArgparseTranslators for its methods.
16
+ """
17
+
18
+ # reference variable used to create custom groups for the ArgpaseTranslators
19
+ _reference: Dict[str, Any] = {}
20
+
21
+ def __init__(
22
+ self,
23
+ target_class: Type,
24
+ add_help: bool = False,
25
+ reference: Optional[Dict[str, Any]] = None,
26
+ ):
27
+ """
28
+ Initialize the ArgparseClassProcessor.
29
+
30
+ Parameters
31
+ ----------
32
+ target_class : Type
33
+ The target class whose methods will be processed.
34
+ add_help : Optional[bool]
35
+ Whether to add help to the ArgparseTranslators.
36
+ """
37
+ self._target_class: Type = target_class
38
+ self._add_help: bool = add_help
39
+ self._translators: Dict[str, ArgparseTranslator] = {}
40
+ self._paths: Dict[str, str] = {}
41
+
42
+ ArgparseClassProcessor._reference = reference or {}
43
+
44
+ self._translators = self._process_class(
45
+ target=self._target_class, add_help=self._add_help
46
+ )
47
+ self._paths[self._get_class_name(self._target_class)] = "path"
48
+ self._build_paths(target=self._target_class)
49
+
50
+ @property
51
+ def translators(self) -> Dict[str, ArgparseTranslator]:
52
+ """
53
+ Get the ArgparseTranslators associated with the target class.
54
+
55
+ Returns
56
+ -------
57
+ Dict[str, ArgparseTranslator]
58
+ The ArgparseTranslators associated with the target class.
59
+ """
60
+ return self._translators
61
+
62
+ @property
63
+ def paths(self) -> Dict[str, str]:
64
+ """
65
+ Get the paths associated with the target class.
66
+
67
+ Returns
68
+ -------
69
+ Dict[str, str]
70
+ The paths associated with the target class.
71
+ """
72
+ return self._paths
73
+
74
+ @classmethod
75
+ def _custom_groups_from_reference(cls, class_name: str, function_name: str) -> Dict:
76
+ route = f"/{class_name.replace('_', '/')}/{function_name}"
77
+ reference = {route: cls._reference[route]} if route in cls._reference else {}
78
+ if not reference:
79
+ return {}
80
+ rp = ReferenceToCustomArgumentsProcessor(reference)
81
+ return rp.custom_groups.get(route, {}) # type: ignore
82
+
83
+ @classmethod
84
+ def _process_class(
85
+ cls,
86
+ target: type,
87
+ add_help: bool = False,
88
+ ) -> Dict[str, ArgparseTranslator]:
89
+ methods = {}
90
+
91
+ for name, member in inspect.getmembers(target):
92
+ if name.startswith("__") or name.startswith("_"):
93
+ continue
94
+ if inspect.ismethod(member):
95
+
96
+ class_name = cls._get_class_name(target)
97
+ methods[f"{class_name}_{name}"] = ArgparseTranslator(
98
+ func=member,
99
+ add_help=add_help,
100
+ custom_argument_groups=cls._custom_groups_from_reference( # type: ignore
101
+ class_name=class_name, function_name=name
102
+ ),
103
+ )
104
+ elif isinstance(member, Container):
105
+ methods = {
106
+ **methods,
107
+ **cls._process_class(
108
+ target=getattr(target, name), add_help=add_help
109
+ ),
110
+ }
111
+
112
+ return methods
113
+
114
+ @staticmethod
115
+ def _get_class_name(target: type) -> str:
116
+ return (
117
+ str(type(target))
118
+ .rsplit(".", maxsplit=1)[-1]
119
+ .replace("'>", "")
120
+ .replace("ROUTER_", "")
121
+ .lower()
122
+ )
123
+
124
+ def get_translator(self, command: str) -> ArgparseTranslator:
125
+ """
126
+ Retrieve the ArgparseTranslator object associated with a specific menu and command.
127
+
128
+ Parameters
129
+ ----------
130
+ command : str
131
+ The command associated with the ArgparseTranslator.
132
+
133
+ Returns
134
+ -------
135
+ ArgparseTranslator
136
+ The ArgparseTranslator associated with the specified menu and command.
137
+ """
138
+ return self._translators[command]
139
+
140
+ def _build_paths(self, target: type, depth: int = 1):
141
+ for name, member in inspect.getmembers(target):
142
+ if name.startswith("__") or name.startswith("_"):
143
+ continue
144
+ if inspect.ismethod(member):
145
+ pass
146
+ elif isinstance(member, Container):
147
+ self._build_paths(target=getattr(target, name), depth=depth + 1)
148
+ self._paths[f"{name}"] = "sub" * depth + "path"