tools/manifestfile.py: Allow require() to specify unix packages.

By default, don't include micropython-lib/unix-ffi in the search.

If unix_ffi=True is passed to require(), then include unix-ffi and make it
take precedence over the other locations (e.g. python-stdlib).

This does two things:
 - Prevents non-unix builds from using unix-only packages.
 - Allows the unix build to optionally use a more full-featured (e.g. ffi)
   based package, even with the same name as one from e.g. stdlib.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
pull/8914/head
Jim Mussared 2022-08-11 00:16:48 +10:00
rodzic e9a28ce312
commit bc23f207ce
1 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -248,19 +248,28 @@ class ManifestFile:
)
os.chdir(prev_cwd)
def require(self, name, version=None, **kwargs):
def require(self, name, version=None, unix_ffi=False, **kwargs):
"""
Require a module by name from micropython-lib.
This is a shortcut for
Optionally specify unix_ffi=True to use a module from the unix-ffi directory.
"""
if self._path_vars["MPY_LIB_DIR"]:
for manifest_path in glob.glob(
os.path.join(self._path_vars["MPY_LIB_DIR"], "**", name, "manifest.py"),
recursive=True,
):
self.include(manifest_path, **kwargs)
return
lib_dirs = ["micropython", "python-stdlib", "python-ecosys"]
if unix_ffi:
# Search unix-ffi only if unix_ffi=True, and make unix-ffi modules
# take precedence.
lib_dirs = ["unix-ffi"] + lib_dirs
for lib_dir in lib_dirs:
for manifest_path in glob.glob(
os.path.join(
self._path_vars["MPY_LIB_DIR"], lib_dir, "**", name, "manifest.py"
),
recursive=True,
):
self.include(manifest_path, **kwargs)
return
raise ValueError("Library not found in local micropython-lib: {}".format(name))
else:
# TODO: HTTP request to obtain URLs from manifest.json.