Skip to content

Commit

Permalink
Change the app.run and entry points to be more explicit to avoid the …
Browse files Browse the repository at this point in the history
…confusion (eg google-deepmind#14) of why the flags weren't being parsed.

PiperOrigin-RevId: 165287285
  • Loading branch information
tewalds committed Aug 15, 2017
1 parent 833d326 commit d0f58aa
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 24 deletions.
8 changes: 4 additions & 4 deletions pysc2/bin/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run_thread(agent_cls, map_name, visualize):
env.save_replay(agent_cls.__name__)


def _main(unused_argv):
def main(unused_argv):
"""Run an agent."""
stopwatch.sw.enabled = FLAGS.profile or FLAGS.trace
stopwatch.sw.trace = FLAGS.trace
Expand All @@ -104,9 +104,9 @@ def _main(unused_argv):
print(stopwatch.sw)


def main(): # Needed so setup.py scripts work.
app.really_start(_main)
def entry_point(): # Needed so setup.py scripts work.
app.run(main)


if __name__ == "__main__":
main()
app.run(main)
2 changes: 1 addition & 1 deletion pysc2/bin/gen_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ def main(unused_argv):


if __name__ == "__main__":
app.really_start(main)
app.run(main)
2 changes: 1 addition & 1 deletion pysc2/bin/map_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def main(unused_argv):


if __name__ == "__main__":
app.run()
app.run(main)
8 changes: 4 additions & 4 deletions pysc2/bin/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
flags.DEFINE_string("replay", None, "Name of a replay to show.")


def _main(unused_argv):
def main(unused_argv):
"""Run SC2 to play a game or a replay."""
stopwatch.sw.enabled = FLAGS.profile or FLAGS.trace
stopwatch.sw.trace = FLAGS.trace
Expand Down Expand Up @@ -175,9 +175,9 @@ def _main(unused_argv):
print(stopwatch.sw)


def main(): # Needed so setup.py scripts work.
app.really_start(_main)
def entry_point(): # Needed so setup.py scripts work.
app.run(main)


if __name__ == "__main__":
main()
app.run(main)
3 changes: 2 additions & 1 deletion pysc2/bin/replay_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,6 @@ def main(unused_argv):
stats_queue.put(None) # Tell the stats_thread to print and exit.
stats_thread.join()


if __name__ == "__main__":
app.run()
app.run(main)
9 changes: 4 additions & 5 deletions pysc2/bin/replay_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _replay_info(replay_path):
print(info)


def _main(argv=()):
def main(argv):
if not argv:
raise ValueError("No replay directory or path specified.")
if len(argv) > 2:
Expand All @@ -108,10 +108,9 @@ def _main(argv=()):
pass


def main(): # Needed so the setup.py scripts work.
app.really_start(_main)
def entry_point(): # Needed so the setup.py scripts work.
app.run(main)


if __name__ == "__main__":
main()

app.run(main)
3 changes: 2 additions & 1 deletion pysc2/bin/valid_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ def main(unused_argv):
print("Total base actions:", count)
print("Total possible actions (flattened):", flattened)


if __name__ == "__main__":
app.run()
app.run(main)
9 changes: 6 additions & 3 deletions pysc2/lib/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ def usage():
print(str(FLAGS))
sys.exit()

def run():
really_start(sys.modules["__main__"].main)

def really_start(main):
try:
argv = FLAGS(sys.argv)
Expand All @@ -52,3 +49,9 @@ def really_start(main):
if FLAGS.help:
usage()
sys.exit(main(argv))


# It's ok to override the apputils.app.run as it doesn't seem to do much more
# than call really_start anyway.
def run(main=None):
really_start(main or sys.modules["__main__"].main)
2 changes: 1 addition & 1 deletion pysc2/lib/basetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
TestCase = unittest.TestCase

def main():
app.really_start(lambda argv: unittest.main(argv=argv))
app.run(lambda argv: unittest.main(argv=argv))
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def read(fname):
],
entry_points={
'console_scripts': [
'pysc2_agent = pysc2.bin.agent:main',
'pysc2_play = pysc2.bin.play:main',
'pysc2_replay_info = pysc2.bin.replay_info:main',
'pysc2_agent = pysc2.bin.agent:entry_point',
'pysc2_play = pysc2.bin.play:entry_point',
'pysc2_replay_info = pysc2.bin.replay_info:entry_point',
],
},
classifiers=[
Expand Down

0 comments on commit d0f58aa

Please sign in to comment.