Generate: split ERmain out of main (#3515)
This commit is contained in:
parent
2a11d610b6
commit
e8542b8acd
|
@ -65,7 +65,7 @@ def get_seed_name(random_source) -> str:
|
|||
return f"{random_source.randint(0, pow(10, seeddigits) - 1)}".zfill(seeddigits)
|
||||
|
||||
|
||||
def main(args=None):
|
||||
def main(args=None) -> Tuple[argparse.Namespace, int]:
|
||||
# __name__ == "__main__" check so unittests that already imported worlds don't trip this.
|
||||
if __name__ == "__main__" and "worlds" in sys.modules:
|
||||
raise Exception("Worlds system should not be loaded before logging init.")
|
||||
|
@ -237,8 +237,7 @@ def main(args=None):
|
|||
with open(os.path.join(args.outputpath if args.outputpath else ".", f"generate_{seed_name}.yaml"), "wt") as f:
|
||||
yaml.dump(important, f)
|
||||
|
||||
from Main import main as ERmain
|
||||
return ERmain(erargs, seed)
|
||||
return erargs, seed
|
||||
|
||||
|
||||
def read_weights_yamls(path) -> Tuple[Any, ...]:
|
||||
|
@ -547,7 +546,9 @@ def roll_alttp_settings(ret: argparse.Namespace, weights):
|
|||
if __name__ == '__main__':
|
||||
import atexit
|
||||
confirmation = atexit.register(input, "Press enter to close.")
|
||||
multiworld = main()
|
||||
erargs, seed = main()
|
||||
from Main import main as ERmain
|
||||
multiworld = ERmain(erargs, seed)
|
||||
if __debug__:
|
||||
import gc
|
||||
import sys
|
||||
|
|
|
@ -26,6 +26,7 @@ def _generate_local_inner(games: Iterable[str],
|
|||
with TemporaryDirectory() as players_dir:
|
||||
with TemporaryDirectory() as output_dir:
|
||||
import Generate
|
||||
import Main
|
||||
|
||||
for n, game in enumerate(games, 1):
|
||||
player_path = Path(players_dir) / f"{n}.yaml"
|
||||
|
@ -42,7 +43,7 @@ def _generate_local_inner(games: Iterable[str],
|
|||
sys.argv = [sys.argv[0], "--seed", str(hash(tuple(games))),
|
||||
"--player_files_path", players_dir,
|
||||
"--outputpath", output_dir]
|
||||
Generate.main()
|
||||
Main.main(*Generate.main())
|
||||
output_files = list(Path(output_dir).glob('*.zip'))
|
||||
assert len(output_files) == 1
|
||||
final_file = dest / output_files[0].name
|
||||
|
|
|
@ -9,6 +9,7 @@ from pathlib import Path
|
|||
from tempfile import TemporaryDirectory
|
||||
|
||||
import Generate
|
||||
import Main
|
||||
|
||||
|
||||
class TestGenerateMain(unittest.TestCase):
|
||||
|
@ -58,7 +59,7 @@ class TestGenerateMain(unittest.TestCase):
|
|||
'--player_files_path', str(self.abs_input_dir),
|
||||
'--outputpath', self.output_tempdir.name]
|
||||
print(f'Testing Generate.py {sys.argv} in {os.getcwd()}')
|
||||
Generate.main()
|
||||
Main.main(*Generate.main())
|
||||
|
||||
self.assertOutput(self.output_tempdir.name)
|
||||
|
||||
|
@ -67,7 +68,7 @@ class TestGenerateMain(unittest.TestCase):
|
|||
'--player_files_path', str(self.rel_input_dir),
|
||||
'--outputpath', self.output_tempdir.name]
|
||||
print(f'Testing Generate.py {sys.argv} in {os.getcwd()}')
|
||||
Generate.main()
|
||||
Main.main(*Generate.main())
|
||||
|
||||
self.assertOutput(self.output_tempdir.name)
|
||||
|
||||
|
@ -86,7 +87,7 @@ class TestGenerateMain(unittest.TestCase):
|
|||
sys.argv = [sys.argv[0], '--seed', '0',
|
||||
'--outputpath', self.output_tempdir.name]
|
||||
print(f'Testing Generate.py {sys.argv} in {os.getcwd()}, player_files_path={self.yaml_input_dir}')
|
||||
Generate.main()
|
||||
Main.main(*Generate.main())
|
||||
finally:
|
||||
user_path.cached_path = user_path_backup
|
||||
|
||||
|
|
Loading…
Reference in New Issue