From ac6f2d1e12172d6e3516940c142df062d6bddbd6 Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Mon, 23 Sep 2024 06:42:31 -0700 Subject: [PATCH] lpar: delete buck1 code Summary: main_runner is always passed in by buck2 Reviewed By: itamaro Differential Revision: D63089502 fbshipit-source-id: 2f49c96ff72ffefef9c153fc9c6a64570da604c0 --- python/tools/make_par/__run_lpar_main__.py | 56 +++------------------- 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/python/tools/make_par/__run_lpar_main__.py b/python/tools/make_par/__run_lpar_main__.py index 8605c5ef3..1a05d95ab 100644 --- a/python/tools/make_par/__run_lpar_main__.py +++ b/python/tools/make_par/__run_lpar_main__.py @@ -8,14 +8,8 @@ # pyre-strict -# -# Put everything inside an __invoke_main() function. -# This way anything we define won't pollute globals(), since runpy -# will propagate our globals() as to the user's main module. -# pyre-fixme[3]: Return type must be annotated. -def __invoke_main(): +def __invoke_main() -> None: import os - import runpy import sys module = os.getenv("FB_PAR_MAIN_MODULE") @@ -24,50 +18,14 @@ def __invoke_main(): sys.argv[0] = os.getenv("FB_LPAR_INVOKED_NAME", sys.argv[0]) del sys.path[0] - main_runner_module = os.getenv("FB_PAR_MAIN_RUNNER_MODULE") - main_runner_function = os.getenv("FB_PAR_MAIN_RUNNER_FUNCTION") - - if main_runner_module and main_runner_function: - from importlib import import_module - - mod = import_module(main_runner_module) - run_as_main = getattr(mod, main_runner_function) - run_as_main(module, main_function) - return - - #### BUCK1-ONLY CODE FOLLOWS #### - - # Allow users to decorate the main module. In normal Python invocations - # this can be done by prefixing the arguments with `-m decoratingmodule`. - # It's not that easy for par files. The startup script sets up `sys.path` - # from within the Python interpreter. Enable decorating the main module - # after `sys.path` has been setup by setting the PAR_MAIN_OVERRIDE - # environment variable. - decorate_main_module = os.environ.pop("PAR_MAIN_OVERRIDE", None) - if decorate_main_module: - # Pass the original main module as environment variable for the process. - # Allowing the decorating module to pick it up. - # pyre-fixme[6]: For 2nd argument expected `str` but got `Optional[str]`. - os.environ["PAR_MAIN_ORIGINAL"] = module - module = decorate_main_module - - if main_function: - assert module - from importlib import import_module - - mod = import_module(module) - main = getattr(mod, main_function) - # This is normally done by `runpy._run_module_as_main`, and is - # important to make multiprocessing work - sys.modules["__main__"] = mod - main() - return + main_runner_module = os.environ["FB_PAR_MAIN_RUNNER_MODULE"] + main_runner_function = os.environ["FB_PAR_MAIN_RUNNER_FUNCTION"] - del os - del sys + from importlib import import_module - # pyre-fixme[16]: Module `runpy` has no attribute `_run_module_as_main`. - runpy._run_module_as_main(module, False) + mod = import_module(main_runner_module) + run_as_main = getattr(mod, main_runner_function) + run_as_main(module, main_function) __invoke_main()