replbase 0.0.34__tar.gz → 0.0.36__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: replbase
3
- Version: 0.0.34
3
+ Version: 0.0.36
4
4
  Summary: "Combination of other REPL tools into a reusable class that generates a REPL"
5
5
  License: MIT
6
6
  Author: Joseph Bochinski
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "replbase"
7
- version = "0.0.34"
7
+ version = "0.0.36"
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.func.__doc__
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.search(header).groups()[0]
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
 
@@ -424,7 +424,7 @@ class ReplBase:
424
424
  if not callable(cmd):
425
425
  return
426
426
 
427
- return CommandMeta(cmd).gen_command()
427
+ return CommandMeta(func=cmd, register_cmd=self.add_command).gen_command()
428
428
 
429
429
  def setup_cmds(self, *cmd_names: list[str]) -> None:
430
430
  """Automatically configure commands based on the provided names
File without changes
File without changes