Skip to content

Commit dee7190

Browse files
committed
manifestfile.py: Update manifestprocessing to allow author in manifest
Signed-off-by: Jos Verlinde <[email protected]>
1 parent 7594349 commit dee7190

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

src/stubber/tools/manifestfile.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@ def __init__(self):
8989
self.version = None
9090
self.description = None
9191
self.license = None
92+
self.author = None
9293

93-
def update(self, description=None, version=None, license=None):
94+
def update(self, description=None, version=None, license=None, author=None):
9495
if description:
9596
self.description = description
9697
if version:
9798
self.version = version
9899
if license:
99100
self.license = version
101+
if author:
102+
self.author = author
100103

101104

102105
# Turns a dict of options into a object with attributes used to turn the
@@ -167,6 +170,7 @@ def _manifest_globals(self, kwargs):
167170
"freeze_as_str": self.freeze_as_str,
168171
"freeze_as_mpy": self.freeze_as_mpy,
169172
"freeze_mpy": self.freeze_mpy,
173+
# "convert_path": self._resolve_path, # compatibility for old manifest files
170174
"options": IncludeOptions(**kwargs),
171175
}
172176

@@ -210,7 +214,11 @@ def _add_file(self, full_path, target_path, kind=KIND_AUTO, opt=None):
210214
raise ManifestFileError("Expected .py file")
211215
kind = KIND_COMPILE_AS_MPY
212216

213-
self._manifest_files.append(ManifestOutput(FILE_TYPE_LOCAL, full_path, target_path, timestamp, kind, self._metadata[-1], opt))
217+
self._manifest_files.append(
218+
ManifestOutput(
219+
FILE_TYPE_LOCAL, full_path, target_path, timestamp, kind, self._metadata[-1], opt
220+
)
221+
)
214222

215223
def _search(self, base_path, package_path, files, exts, kind, opt=None, strict=False):
216224
base_path = self._resolve_path(base_path)
@@ -244,7 +252,7 @@ def _search(self, base_path, package_path, files, exts, kind, opt=None, strict=F
244252
if base_path:
245253
os.chdir(prev_cwd) # type: ignore
246254

247-
def metadata(self, description=None, version=None, license=None):
255+
def metadata(self, description=None, version=None, license=None, author=None):
248256
"""
249257
From within a manifest file, use this to set the metadata for the
250258
package described by current manifest.
@@ -253,7 +261,7 @@ def metadata(self, description=None, version=None, license=None):
253261
to obtain the metadata for the top-level manifest file.
254262
"""
255263

256-
self._metadata[-1].update(description, version, license)
264+
self._metadata[-1].update(description, version, license, author)
257265
return self._metadata[-1]
258266

259267
def include(self, manifest_path, top_level=False, **kwargs):
@@ -303,7 +311,9 @@ def include(self, manifest_path, top_level=False, **kwargs):
303311
try:
304312
exec(f.read(), self._manifest_globals(kwargs))
305313
except Exception as er:
306-
raise ManifestFileError("Error in manifest file: {}: {}".format(manifest_path, er))
314+
raise ManifestFileError(
315+
"Error in manifest file: {}: {}".format(manifest_path, er)
316+
)
307317
os.chdir(prev_cwd)
308318
if not top_level:
309319
self._metadata.pop()
@@ -322,12 +332,14 @@ def require(self, name, version=None, unix_ffi=False, **kwargs):
322332
lib_dirs = ["unix-ffi"] + lib_dirs
323333

324334
for lib_dir in lib_dirs:
325-
for manifest_path in glob.glob(
326-
os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir, "**", name, "manifest.py"),
327-
recursive=True,
335+
# Search for {lib_dir}/**/{name}/manifest.py.
336+
for root, dirnames, filenames in os.walk(
337+
os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir)
328338
):
329-
self.include(manifest_path, **kwargs)
330-
return
339+
if os.path.basename(root) == name and "manifest.py" in filenames:
340+
self.include(root, **kwargs)
341+
return
342+
331343
raise ValueError("Library not found in local micropython-lib: {}".format(name))
332344
else:
333345
# TODO: HTTP request to obtain URLs from manifest.json.
@@ -406,28 +418,37 @@ def freeze(self, path, script=None, opt=None):
406418
`opt` is the optimisation level to pass to mpy-cross when compiling .py
407419
to .mpy.
408420
"""
409-
self._freeze_internal(path, script, exts=(".py", ".mpy"), kind=KIND_FREEZE_AUTO, opt=opt)
421+
self._freeze_internal(
422+
path,
423+
script,
424+
exts=(
425+
".py",
426+
".mpy",
427+
),
428+
kind=KIND_FREEZE_AUTO,
429+
opt=opt,
430+
)
410431

411432
def freeze_as_str(self, path):
412433
"""
413434
Freeze the given `path` and all .py scripts within it as a string,
414435
which will be compiled upon import.
415436
"""
416-
self._search(path, None, None, exts=(".py"), kind=KIND_FREEZE_AS_STR)
437+
self._search(path, None, None, exts=(".py",), kind=KIND_FREEZE_AS_STR)
417438

418439
def freeze_as_mpy(self, path, script=None, opt=None):
419440
"""
420441
Freeze the input (see above) by first compiling the .py scripts to
421442
.mpy files, then freezing the resulting .mpy files.
422443
"""
423-
self._freeze_internal(path, script, exts=(".py"), kind=KIND_FREEZE_AS_MPY, opt=opt)
444+
self._freeze_internal(path, script, exts=(".py",), kind=KIND_FREEZE_AS_MPY, opt=opt)
424445

425446
def freeze_mpy(self, path, script=None, opt=None):
426447
"""
427448
Freeze the input (see above), which must be .mpy files that are
428449
frozen directly.
429450
"""
430-
self._freeze_internal(path, script, exts=(".mpy"), kind=KIND_FREEZE_MPY, opt=opt)
451+
self._freeze_internal(path, script, exts=(".mpy",), kind=KIND_FREEZE_MPY, opt=opt)
431452

432453

433454
# Generate a temporary file with a line appended to the end that adds __version__.

0 commit comments

Comments
 (0)