From 8a4dfe29c6be6e8e5532d3a72ab281634ab79e7e Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 25 Jan 2025 22:27:41 +0530 Subject: [PATCH] Add better explanation --- micropip/_vendored/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/micropip/_vendored/__init__.py b/micropip/_vendored/__init__.py index 55e8914..715c9f0 100644 --- a/micropip/_vendored/__init__.py +++ b/micropip/_vendored/__init__.py @@ -70,21 +70,32 @@ def _create_module(name, package_path=None): #################################################### # 1. First, handle any packages: these are directories with __init__.py. +# 2. Then, we load all the internal modules +# 3. Finally, we'll load all the regular modules (whatever is in the +# public API) +# +# While rudimentary, this order is important because the internal modules +# may depend on subpackages, and regular modules may depend on internal ones. +# +# For example, the metadata.py module imports from licenses, requirements, +# specifiers, and utils. +# +# Similarly, tags.py needs _manylinux and _musllinux to be available. + + for path in PACKAGING_PATH.glob("*/__init__.py"): package_name = path.parent.name module = _create_module(f"{package_name}/__init__", path) setattr(packaging_vendored, package_name, module) setattr(packaging_direct, package_name, module) -# 2. Then, we load all the internal modules internal_modules = [path.stem for path in PACKAGING_PATH.glob("_*.py")] for name in internal_modules: module = _create_module(name) setattr(packaging_vendored, name, module) setattr(packaging_direct, name, module) -# 3. Finally, we'll load all the regular modules (whatever is in the -# public API) + for path in PACKAGING_PATH.glob("*.py"): if path.stem == "__init__" or path.stem.startswith("_"): continue