From bc23f207cefed82172551288ebb8686ee2c512a3 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 11 Aug 2022 00:16:48 +1000 Subject: [PATCH] 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 --- tools/manifestfile.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/manifestfile.py b/tools/manifestfile.py index bf626c22b3..61560e4565 100644 --- a/tools/manifestfile.py +++ b/tools/manifestfile.py @@ -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.