Refactor Platforms/WASI/__main__.py for lazy importing and future new subcommands#145404
Refactor Platforms/WASI/__main__.py for lazy importing and future new subcommands#145404brettcannon wants to merge 9 commits intopython:mainfrom
Platforms/WASI/__main__.py for lazy importing and future new subcommands#145404Conversation
Along the way, support lazy importing.
Ruff and isort issues:
Although this PR is using |
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
|
Now we have this duplicate: - id: ruff-check
name: Run Ruff (lint) on Tools/build/
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
files: ^Tools/build/
- id: ruff-check
name: Run Ruff (lint) on Tools/build/
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
files: ^Tools/build/ |
Correct! (The initial version did, but I realized backporting would not be fun with Maybe that will help define what to do with |
|
|
||
|
|
||
| @subdir(lambda context: CROSS_BUILD_DIR / host_triple(context), clean_ok=True) | ||
| def configure_wasi_python(context, working_dir): |
There was a problem hiding this comment.
In the original version of this function, we had a guard to check if the context.wasi_sdk_path was set before calling wasi_sdk_env. Was it intentionally removed here?
| "w", | ||
| encoding="utf-8", | ||
| delete=False, | ||
| dir=logdir, |
There was a problem hiding this comment.
This is not new but I just noticed that logdir is unbound when context.logdir is not None.
|
When you're done making the requested changes, leave the comment: |
Everything related to the
buildsubcommand & friends has been moved into a_buildmodule which is now lazily imported in__main__which now only handles argparse. This did require tweaking what the defaults are in the argument parser so that it didn't trigger needing to import_build. It also required changing dispatching to subcommands from a dict to amatchstatement to also avoid triggering the import of_build. As well, all imports in_buildthat are not needed for every subcommand has also been made lazy. Since neither PEP 8 or Ruff/Black have decided how to sort lazy imports, they are interleaved and imports are sorted by name as if thelazyaspect of the statement wasn't there.This work also sets things up so that any future subcommands can go into their own module and also be lazily imported into
__main__.