Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Akashortstack authored Jun 16, 2024
2 parents c2b26f4 + e8542b8 commit bf5b05c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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, ...]:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/hosting/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions test/programs/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tempfile import TemporaryDirectory

import Generate
import Main


class TestGenerateMain(unittest.TestCase):
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_generate_absolute(self):
'--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)

Expand All @@ -67,7 +68,7 @@ def test_generate_relative(self):
'--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)

Expand All @@ -86,7 +87,7 @@ def test_generate_yaml(self):
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

Expand Down

0 comments on commit bf5b05c

Please sign in to comment.