Skip to content

Commit

Permalink
lpar: delete buck1 code
Browse files Browse the repository at this point in the history
Summary: main_runner is always passed in by buck2

Reviewed By: itamaro

Differential Revision: D63089502

fbshipit-source-id: 2f49c96ff72ffefef9c153fc9c6a64570da604c0
  • Loading branch information
zsol authored and facebook-github-bot committed Sep 23, 2024
1 parent 933a885 commit ac6f2d1
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions python/tools/make_par/__run_lpar_main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()

0 comments on commit ac6f2d1

Please sign in to comment.