8000 tools/manifestfile.py: Allow require() to specify unix packages. · micropython/micropython@22e0d71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22e0d71

Browse files
committed
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>
1 parent a2a6530 commit 22e0d71

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tools/manifestfile.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,28 @@ def include(self, manifest_path, **kwargs):
252252
)
253253
os.chdir(prev_cwd)
254254

255-
def require(self, name, **kwargs):
255+
def require(self, name, unix_ffi=False, **kwargs):
256256
"""
257257
Require a module by name from micropython-lib.
258258
259-
This is a shortcut for
259+
Optionally specify unix_ffi=True to use a module from the unix-ffi directory.
260260
"""
261261
if self._path_vars["MPY_LIB_DIR"]:
262-
for manifest_path in glob.glob(
263-
os.path.join(self._path_vars["MPY_LIB_DIR"], "**", name, "manifest.py"),
264-
recursive=True,
265-
):
266-
self.include(manifest_path, **kwargs)
267-
return
262+
lib_dirs = ["micropython", "python-stdlib", "python-ecosys"]
263+
if unix_ffi:
264+
# Search unix-ffi only if unix_ffi=True, and make unix-ffi modules
265+
# take precedence.
266+
lib_dirs = ["unix-ffi"] + lib_dirs
267+
268+
for lib_dir in lib_dirs:
269+
for manifest_path in glob.glob(
270+
os.path.join(
271+
self._path_vars["MPY_LIB_DIR"], lib_dir, "**", name, "manifest.py"
272+
),
273+
recursive=True,
274+
):
275+
self.include(manifest_path, **kwargs)
276+
return
268277
raise ValueError("Library not found in local micropython-lib: {}".format(name))
269278
else:
270279
# TODO: HTTP request to obtain URLs from manifest.json.

0 commit comments

Comments
 (0)
0