micropython-stubber 1.14.1__py3-none-any.whl → 1.15.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.
Files changed (50) hide show
  1. micropython_stubber-1.15.1.dist-info/METADATA +244 -0
  2. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/RECORD +49 -46
  3. stubber/__init__.py +1 -1
  4. stubber/basicgit.py +27 -14
  5. stubber/board/createstubs.py +34 -36
  6. stubber/board/createstubs_db.py +35 -35
  7. stubber/board/createstubs_db_min.py +195 -193
  8. stubber/board/createstubs_db_mpy.mpy +0 -0
  9. stubber/board/createstubs_info.py +73 -42
  10. stubber/board/createstubs_lvgl.py +35 -35
  11. stubber/board/createstubs_lvgl_min.py +88 -87
  12. stubber/board/createstubs_lvgl_mpy.mpy +0 -0
  13. stubber/board/createstubs_mem.py +44 -40
  14. stubber/board/createstubs_mem_min.py +179 -174
  15. stubber/board/createstubs_mem_mpy.mpy +0 -0
  16. stubber/board/createstubs_min.py +75 -74
  17. stubber/board/createstubs_mpy.mpy +0 -0
  18. stubber/board/info.py +183 -0
  19. stubber/codemod/enrich.py +28 -16
  20. stubber/commands/build_cmd.py +3 -3
  21. stubber/commands/get_core_cmd.py +17 -5
  22. stubber/commands/get_docstubs_cmd.py +23 -8
  23. stubber/commands/get_frozen_cmd.py +62 -9
  24. stubber/commands/get_lobo_cmd.py +13 -3
  25. stubber/commands/merge_cmd.py +7 -4
  26. stubber/commands/publish_cmd.py +5 -4
  27. stubber/commands/stub_cmd.py +2 -1
  28. stubber/commands/variants_cmd.py +0 -1
  29. stubber/freeze/common.py +2 -2
  30. stubber/freeze/freeze_folder.py +1 -1
  31. stubber/freeze/get_frozen.py +1 -1
  32. stubber/minify.py +43 -28
  33. stubber/publish/bump.py +1 -1
  34. stubber/publish/candidates.py +61 -17
  35. stubber/publish/defaults.py +44 -0
  36. stubber/publish/merge_docstubs.py +19 -56
  37. stubber/publish/package.py +44 -37
  38. stubber/publish/pathnames.py +51 -0
  39. stubber/publish/publish.py +5 -4
  40. stubber/publish/stubpacker.py +55 -33
  41. stubber/rst/lookup.py +7 -16
  42. stubber/rst/reader.py +39 -8
  43. stubber/stubs_from_docs.py +5 -8
  44. stubber/utils/post.py +34 -40
  45. stubber/utils/repos.py +32 -17
  46. stubber/utils/stubmaker.py +22 -14
  47. micropython_stubber-1.14.1.dist-info/METADATA +0 -217
  48. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/LICENSE +0 -0
  49. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/WHEEL +0 -0
  50. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/entry_points.txt +0 -0
@@ -38,11 +38,11 @@ class Stubber:
38
38
  except AttributeError:
39
39
  pass
40
40
 
41
- self._log = logging.getLogger("stubber")
41
+ self.log = logging.getLogger("stubber")
42
42
  self._report = [] # type: list[str]
43
43
  self.info = _info()
44
- self._log.info("Port: {}".format(self.info["port"]))
45
- self._log.info("Board: {}".format(self.info["board"]))
44
+ self.log.info("Port: {}".format(self.info["port"]))
45
+ self.log.info("Board: {}".format(self.info["board"]))
46
46
  gc.collect()
47
47
  if firmware_id:
48
48
  self._fwid = firmware_id.lower()
@@ -60,11 +60,11 @@ class Stubber:
60
60
  path = get_root()
61
61
 
62
62
  self.path = "{}/stubs/{}".format(path, self.flat_fwid).replace("//", "/")
63
- self._log.debug(self.path)
63
+ self.log.debug(self.path)
64
64
  try:
65
65
  ensure_folder(path + "/")
66
66
  except OSError:
67
- self._log.error("error creating stub folder {}".format(path))
67
+ self.log.error("error creating stub folder {}".format(path))
68
68
  self.problematic = [
69
69
  "upip",
70
70
  "upysh",
@@ -89,11 +89,11 @@ class Stubber:
89
89
  # name_, repr_(value), type as text, item_instance
90
90
  _result = []
91
91
  _errors = []
92
- self._log.debug("get attributes {} {}".format(repr(item_instance), item_instance))
92
+ self.log.debug("get attributes {} {}".format(repr(item_instance), item_instance))
93
93
  for name in dir(item_instance):
94
94
  if name.startswith("_") and not name in self.modules:
95
95
  continue
96
- self._log.debug("get attribute {}".format(name))
96
+ self.log.debug("get attribute {}".format(name))
97
97
  try:
98
98
  val = getattr(item_instance, name)
99
99
  # name , item_repr(value) , type as text, item_instance, order
@@ -111,7 +111,11 @@ class Stubber:
111
111
  order = 4
112
112
  _result.append((name, repr(val), repr(type(val)), val, order))
113
113
  except AttributeError as e:
114
- _errors.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(name, item_instance, e))
114
+ _errors.append(
115
+ "Couldn't get attribute '{}' from object '{}', Err: {}".format(
116
+ name, item_instance, e
117
+ )
118
+ )
115
119
  except MemoryError as e:
116
120
  print("MemoryError: {}".format(e))
117
121
  sleep(1)
@@ -129,20 +133,20 @@ class Stubber:
129
133
 
130
134
  def create_all_stubs(self):
131
135
  "Create stubs for all configured modules"
132
- self._log.info("Start micropython-stubber v{} on {}".format(__version__, self._fwid))
136
+ self.log.info("Start micropython-stubber v{} on {}".format(__version__, self._fwid))
133
137
  log_mem("create_all_stubs")
134
138
  gc.collect()
135
139
  for module_name in self.modules:
136
140
  self.create_one_stub(module_name)
137
- self._log.info("Finally done")
141
+ self.log.info("Finally done")
138
142
 
139
143
  def create_one_stub(self, module_name: str):
140
144
  log_mem(f"create_one_stub:{module_name}")
141
145
  if module_name in self.problematic:
142
- self._log.warning("Skip module: {:<25} : Known problematic".format(module_name))
146
+ self.log.warning("Skip module: {:<25} : Known problematic".format(module_name))
143
147
  return False
144
148
  if module_name in self.excluded:
145
- self._log.warning("Skip module: {:<25} : Excluded".format(module_name))
149
+ self.log.warning("Skip module: {:<25} : Excluded".format(module_name))
146
150
  return False
147
151
 
148
152
  file_name = "{}/{}.py".format(self.path, module_name.replace(".", "/"))
@@ -179,48 +183,56 @@ class Stubber:
179
183
  m1 = gc.mem_free() # type: ignore
180
184
  log_mem(module_name)
181
185
 
182
- self._log.info("Stub module: {:<25} to file: {:<70} mem:{:>5}".format(module_name, fname, m1))
186
+ self.log.info(
187
+ "Stub module: {:<25} to file: {:<70} mem:{:>5}".format(module_name, fname, m1)
188
+ )
183
189
 
184
190
  except ImportError:
185
- self._log.warning("Skip module: {:<25} {:<79}".format(module_name, "Module not found."))
191
+ self.log.warning("Skip module: {:<25} {:<79}".format(module_name, "Module not found."))
186
192
  return False
187
193
 
188
194
  # Start a new file
189
195
  ensure_folder(file_name)
190
196
  with open(file_name, "w") as fp:
191
197
  # todo: improve header
192
- s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, self.info, __version__)
198
+ s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(
199
+ module_name, self._fwid, self.info, __version__
200
+ )
193
201
  fp.write(s)
194
202
  fp.write("from typing import Any\n\n")
195
203
  self.write_object_stub(fp, new_module, module_name, "")
196
204
 
197
- self._report.append('{{"module": "{}", "file": "{}"}}'.format(module_name, file_name.replace("\\", "/")))
205
+ self._report.append(
206
+ '{{"module": "{}", "file": "{}"}}'.format(module_name, file_name.replace("\\", "/"))
207
+ )
198
208
 
199
209
  if module_name not in {"os", "sys", "logging", "gc"}:
200
210
  # try to unload the module unless we use it
201
211
  try:
202
212
  del new_module
203
213
  except (OSError, KeyError): # lgtm [py/unreachable-statement]
204
- self._log.warning("could not del new_module")
214
+ self.log.warning("could not del new_module")
205
215
  try:
206
216
  del sys.modules[module_name]
207
217
  except KeyError:
208
- self._log.debug("could not del sys.modules[{}]".format(module_name))
218
+ self.log.debug("could not del sys.modules[{}]".format(module_name))
209
219
  gc.collect()
210
220
  return True
211
221
 
212
- def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str, in_class: int = 0):
222
+ def write_object_stub(
223
+ self, fp, object_expr: object, obj_name: str, indent: str, in_class: int = 0
224
+ ):
213
225
  "Write a module/object stub to an open file. Can be called recursive."
214
226
  gc.collect()
215
227
  if object_expr in self.problematic:
216
- self._log.warning("SKIPPING problematic module:{}".format(object_expr))
228
+ self.log.warning("SKIPPING problematic module:{}".format(object_expr))
217
229
  return
218
230
 
219
- # self._log.debug("DUMP : {}".format(object_expr))
231
+ # self.log.debug("DUMP : {}".format(object_expr))
220
232
  items, errors = self.get_obj_attributes(object_expr)
221
233
 
222
234
  if errors:
223
- self._log.error(errors)
235
+ self.log.error(errors)
224
236
 
225
237
  for item_name, item_repr, item_type_txt, item_instance, _ in items:
226
238
  # name_, repr_(value), type as text, item_instance, order
@@ -228,11 +240,11 @@ class Stubber:
228
240
  if item_name in ["classmethod", "staticmethod", "BaseException", "Exception"]:
229
241
  continue
230
242
  if item_name[0].isdigit():
231
- self._log.warning("NameError: invalid name {}".format(item_name))
243
+ self.log.warning("NameError: invalid name {}".format(item_name))
232
244
  continue
233
245
  # Class expansion only on first 3 levels (bit of a hack)
234
246
  if item_type_txt == "<class 'type'>" and len(indent) <= _MAX_CLASS_LEVEL * 4:
235
- self._log.debug("{0}class {1}:".format(indent, item_name))
247
+ self.log.debug("{0}class {1}:".format(indent, item_name))
236
248
  superclass = ""
237
249
  is_exception = (
238
250
  item_name.endswith("Exception")
@@ -255,7 +267,7 @@ class Stubber:
255
267
  # write classdef
256
268
  fp.write(s)
257
269
  # first write the class literals and methods
258
- self._log.debug("# recursion over class {0}".format(item_name))
270
+ self.log.debug("# recursion over class {0}".format(item_name))
259
271
  self.write_object_stub(
260
272
  fp,
261
273
  item_instance,
@@ -269,7 +281,9 @@ class Stubber:
269
281
  s += indent + " ...\n\n"
270
282
  fp.write(s)
271
283
  elif "method" in item_type_txt or "function" in item_type_txt:
272
- self._log.debug("# def {1} function or method, type = '{0}'".format(item_type_txt, item_name))
284
+ self.log.debug(
285
+ "# def {1} function or method, type = '{0}'".format(item_type_txt, item_name)
286
+ )
273
287
  # module Function or class method
274
288
  # will accept any number of params
275
289
  # return type Any
@@ -280,12 +294,16 @@ class Stubber:
280
294
  first = "self, "
281
295
  # class method - add function decoration
282
296
  if "bound_method" in item_type_txt or "bound_method" in item_repr:
283
- s = "{}@classmethod\n".format(indent) + "{}def {}(cls, *args, **kwargs) -> {}:\n".format(indent, item_name, ret)
297
+ s = "{}@classmethod\n".format(
298
+ indent
299
+ ) + "{}def {}(cls, *args, **kwargs) -> {}:\n".format(indent, item_name, ret)
284
300
  else:
285
- s = "{}def {}({}*args, **kwargs) -> {}:\n".format(indent, item_name, first, ret)
301
+ s = "{}def {}({}*args, **kwargs) -> {}:\n".format(
302
+ indent, item_name, first, ret
303
+ )
286
304
  s += indent + " ...\n\n"
287
305
  fp.write(s)
288
- self._log.debug("\n" + s)
306
+ self.log.debug("\n" + s)
289
307
  elif item_type_txt == "<class 'module'>":
290
308
  # Skip imported modules
291
309
  # fp.write("# import {}\n".format(item_name))
@@ -309,12 +327,14 @@ class Stubber:
309
327
  # https://docs.python.org/3/tutorial/classes.html#item_instance-objects
310
328
  t = "Any"
311
329
  # Requires Python 3.6 syntax, which is OK for the stubs/pyi
312
- s = "{0}{1} : {2} ## {3} = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
330
+ s = "{0}{1} : {2} ## {3} = {4}\n".format(
331
+ indent, item_name, t, item_type_txt, item_repr
332
+ )
313
333
  fp.write(s)
314
- self._log.debug("\n" + s)
334
+ self.log.debug("\n" + s)
315
335
  else:
316
336
  # keep only the name
317
- self._log.debug("# all other, type = '{0}'".format(item_type_txt))
337
+ self.log.debug("# all other, type = '{0}'".format(item_type_txt))
318
338
  fp.write("# all other, type = '{0}'\n".format(item_type_txt))
319
339
 
320
340
  fp.write(indent + item_name + " # type: Any\n")
@@ -340,7 +360,7 @@ class Stubber:
340
360
  "Remove all files from the stub folder"
341
361
  if path is None:
342
362
  path = self.path
343
- self._log.info("Clean/remove files in folder: {}".format(path))
363
+ self.log.info("Clean/remove files in folder: {}".format(path))
344
364
  try:
345
365
  os.stat(path) # TEMP workaround mpremote listdir bug -
346
366
  items = os.listdir(path)
@@ -360,9 +380,13 @@ class Stubber:
360
380
 
361
381
  def report(self, filename: str = "modules.json"):
362
382
  "create json with list of exported modules"
363
- self._log.info("Created stubs for {} modules on board {}\nPath: {}".format(len(self._report), self._fwid, self.path))
383
+ self.log.info(
384
+ "Created stubs for {} modules on board {}\nPath: {}".format(
385
+ len(self._report), self._fwid, self.path
386
+ )
387
+ )
364
388
  f_name = "{}/{}".format(self.path, filename)
365
- self._log.info("Report file: {}".format(f_name))
389
+ self.log.info("Report file: {}".format(f_name))
366
390
  gc.collect()
367
391
  try:
368
392
  # write json by node to reduce memory requirements
@@ -374,9 +398,9 @@ class Stubber:
374
398
  first = False
375
399
  self.write_json_end(f)
376
400
  used = self._start_free - gc.mem_free() # type: ignore
377
- self._log.info("Memory used: {0} Kb".format(used // 1024))
401
+ self.log.info("Memory used: {0} Kb".format(used // 1024))
378
402
  except OSError:
379
- self._log.error("Failed to create the report.")
403
+ self.log.error("Failed to create the report.")
380
404
 
381
405
  def write_json_header(self, f):
382
406
  f.write("{")
@@ -411,7 +435,7 @@ def ensure_folder(path: str):
411
435
  try:
412
436
  os.mkdir(p)
413
437
  except OSError as e2:
414
- _log.error("failed to create folder {}".format(p))
438
+ log.error("failed to create folder {}".format(p))
415
439
  raise e2
416
440
  # next level deep
417
441
  start = i + 1
@@ -433,7 +457,9 @@ def _info(): # type:() -> dict[str, str]
433
457
  "version": "",
434
458
  "build": "",
435
459
  "ver": "",
436
- "port": "stm32" if sys.platform.startswith("pyb") else sys.platform, # port: esp32 / win32 / linux / stm32
460
+ "port": "stm32"
461
+ if sys.platform.startswith("pyb")
462
+ else sys.platform, # port: esp32 / win32 / linux / stm32
437
463
  "board": "GENERIC",
438
464
  "cpu": "",
439
465
  "mpy": "",
@@ -445,7 +471,11 @@ def _info(): # type:() -> dict[str, str]
445
471
  except AttributeError:
446
472
  pass
447
473
  try:
448
- machine = sys.implementation._machine if "_machine" in dir(sys.implementation) else os.uname().machine
474
+ machine = (
475
+ sys.implementation._machine
476
+ if "_machine" in dir(sys.implementation)
477
+ else os.uname().machine
478
+ )
449
479
  info["board"] = machine.strip()
450
480
  info["cpu"] = machine.split("with")[1].strip()
451
481
  info["mpy"] = (
@@ -515,7 +545,8 @@ def _info(): # type:() -> dict[str, str]
515
545
  if (
516
546
  info["version"]
517
547
  and info["version"].endswith(".0")
518
- and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.20.0 do not have a micro .0
548
+ and info["version"]
549
+ >= "1.10.0" # versions from 1.10.0 to 1.20.0 do not have a micro .0
519
550
  and info["version"] <= "1.19.9"
520
551
  ):
521
552
  # drop the .0 for newer releases
@@ -886,7 +917,7 @@ def log_mem(id="", verbose=True):
886
917
 
887
918
  if __name__ == "__main__" or is_micropython():
888
919
  try:
889
- _log = logging.getLogger("stubber")
920
+ log = logging.getLogger("stubber")
890
921
  logging.basicConfig(level=logging.INFO)
891
922
  # logging.basicConfig(level=logging.DEBUG)
892
923
  except NameError:
@@ -3,7 +3,7 @@ Create stubs for the lvgl modules on a MicroPython board.
3
3
 
4
4
  Note that the stubs can be very large, and it may be best to directly store them on an SD card if your device supports this.
5
5
 
6
- This variant was generated from createstubs.py by micropython-stubber v1.13.8
6
+ This variant was generated from createstubs.py by micropython-stubber v1.15.0
7
7
  """
8
8
  # Copyright (c) 2019-2023 Jos Verlinde
9
9
  # pylint: disable= invalid-name, missing-function-docstring, import-outside-toplevel, logging-not-lazy
@@ -24,7 +24,7 @@ try:
24
24
  except ImportError:
25
25
  from ucollections import OrderedDict # type: ignore
26
26
 
27
- __version__ = "v1.13.8"
27
+ __version__ = "v1.15.0"
28
28
  ENOENT = 2
29
29
  _MAX_CLASS_LEVEL = 2 # Max class nesting
30
30
  LIBS = [".", "/lib", "/sd/lib", "/flash/lib", "lib"]
@@ -40,12 +40,12 @@ class Stubber:
40
40
  raise NotImplementedError("MicroPython 1.13.0 cannot be stubbed")
41
41
  except AttributeError:
42
42
  pass
43
-
44
- self._log = logging.getLogger("stubber")
43
+ self.log = None
44
+ self.log = logging.getLogger("stubber")
45
45
  self._report = [] # type: list[str]
46
46
  self.info = _info()
47
- self._log.info("Port: {}".format(self.info["port"]))
48
- self._log.info("Board: {}".format(self.info["board"]))
47
+ self.log.info("Port: {}".format(self.info["port"]))
48
+ self.log.info("Board: {}".format(self.info["board"]))
49
49
  gc.collect()
50
50
  if firmware_id:
51
51
  self._fwid = firmware_id.lower()
@@ -63,11 +63,11 @@ class Stubber:
63
63
  path = get_root()
64
64
 
65
65
  self.path = "{}/stubs/{}".format(path, self.flat_fwid).replace("//", "/")
66
- self._log.debug(self.path)
66
+ self.log.debug(self.path)
67
67
  try:
68
68
  ensure_folder(path + "/")
69
69
  except OSError:
70
- self._log.error("error creating stub folder {}".format(path))
70
+ self.log.error("error creating stub folder {}".format(path))
71
71
  self.problematic = [
72
72
  "upip",
73
73
  "upysh",
@@ -92,11 +92,11 @@ class Stubber:
92
92
  # name_, repr_(value), type as text, item_instance
93
93
  _result = []
94
94
  _errors = []
95
- self._log.debug("get attributes {} {}".format(repr(item_instance), item_instance))
95
+ self.log.debug("get attributes {} {}".format(repr(item_instance), item_instance))
96
96
  for name in dir(item_instance):
97
97
  if name.startswith("_") and not name in self.modules:
98
98
  continue
99
- self._log.debug("get attribute {}".format(name))
99
+ self.log.debug("get attribute {}".format(name))
100
100
  try:
101
101
  val = getattr(item_instance, name)
102
102
  # name , item_repr(value) , type as text, item_instance, order
@@ -132,18 +132,18 @@ class Stubber:
132
132
 
133
133
  def create_all_stubs(self):
134
134
  "Create stubs for all configured modules"
135
- self._log.info("Start micropython-stubber v{} on {}".format(__version__, self._fwid))
135
+ self.log.info("Start micropython-stubber v{} on {}".format(__version__, self._fwid))
136
136
  gc.collect()
137
137
  for module_name in self.modules:
138
138
  self.create_one_stub(module_name)
139
- self._log.info("Finally done")
139
+ self.log.info("Finally done")
140
140
 
141
141
  def create_one_stub(self, module_name: str):
142
142
  if module_name in self.problematic:
143
- self._log.warning("Skip module: {:<25} : Known problematic".format(module_name))
143
+ self.log.warning("Skip module: {:<25} : Known problematic".format(module_name))
144
144
  return False
145
145
  if module_name in self.excluded:
146
- self._log.warning("Skip module: {:<25} : Excluded".format(module_name))
146
+ self.log.warning("Skip module: {:<25} : Excluded".format(module_name))
147
147
  return False
148
148
 
149
149
  file_name = "{}/{}.py".format(self.path, module_name.replace(".", "/"))
@@ -178,10 +178,10 @@ class Stubber:
178
178
  try:
179
179
  new_module = __import__(module_name, None, None, ("*"))
180
180
  m1 = gc.mem_free() # type: ignore
181
- self._log.info("Stub module: {:<25} to file: {:<70} mem:{:>5}".format(module_name, fname, m1))
181
+ self.log.info("Stub module: {:<25} to file: {:<70} mem:{:>5}".format(module_name, fname, m1))
182
182
 
183
183
  except ImportError:
184
- self._log.warning("Skip module: {:<25} {:<79}".format(module_name, "Module not found."))
184
+ self.log.warning("Skip module: {:<25} {:<79}".format(module_name, "Module not found."))
185
185
  return False
186
186
 
187
187
  # Start a new file
@@ -201,11 +201,11 @@ class Stubber:
201
201
  try:
202
202
  del new_module
203
203
  except (OSError, KeyError): # lgtm [py/unreachable-statement]
204
- self._log.warning("could not del new_module")
204
+ self.log.warning("could not del new_module")
205
205
  try:
206
206
  del sys.modules[module_name]
207
207
  except KeyError:
208
- self._log.debug("could not del sys.modules[{}]".format(module_name))
208
+ self.log.debug("could not del sys.modules[{}]".format(module_name))
209
209
  gc.collect()
210
210
  return True
211
211
 
@@ -213,14 +213,14 @@ class Stubber:
213
213
  "Write a module/object stub to an open file. Can be called recursive."
214
214
  gc.collect()
215
215
  if object_expr in self.problematic:
216
- self._log.warning("SKIPPING problematic module:{}".format(object_expr))
216
+ self.log.warning("SKIPPING problematic module:{}".format(object_expr))
217
217
  return
218
218
 
219
- # self._log.debug("DUMP : {}".format(object_expr))
219
+ # self.log.debug("DUMP : {}".format(object_expr))
220
220
  items, errors = self.get_obj_attributes(object_expr)
221
221
 
222
222
  if errors:
223
- self._log.error(errors)
223
+ self.log.error(errors)
224
224
 
225
225
  for item_name, item_repr, item_type_txt, item_instance, _ in items:
226
226
  # name_, repr_(value), type as text, item_instance, order
@@ -228,11 +228,11 @@ class Stubber:
228
228
  # do not create stubs for these primitives
229
229
  continue
230
230
  if item_name[0].isdigit():
231
- self._log.warning("NameError: invalid name {}".format(item_name))
231
+ self.log.warning("NameError: invalid name {}".format(item_name))
232
232
  continue
233
233
  # Class expansion only on first 3 levels (bit of a hack)
234
234
  if item_type_txt == "<class 'type'>" and len(indent) <= _MAX_CLASS_LEVEL * 4:
235
- self._log.debug("{0}class {1}:".format(indent, item_name))
235
+ self.log.debug("{0}class {1}:".format(indent, item_name))
236
236
  superclass = ""
237
237
  is_exception = (
238
238
  item_name.endswith("Exception")
@@ -255,7 +255,7 @@ class Stubber:
255
255
  # write classdef
256
256
  fp.write(s)
257
257
  # first write the class literals and methods
258
- self._log.debug("# recursion over class {0}".format(item_name))
258
+ self.log.debug("# recursion over class {0}".format(item_name))
259
259
  self.write_object_stub(
260
260
  fp,
261
261
  item_instance,
@@ -269,7 +269,7 @@ class Stubber:
269
269
  s += indent + " ...\n\n"
270
270
  fp.write(s)
271
271
  elif any(word in item_type_txt for word in ["method", "function", "closure"]):
272
- self._log.debug("# def {1} function/method/closure, type = '{0}'".format(item_type_txt, item_name))
272
+ self.log.debug("# def {1} function/method/closure, type = '{0}'".format(item_type_txt, item_name))
273
273
  # module Function or class method
274
274
  # will accept any number of params
275
275
  # return type Any/Incomplete
@@ -285,7 +285,7 @@ class Stubber:
285
285
  s = "{}def {}({}*args, **kwargs) -> {}:\n".format(indent, item_name, first, ret)
286
286
  s += indent + " ...\n\n"
287
287
  fp.write(s)
288
- self._log.debug("\n" + s)
288
+ self.log.debug("\n" + s)
289
289
  elif item_type_txt == "<class 'module'>":
290
290
  # Skip imported modules
291
291
  # fp.write("# import {}\n".format(item_name))
@@ -311,10 +311,10 @@ class Stubber:
311
311
  # Requires Python 3.6 syntax, which is OK for the stubs/pyi
312
312
  s = "{0}{1} : {2} ## {3} = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
313
313
  fp.write(s)
314
- self._log.debug("\n" + s)
314
+ self.log.debug("\n" + s)
315
315
  else:
316
316
  # keep only the name
317
- self._log.debug("# all other, type = '{0}'".format(item_type_txt))
317
+ self.log.debug("# all other, type = '{0}'".format(item_type_txt))
318
318
  fp.write("# all other, type = '{0}'\n".format(item_type_txt))
319
319
 
320
320
  fp.write(indent + item_name + " # type: Incomplete\n")
@@ -340,7 +340,7 @@ class Stubber:
340
340
  "Remove all files from the stub folder"
341
341
  if path is None:
342
342
  path = self.path
343
- self._log.info("Clean/remove files in folder: {}".format(path))
343
+ self.log.info("Clean/remove files in folder: {}".format(path))
344
344
  try:
345
345
  os.stat(path) # TEMP workaround mpremote listdir bug -
346
346
  items = os.listdir(path)
@@ -360,9 +360,9 @@ class Stubber:
360
360
 
361
361
  def report(self, filename: str = "modules.json"):
362
362
  "create json with list of exported modules"
363
- self._log.info("Created stubs for {} modules on board {}\nPath: {}".format(len(self._report), self._fwid, self.path))
363
+ self.log.info("Created stubs for {} modules on board {}\nPath: {}".format(len(self._report), self._fwid, self.path))
364
364
  f_name = "{}/{}".format(self.path, filename)
365
- self._log.info("Report file: {}".format(f_name))
365
+ self.log.info("Report file: {}".format(f_name))
366
366
  gc.collect()
367
367
  try:
368
368
  # write json by node to reduce memory requirements
@@ -374,9 +374,9 @@ class Stubber:
374
374
  first = False
375
375
  self.write_json_end(f)
376
376
  used = self._start_free - gc.mem_free() # type: ignore
377
- self._log.info("Memory used: {0} Kb".format(used // 1024))
377
+ self.log.info("Memory used: {0} Kb".format(used // 1024))
378
378
  except OSError:
379
- self._log.error("Failed to create the report.")
379
+ self.log.error("Failed to create the report.")
380
380
 
381
381
  def write_json_header(self, f):
382
382
  f.write("{")
@@ -411,7 +411,7 @@ def ensure_folder(path: str):
411
411
  try:
412
412
  os.mkdir(p)
413
413
  except OSError as e2:
414
- _log.error("failed to create folder {}".format(p))
414
+ log.error("failed to create folder {}".format(p))
415
415
  raise e2
416
416
  # next level deep
417
417
  start = i + 1
@@ -662,7 +662,7 @@ def main():
662
662
 
663
663
  if __name__ == "__main__" or is_micropython():
664
664
  try:
665
- _log = logging.getLogger("stubber")
665
+ log = logging.getLogger("stubber")
666
666
  logging.basicConfig(level=logging.INFO)
667
667
  # logging.basicConfig(level=logging.DEBUG)
668
668
  except NameError: