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

Skip to content

Commit bc23f20

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 e9a28ce commit bc23f20

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tools/manifestfile.py

Copy file name to clipboard
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,28 @@ def include(self, manifest_path, **kwargs):
248248
)
249249
os.chdir(prev_cwd)
250250

251-
def require(self, name, version=None, **kwargs):
251+
def require(self, name, version=None, unix_ffi=False, **kwargs):
252252
"""
253253
Require a module by name from micropython-lib.
254254
255-
This is a shortcut for
255+
Optionally specify unix_ffi=True to use a module from the unix-ffi directory.
256256
"""
257257
if self._path_vars["MPY_LIB_DIR"]:
258-
for manifest_path in glob.glob(
259-
os.path.join(self._path_vars["MPY_LIB_DIR"], "**", name, "manifest.py"),
260-
recursive=True,
261-
):
262-
self.include(manifest_path, **kwargs)
263-
return
258+
lib_dirs = ["micropython", "python-stdlib", "python-ecosys"]
259+
if unix_ffi:
260+
# Search unix-ffi only if unix_ffi=True, and make unix-ffi modules
261+
# take precedence.
262+
lib_dirs = ["unix-ffi"] + lib_dirs
263+
264+
for lib_dir in lib_dirs:
265+
for manifest_path in glob.glob(
266+
os.path.join(
267+
self._path_vars["MPY_LIB_DIR"], lib_dir, "**", name, "manifest.py"
268+
),
269+
recursive=True,
270+
):
271+
self.include(manifest_path, **kwargs)
272+
return
264273
raise ValueError(&qu 46EB ot;Library not found in local micropython-lib: {}".format(name))
265274
else:
266275
# TODO: HTTP request to obtain URLs from manifest.json.

0 commit comments

Comments
 (0)
0