replbase 0.0.35__tar.gz → 0.0.37__tar.gz
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.
- {replbase-0.0.35 → replbase-0.0.37}/PKG-INFO +1 -1
- {replbase-0.0.35 → replbase-0.0.37}/pyproject.toml +1 -1
- {replbase-0.0.35 → replbase-0.0.37}/replbase/cmd_meta.py +52 -3
- {replbase-0.0.35 → replbase-0.0.37}/LICENSE +0 -0
- {replbase-0.0.35 → replbase-0.0.37}/README.md +0 -0
- {replbase-0.0.35 → replbase-0.0.37}/replbase/__init__.py +0 -0
- {replbase-0.0.35 → replbase-0.0.37}/replbase/repl_base.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "replbase"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.37"
|
|
8
8
|
description = "\"Combination of other REPL tools into a reusable class that generates a REPL\""
|
|
9
9
|
authors = [ "Joseph Bochinski <stirgejr@gmail.com>",]
|
|
10
10
|
license = "MIT"
|
|
@@ -86,7 +86,7 @@ class CommandMeta:
|
|
|
86
86
|
self.type_hints = get_type_hints(self.func)
|
|
87
87
|
self.sig_parms = dict(inspect.signature(self.func).parameters)
|
|
88
88
|
|
|
89
|
-
docstring = self.
|
|
89
|
+
docstring = self.get_docstring()
|
|
90
90
|
|
|
91
91
|
header_re = re.compile(r"[A-Z].*?:$")
|
|
92
92
|
|
|
@@ -99,7 +99,7 @@ class CommandMeta:
|
|
|
99
99
|
|
|
100
100
|
def get_header(header: str) -> str:
|
|
101
101
|
nonlocal header_re
|
|
102
|
-
header_name = header_re.
|
|
102
|
+
header_name = header_re.findall(header)[0]
|
|
103
103
|
|
|
104
104
|
return header_name.lower().replace(":", "")
|
|
105
105
|
|
|
@@ -122,6 +122,55 @@ class CommandMeta:
|
|
|
122
122
|
self.parse_lines()
|
|
123
123
|
self.parse_flags()
|
|
124
124
|
|
|
125
|
+
def get_docstring(self) -> str | None:
|
|
126
|
+
"""Retrieve docstring from function or, if not available, from inherited classes
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
str | None: Docstring value
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
if not self.func:
|
|
133
|
+
return
|
|
134
|
+
|
|
135
|
+
if hasattr(self.func, "__doc__") and self.func.__doc__:
|
|
136
|
+
return self.func.__doc__
|
|
137
|
+
|
|
138
|
+
if not hasattr(self.func, "__name__") or not hasattr(self.func, "__self__"):
|
|
139
|
+
return
|
|
140
|
+
|
|
141
|
+
fname = self.func.__name__
|
|
142
|
+
fn_self = getattr(self.func, "__self__")
|
|
143
|
+
|
|
144
|
+
if not hasattr(fn_self, "__class__"):
|
|
145
|
+
return
|
|
146
|
+
|
|
147
|
+
cls = getattr(fn_self, "__class__")
|
|
148
|
+
if not hasattr(cls, "__bases__"):
|
|
149
|
+
return
|
|
150
|
+
|
|
151
|
+
bases = getattr(cls, "__bases__")
|
|
152
|
+
|
|
153
|
+
cls_fn = getattr(cls, fname)
|
|
154
|
+
|
|
155
|
+
cls_sig = inspect.signature(cls_fn)
|
|
156
|
+
|
|
157
|
+
for base in bases:
|
|
158
|
+
if not hasattr(base, fname):
|
|
159
|
+
continue
|
|
160
|
+
|
|
161
|
+
base_fn = getattr(base, fname)
|
|
162
|
+
|
|
163
|
+
if not inspect.signature(base_fn) == cls_sig:
|
|
164
|
+
continue
|
|
165
|
+
|
|
166
|
+
if not hasattr(base_fn, "__doc__"):
|
|
167
|
+
continue
|
|
168
|
+
|
|
169
|
+
doc = getattr(base_fn, "__doc__")
|
|
170
|
+
|
|
171
|
+
if doc:
|
|
172
|
+
return doc
|
|
173
|
+
|
|
125
174
|
def gen_command(self) -> ReplCommand:
|
|
126
175
|
"""Generate a ReplCommand object from the provided function
|
|
127
176
|
|
|
@@ -161,7 +210,7 @@ class CommandMeta:
|
|
|
161
210
|
"store_false" if parm.default is True else "store_true"
|
|
162
211
|
)
|
|
163
212
|
|
|
164
|
-
if arg_type
|
|
213
|
+
if arg_type not in [str, bool]:
|
|
165
214
|
cmd_init["type"] = arg_type
|
|
166
215
|
|
|
167
216
|
if isinstance(arg_type, type) and isinstance(parm.default, arg_type):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|