micropython-stubber 1.16.3__py3-none-any.whl → 1.17.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.
- {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/METADATA +1 -1
- {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/RECORD +48 -49
- stubber/__init__.py +1 -1
- stubber/basicgit.py +11 -13
- stubber/board/createstubs.py +138 -97
- stubber/board/createstubs_db.py +211 -239
- stubber/board/createstubs_db_min.py +322 -844
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_lvgl.py +91 -137
- stubber/board/createstubs_lvgl_min.py +87 -129
- stubber/board/createstubs_lvgl_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +164 -199
- stubber/board/createstubs_mem_min.py +297 -791
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +286 -1009
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +1 -2
- stubber/codemod/_partials/__init__.py +1 -1
- stubber/codemod/_partials/db_main.py +90 -72
- stubber/codemod/_partials/modules_reader.py +29 -17
- stubber/codemod/board.py +2 -4
- stubber/codemod/enrich.py +1 -1
- stubber/commands/build_cmd.py +6 -4
- stubber/commands/get_docstubs_cmd.py +6 -11
- stubber/commands/get_frozen_cmd.py +6 -11
- stubber/commands/switch_cmd.py +6 -4
- stubber/freeze/freeze_manifest_2.py +2 -1
- stubber/freeze/get_frozen.py +28 -13
- stubber/minify.py +51 -38
- stubber/publish/candidates.py +15 -23
- stubber/publish/defaults.py +2 -2
- stubber/publish/merge_docstubs.py +5 -7
- stubber/publish/missing_class_methods.py +2 -2
- stubber/publish/pathnames.py +2 -2
- stubber/publish/publish.py +2 -1
- stubber/publish/stubpackage.py +20 -41
- stubber/rst/lookup.py +9 -7
- stubber/rst/reader.py +2 -1
- stubber/stubber.py +5 -6
- stubber/update_fallback.py +3 -1
- stubber/utils/__init__.py +1 -1
- stubber/utils/config.py +7 -9
- stubber/utils/repos.py +6 -5
- stubber/utils/versions.py +48 -7
- stubber/variants.py +3 -3
- stubber/board/logging.py +0 -99
- {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/WHEEL +0 -0
- {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/entry_points.txt +0 -0
stubber/board/createstubs_mem.py
CHANGED
@@ -9,12 +9,11 @@
|
|
9
9
|
- cross compilation, using mpy-cross,
|
10
10
|
to avoid the compilation step on the micropython device
|
11
11
|
|
12
|
-
This variant was generated from createstubs.py by micropython-stubber v1.
|
12
|
+
This variant was generated from createstubs.py by micropython-stubber v1.17.0
|
13
13
|
"""
|
14
14
|
# Copyright (c) 2019-2023 Jos Verlinde
|
15
15
|
|
16
16
|
import gc
|
17
|
-
import logging
|
18
17
|
import os
|
19
18
|
import sys
|
20
19
|
from time import sleep
|
@@ -34,26 +33,49 @@ try:
|
|
34
33
|
except ImportError:
|
35
34
|
from ucollections import OrderedDict # type: ignore
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
__version__ = "v1.17.0"
|
37
|
+
ENOENT = 2
|
38
|
+
_MAX_CLASS_LEVEL = 2 # Max class nesting
|
39
|
+
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
39
40
|
|
40
|
-
wdt = WDT()
|
41
41
|
|
42
|
-
|
42
|
+
# our own logging module to avoid dependency on and interfering with logging module
|
43
|
+
class logging:
|
44
|
+
# DEBUG = 10
|
45
|
+
INFO = 20
|
46
|
+
WARNING = 30
|
47
|
+
ERROR = 40
|
48
|
+
level = INFO
|
49
|
+
prnt = print
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
@staticmethod
|
52
|
+
def getLogger(name):
|
53
|
+
return logging()
|
47
54
|
|
48
|
-
|
55
|
+
@classmethod
|
56
|
+
def basicConfig(cls, level):
|
57
|
+
cls.level = level
|
49
58
|
|
59
|
+
# def debug(self, msg):
|
60
|
+
# if self.level <= logging.DEBUG:
|
61
|
+
# self.prnt("DEBUG :", msg)
|
50
62
|
|
51
|
-
|
63
|
+
def info(self, msg):
|
64
|
+
if self.level <= logging.INFO:
|
65
|
+
self.prnt("INFO :", msg)
|
52
66
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
67
|
+
def warning(self, msg):
|
68
|
+
if self.level <= logging.WARNING:
|
69
|
+
self.prnt("WARN :", msg)
|
70
|
+
|
71
|
+
def error(self, msg):
|
72
|
+
if self.level <= logging.ERROR:
|
73
|
+
self.prnt("ERROR :", msg)
|
74
|
+
|
75
|
+
|
76
|
+
log = logging.getLogger("stubber")
|
77
|
+
logging.basicConfig(level=logging.INFO)
|
78
|
+
# logging.basicConfig(level=logging.DEBUG)
|
57
79
|
|
58
80
|
|
59
81
|
class Stubber:
|
@@ -65,13 +87,10 @@ class Stubber:
|
|
65
87
|
raise NotImplementedError("MicroPython 1.13.0 cannot be stubbed")
|
66
88
|
except AttributeError:
|
67
89
|
pass
|
68
|
-
self.log = logging.getLogger("stubber")
|
69
|
-
self._report = [] # type: list[str]
|
70
90
|
self.info = _info()
|
71
|
-
|
72
|
-
|
91
|
+
log.info("Port: {}".format(self.info["port"]))
|
92
|
+
log.info("Board: {}".format(self.info["board"]))
|
73
93
|
gc.collect()
|
74
|
-
wdt.feed()
|
75
94
|
if firmware_id:
|
76
95
|
self._fwid = firmware_id.lower()
|
77
96
|
else:
|
@@ -88,11 +107,11 @@ class Stubber:
|
|
88
107
|
path = get_root()
|
89
108
|
|
90
109
|
self.path = "{}/stubs/{}".format(path, self.flat_fwid).replace("//", "/")
|
91
|
-
|
110
|
+
# log.debug(self.path)
|
92
111
|
try:
|
93
112
|
ensure_folder(path + "/")
|
94
113
|
except OSError:
|
95
|
-
|
114
|
+
log.error("error creating stub folder {}".format(path))
|
96
115
|
self.problematic = [
|
97
116
|
"upip",
|
98
117
|
"upysh",
|
@@ -111,21 +130,23 @@ class Stubber:
|
|
111
130
|
]
|
112
131
|
# there is no option to discover modules from micropython, list is read from an external file.
|
113
132
|
self.modules = [] # type: list[str]
|
133
|
+
self._json_name = None
|
134
|
+
self._json_first = False
|
114
135
|
|
115
136
|
def get_obj_attributes(self, item_instance: object):
|
116
137
|
"extract information of the objects members and attributes"
|
117
138
|
# name_, repr_(value), type as text, item_instance
|
118
139
|
_result = []
|
119
140
|
_errors = []
|
120
|
-
|
141
|
+
# log.debug("get attributes {} {}".format(repr(item_instance), item_instance))
|
121
142
|
for name in dir(item_instance):
|
122
|
-
if name.startswith("
|
143
|
+
if name.startswith("__") and not name in self.modules:
|
123
144
|
continue
|
124
|
-
|
145
|
+
# log.debug("get attribute {}".format(name))
|
125
146
|
try:
|
126
147
|
val = getattr(item_instance, name)
|
127
148
|
# name , item_repr(value) , type as text, item_instance, order
|
128
|
-
|
149
|
+
# log.debug("attribute {}:{}".format(name, val))
|
129
150
|
try:
|
130
151
|
type_text = repr(type(val)).split("'")[1]
|
131
152
|
except IndexError:
|
@@ -158,22 +179,23 @@ class Stubber:
|
|
158
179
|
|
159
180
|
def create_all_stubs(self):
|
160
181
|
"Create stubs for all configured modules"
|
161
|
-
|
182
|
+
log.info("Start micropython-stubber {} on {}".format(__version__, self._fwid))
|
183
|
+
self.report_start()
|
162
184
|
gc.collect()
|
163
185
|
for module_name in self.modules:
|
164
186
|
self.create_one_stub(module_name)
|
165
|
-
self.
|
187
|
+
self.report_end()
|
188
|
+
log.info("Finally done")
|
166
189
|
|
167
190
|
def create_one_stub(self, module_name: str):
|
168
|
-
wdt.feed()
|
169
191
|
if module_name in self.problematic:
|
170
|
-
|
192
|
+
log.warning("Skip module: {:<25} : Known problematic".format(module_name))
|
171
193
|
return False
|
172
194
|
if module_name in self.excluded:
|
173
|
-
|
195
|
+
log.warning("Skip module: {:<25} : Excluded".format(module_name))
|
174
196
|
return False
|
175
197
|
|
176
|
-
file_name = "{}/{}.
|
198
|
+
file_name = "{}/{}.pyi".format(self.path, module_name.replace(".", "/"))
|
177
199
|
gc.collect()
|
178
200
|
result = False
|
179
201
|
try:
|
@@ -188,10 +210,10 @@ class Stubber:
|
|
188
210
|
|
189
211
|
Args:
|
190
212
|
- module_name (str): name of the module to document. This module will be imported.
|
191
|
-
- file_name (Optional[str]): the 'path/filename.
|
213
|
+
- file_name (Optional[str]): the 'path/filename.pyi' to write to. If omitted will be created based on the module name.
|
192
214
|
"""
|
193
215
|
if file_name is None:
|
194
|
-
fname = module_name.replace(".", "_") + ".
|
216
|
+
fname = module_name.replace(".", "_") + ".pyi"
|
195
217
|
file_name = self.path + "/" + fname
|
196
218
|
else:
|
197
219
|
fname = file_name.split("/")[-1]
|
@@ -205,10 +227,10 @@ class Stubber:
|
|
205
227
|
try:
|
206
228
|
new_module = __import__(module_name, None, None, ("*"))
|
207
229
|
m1 = gc.mem_free() # type: ignore
|
208
|
-
|
230
|
+
log.info("Stub module: {:<25} to file: {:<70} mem:{:>5}".format(module_name, fname, m1))
|
209
231
|
|
210
232
|
except ImportError:
|
211
|
-
|
233
|
+
# log.debug("Skip module: {:<25} {:<79}".format(module_name, "Module not found."))
|
212
234
|
return False
|
213
235
|
|
214
236
|
# Start a new file
|
@@ -218,22 +240,18 @@ class Stubber:
|
|
218
240
|
info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
|
219
241
|
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
|
220
242
|
fp.write(s)
|
221
|
-
fp.write("from __future__ import annotations\nfrom typing import Any\nfrom _typeshed import Incomplete\n\n")
|
243
|
+
fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
|
222
244
|
self.write_object_stub(fp, new_module, module_name, "")
|
223
245
|
|
224
|
-
self.
|
246
|
+
self.report_add(module_name, file_name)
|
225
247
|
|
226
248
|
if module_name not in {"os", "sys", "logging", "gc"}:
|
227
249
|
# try to unload the module unless we use it
|
228
250
|
try:
|
229
251
|
del new_module
|
230
252
|
except (OSError, KeyError): # lgtm [py/unreachable-statement]
|
231
|
-
|
232
|
-
#
|
233
|
-
# try:
|
234
|
-
# del sys.modules[module_name]
|
235
|
-
# except KeyError:
|
236
|
-
# self.log.warning("could not del sys.modules[{}]".format(module_name))
|
253
|
+
log.warning("could not del new_module")
|
254
|
+
# do not try to delete from sys.modules - most times it does not work anyway
|
237
255
|
gc.collect()
|
238
256
|
return True
|
239
257
|
|
@@ -241,14 +259,14 @@ class Stubber:
|
|
241
259
|
"Write a module/object stub to an open file. Can be called recursive."
|
242
260
|
gc.collect()
|
243
261
|
if object_expr in self.problematic:
|
244
|
-
|
262
|
+
log.warning("SKIPPING problematic module:{}".format(object_expr))
|
245
263
|
return
|
246
264
|
|
247
|
-
#
|
265
|
+
# # log.debug("DUMP : {}".format(object_expr))
|
248
266
|
items, errors = self.get_obj_attributes(object_expr)
|
249
267
|
|
250
268
|
if errors:
|
251
|
-
|
269
|
+
log.error(errors)
|
252
270
|
|
253
271
|
for item_name, item_repr, item_type_txt, item_instance, _ in items:
|
254
272
|
# name_, repr_(value), type as text, item_instance, order
|
@@ -256,7 +274,7 @@ class Stubber:
|
|
256
274
|
# do not create stubs for these primitives
|
257
275
|
continue
|
258
276
|
if item_name[0].isdigit():
|
259
|
-
|
277
|
+
log.warning("NameError: invalid name {}".format(item_name))
|
260
278
|
continue
|
261
279
|
# Class expansion only on first 3 levels (bit of a hack)
|
262
280
|
if (
|
@@ -265,7 +283,7 @@ class Stubber:
|
|
265
283
|
# and not obj_name.endswith(".Pin")
|
266
284
|
# avoid expansion of Pin.cpu / Pin.board to avoid crashes on most platforms
|
267
285
|
):
|
268
|
-
|
286
|
+
# log.debug("{0}class {1}:".format(indent, item_name))
|
269
287
|
superclass = ""
|
270
288
|
is_exception = (
|
271
289
|
item_name.endswith("Exception")
|
@@ -288,7 +306,7 @@ class Stubber:
|
|
288
306
|
# write classdef
|
289
307
|
fp.write(s)
|
290
308
|
# first write the class literals and methods
|
291
|
-
|
309
|
+
# log.debug("# recursion over class {0}".format(item_name))
|
292
310
|
self.write_object_stub(
|
293
311
|
fp,
|
294
312
|
item_instance,
|
@@ -302,7 +320,7 @@ class Stubber:
|
|
302
320
|
s += indent + " ...\n\n"
|
303
321
|
fp.write(s)
|
304
322
|
elif any(word in item_type_txt for word in ["method", "function", "closure"]):
|
305
|
-
|
323
|
+
# log.debug("# def {1} function/method/closure, type = '{0}'".format(item_type_txt, item_name))
|
306
324
|
# module Function or class method
|
307
325
|
# will accept any number of params
|
308
326
|
# return type Any/Incomplete
|
@@ -318,7 +336,7 @@ class Stubber:
|
|
318
336
|
s = "{}def {}({}*args, **kwargs) -> {}:\n".format(indent, item_name, first, ret)
|
319
337
|
s += indent + " ...\n\n"
|
320
338
|
fp.write(s)
|
321
|
-
|
339
|
+
# log.debug("\n" + s)
|
322
340
|
elif item_type_txt == "<class 'module'>":
|
323
341
|
# Skip imported modules
|
324
342
|
# fp.write("# import {}\n".format(item_name))
|
@@ -328,28 +346,32 @@ class Stubber:
|
|
328
346
|
t = item_type_txt[8:-2]
|
329
347
|
s = ""
|
330
348
|
|
331
|
-
if t in
|
349
|
+
if t in ("str", "int", "float", "bool", "bytearray", "bytes"):
|
332
350
|
# known type: use actual value
|
333
|
-
s = "{0}{1} = {2} # type: {3}\n".format(indent, item_name, item_repr, t)
|
334
|
-
|
351
|
+
# s = "{0}{1} = {2} # type: {3}\n".format(indent, item_name, item_repr, t)
|
352
|
+
s = "{0}{1}: {3} = {2}\n".format(indent, item_name, item_repr, t)
|
353
|
+
elif t in ("dict", "list", "tuple"):
|
335
354
|
# dict, list , tuple: use empty value
|
336
355
|
ev = {"dict": "{}", "list": "[]", "tuple": "()"}
|
337
|
-
s = "{0}{1} = {2} # type: {3}\n".format(indent, item_name, ev[t], t)
|
356
|
+
# s = "{0}{1} = {2} # type: {3}\n".format(indent, item_name, ev[t], t)
|
357
|
+
s = "{0}{1}: {3} = {2}\n".format(indent, item_name, ev[t], t)
|
338
358
|
else:
|
339
359
|
# something else
|
340
|
-
if t in
|
360
|
+
if t in ("object", "set", "frozenset", "Pin", "generator"): # "FileIO"
|
341
361
|
# https://docs.python.org/3/tutorial/classes.html#item_instance-objects
|
342
|
-
#
|
343
|
-
|
362
|
+
# use these types for the attribute
|
363
|
+
if t == "generator":
|
364
|
+
t = "Generator"
|
365
|
+
s = "{0}{1}: {2} ## = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
|
344
366
|
else:
|
345
367
|
# Requires Python 3.6 syntax, which is OK for the stubs/pyi
|
346
368
|
t = "Incomplete"
|
347
|
-
s = "{0}{1}
|
369
|
+
s = "{0}{1}: {2} ## {3} = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
|
348
370
|
fp.write(s)
|
349
|
-
|
371
|
+
# log.debug("\n" + s)
|
350
372
|
else:
|
351
373
|
# keep only the name
|
352
|
-
|
374
|
+
# log.debug("# all other, type = '{0}'".format(item_type_txt))
|
353
375
|
fp.write("# all other, type = '{0}'\n".format(item_type_txt))
|
354
376
|
|
355
377
|
fp.write(indent + item_name + " # type: Incomplete\n")
|
@@ -373,10 +395,9 @@ class Stubber:
|
|
373
395
|
|
374
396
|
def clean(self, path: str = None): # type: ignore
|
375
397
|
"Remove all files from the stub folder"
|
376
|
-
wdt.feed()
|
377
398
|
if path is None:
|
378
399
|
path = self.path
|
379
|
-
|
400
|
+
log.info("Clean/remove files in folder: {}".format(path))
|
380
401
|
try:
|
381
402
|
os.stat(path) # TEMP workaround mpremote listdir bug -
|
382
403
|
items = os.listdir(path)
|
@@ -394,42 +415,53 @@ class Stubber:
|
|
394
415
|
except OSError:
|
395
416
|
pass
|
396
417
|
|
397
|
-
def
|
398
|
-
"
|
399
|
-
|
400
|
-
self.
|
401
|
-
|
402
|
-
self.
|
418
|
+
def report_start(self, filename: str = "modules.json"):
|
419
|
+
"""Start a report of the modules that have been stubbed
|
420
|
+
"create json with list of exported modules"""
|
421
|
+
self._json_name = "{}/{}".format(self.path, filename)
|
422
|
+
self._json_first = True
|
423
|
+
ensure_folder(self._json_name)
|
424
|
+
log.info("Report file: {}".format(self._json_name))
|
403
425
|
gc.collect()
|
404
426
|
try:
|
405
427
|
# write json by node to reduce memory requirements
|
406
|
-
with open(
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
self.
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
428
|
+
with open(self._json_name, "w") as f:
|
429
|
+
f.write("{")
|
430
|
+
f.write(dumps({"firmware": self.info})[1:-1])
|
431
|
+
f.write(",\n")
|
432
|
+
f.write(dumps({"stubber": {"version": __version__}, "stubtype": "firmware"})[1:-1])
|
433
|
+
f.write(",\n")
|
434
|
+
f.write('"modules" :[\n')
|
435
|
+
|
436
|
+
except OSError as e:
|
437
|
+
log.error("Failed to create the report.")
|
438
|
+
self._json_name = None
|
439
|
+
raise e
|
440
|
+
|
441
|
+
def report_add(self, module_name: str, stub_file: str):
|
442
|
+
"Add a module to the report"
|
443
|
+
# write json by node to reduce memory requirements
|
444
|
+
if not self._json_name:
|
445
|
+
raise Exception("No report file")
|
446
|
+
try:
|
447
|
+
with open(self._json_name, "a") as f:
|
448
|
+
if not self._json_first:
|
449
|
+
f.write(",\n")
|
450
|
+
else:
|
451
|
+
self._json_first = False
|
452
|
+
line = '{{"module": "{}", "file": "{}"}}'.format(module_name, stub_file.replace("\\", "/"))
|
453
|
+
f.write(line)
|
425
454
|
|
426
|
-
|
427
|
-
|
428
|
-
f.write(",\n")
|
429
|
-
f.write(n)
|
455
|
+
except OSError:
|
456
|
+
log.error("Failed to create the report.")
|
430
457
|
|
431
|
-
def
|
432
|
-
|
458
|
+
def report_end(self):
|
459
|
+
if not self._json_name:
|
460
|
+
raise Exception("No report file")
|
461
|
+
with open(self._json_name, "a") as f:
|
462
|
+
f.write("\n]}")
|
463
|
+
# is used as sucess indicator
|
464
|
+
log.info("Path: {}".format(self.path))
|
433
465
|
|
434
466
|
|
435
467
|
def ensure_folder(path: str):
|
@@ -475,7 +507,7 @@ def _build(s):
|
|
475
507
|
def _info(): # type:() -> dict[str, str]
|
476
508
|
info = OrderedDict(
|
477
509
|
{
|
478
|
-
"family": sys.implementation.name,
|
510
|
+
"family": sys.implementation.name, # type: ignore
|
479
511
|
"version": "",
|
480
512
|
"build": "",
|
481
513
|
"ver": "",
|
@@ -503,9 +535,9 @@ def _info(): # type:() -> dict[str, str]
|
|
503
535
|
info["board"] = _machine
|
504
536
|
info["cpu"] = _machine.split("with")[-1].strip()
|
505
537
|
info["mpy"] = (
|
506
|
-
sys.implementation._mpy
|
538
|
+
sys.implementation._mpy # type: ignore
|
507
539
|
if "_mpy" in dir(sys.implementation)
|
508
|
-
else sys.implementation.mpy
|
540
|
+
else sys.implementation.mpy # type: ignore
|
509
541
|
if "mpy" in dir(sys.implementation)
|
510
542
|
else ""
|
511
543
|
)
|
@@ -599,79 +631,16 @@ def version_str(version: tuple): # -> str:
|
|
599
631
|
return v_str
|
600
632
|
|
601
633
|
|
602
|
-
def
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
info["board"] = data.strip()
|
613
|
-
found = True
|
614
|
-
break
|
615
|
-
if not found:
|
616
|
-
print("Board not found, guessing board name")
|
617
|
-
descr = ""
|
618
|
-
# descr = desc or info["board"].strip()
|
619
|
-
# if "with " + info["cpu"].upper() in descr:
|
620
|
-
# # remove the with cpu part
|
621
|
-
# descr = descr.split("with " + info["cpu"].upper())[0].strip()
|
622
|
-
info["board"] = descr
|
623
|
-
|
624
|
-
|
625
|
-
# def read_boardname(info, desc: str = ""):
|
626
|
-
# wdt.feed()
|
627
|
-
# # print("look up the board name in the file", filename)
|
628
|
-
# if file_exists(filename):
|
629
|
-
# descr = desc or info["board"].strip()
|
630
|
-
# pos = descr.rfind(" with")
|
631
|
-
# if pos != -1:
|
632
|
-
# short_descr = descr[:pos].strip()
|
633
|
-
# else:
|
634
|
-
# short_descr = ""
|
635
|
-
# print("searching info file: {} for: '{}' or '{}'".format(filename, descr, short_descr))
|
636
|
-
# if find_board(info, descr, filename, short_descr):
|
637
|
-
# found = True
|
638
|
-
# break
|
639
|
-
# if not found:
|
640
|
-
# print("Board not found, guessing board name")
|
641
|
-
# descr = desc or info["board"].strip()
|
642
|
-
# if "with " + info["cpu"].upper() in descr:
|
643
|
-
# # remove the with cpu part
|
644
|
-
# descr = descr.split("with " + info["cpu"].upper())[0].strip()
|
645
|
-
# info["board"] = descr
|
646
|
-
# info["board"] = info["board"].replace(" ", "_")
|
647
|
-
# gc.collect()
|
648
|
-
|
649
|
-
|
650
|
-
# def find_board(info: dict, descr: str, filename: str, short_descr: str):
|
651
|
-
# "Find the board in the provided board_info.csv file"
|
652
|
-
# short_hit = ""
|
653
|
-
# with open(filename, "r") as file:
|
654
|
-
# # ugly code to make testable in python and micropython
|
655
|
-
# # TODO: This is VERY slow on micropython whith MPREMOTE mount on esp32 (2-3 minutes to read file)
|
656
|
-
# while 1:
|
657
|
-
# line = file.readline()
|
658
|
-
# if not line:
|
659
|
-
# break
|
660
|
-
# descr_, board_ = line.split(",")[0].strip(), line.split(",")[1].strip()
|
661
|
-
# if descr_ == descr:
|
662
|
-
# info["board"] = board_
|
663
|
-
# return True
|
664
|
-
# elif short_descr and descr_ == short_descr:
|
665
|
-
# if "with" in short_descr:
|
666
|
-
# # Good enough - no need to trawl the entire file
|
667
|
-
# info["board"] = board_
|
668
|
-
# return True
|
669
|
-
# # good enough if not found in the rest of the file (but slow)
|
670
|
-
# short_hit = board_
|
671
|
-
# if short_hit:
|
672
|
-
# info["board"] = short_hit
|
673
|
-
# return True
|
674
|
-
# return False
|
634
|
+
def get_boardname() -> str:
|
635
|
+
"Read the board name from the boardname.py file that may have been created upfront"
|
636
|
+
try:
|
637
|
+
from boardname import BOARDNAME # type: ignore
|
638
|
+
|
639
|
+
log.info("Found BOARDNAME: {}".format(BOARDNAME))
|
640
|
+
except ImportError:
|
641
|
+
log.warning("BOARDNAME not found")
|
642
|
+
BOARDNAME = ""
|
643
|
+
return BOARDNAME
|
675
644
|
|
676
645
|
|
677
646
|
def get_root() -> str: # sourcery skip: use-assigned-variable
|
@@ -724,10 +693,6 @@ def is_micropython() -> bool:
|
|
724
693
|
# pylint: disable=unused-variable,eval-used
|
725
694
|
try:
|
726
695
|
# either test should fail on micropython
|
727
|
-
# a) https://docs.micropython.org/en/latest/genrst/syntax.html#spaces
|
728
|
-
# Micropython : SyntaxError
|
729
|
-
# a = eval("1and 0") # lgtm [py/unused-local-variable]
|
730
|
-
# Eval blocks some minification aspects
|
731
696
|
|
732
697
|
# b) https://docs.micropython.org/en/latest/genrst/builtin_types.html#bytes-with-keywords-not-implemented
|
733
698
|
# Micropython: NotImplementedError
|
@@ -749,40 +714,40 @@ def main():
|
|
749
714
|
stubber.clean()
|
750
715
|
# Read stubs from modulelist in the current folder or in /libs
|
751
716
|
# fall back to default modules
|
752
|
-
stubber
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
717
|
+
def get_modulelist(stubber):
|
718
|
+
# new
|
719
|
+
gc.collect()
|
720
|
+
stubber.modules = [] # avoid duplicates
|
721
|
+
for p in LIBS:
|
722
|
+
fname = p + "/modulelist.txt"
|
723
|
+
if not file_exists(fname):
|
724
|
+
continue
|
725
|
+
with open(fname) as f:
|
726
|
+
# print("DEBUG: list of modules: " + p + "/modulelist.txt")
|
727
|
+
while True:
|
728
|
+
line = f.readline().strip()
|
729
|
+
if not line:
|
730
|
+
break
|
761
731
|
if len(line) > 0 and line[0] != "#":
|
762
732
|
stubber.modules.append(line)
|
763
|
-
|
764
|
-
|
765
|
-
print("Debug: Used memory to load modulelist.txt: " + str(_1 - gc.mem_free()) + " bytes") # type: ignore
|
733
|
+
gc.collect()
|
734
|
+
print("BREAK")
|
766
735
|
break
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
736
|
+
|
737
|
+
if not stubber.modules:
|
738
|
+
stubber.modules = ["micropython"]
|
739
|
+
# _log.warn("Could not find modulelist.txt, using default modules")
|
740
|
+
gc.collect()
|
741
|
+
|
742
|
+
stubber.modules = [] # avoid duplicates
|
743
|
+
get_modulelist(stubber)
|
772
744
|
|
773
745
|
gc.collect()
|
774
746
|
|
775
747
|
stubber.create_all_stubs()
|
776
|
-
stubber.report()
|
777
748
|
|
778
749
|
|
779
750
|
if __name__ == "__main__" or is_micropython():
|
780
|
-
try:
|
781
|
-
log = logging.getLogger("stubber")
|
782
|
-
logging.basicConfig(level=logging.INFO)
|
783
|
-
# logging.basicConfig(level=logging.DEBUG)
|
784
|
-
except NameError:
|
785
|
-
pass
|
786
751
|
if not file_exists("no_auto_stubber.txt"):
|
787
752
|
try:
|
788
753
|
gc.threshold(4 * 1024) # type: ignore
|