Core: Use Better Practices Accessing Manifests (#5543)

* Close manifest files

* Name explicit encoding
This commit is contained in:
Nicholas Saylor
2025-10-14 19:09:05 -04:00
committed by GitHub
parent bdae7cd42c
commit 28c7a214dc
3 changed files with 6 additions and 3 deletions

View File

@@ -381,7 +381,8 @@ class BuildExeCommand(cx_Freeze.command.build_exe.build_exe):
file_name = os.path.split(os.path.dirname(worldtype.__file__))[1] file_name = os.path.split(os.path.dirname(worldtype.__file__))[1]
world_directory = self.libfolder / "worlds" / file_name world_directory = self.libfolder / "worlds" / file_name
if os.path.isfile(world_directory / "archipelago.json"): if os.path.isfile(world_directory / "archipelago.json"):
manifest = json.load(open(world_directory / "archipelago.json")) with open(os.path.join(world_directory, "archipelago.json"), mode="r", encoding="utf-8") as manifest_file:
manifest = json.load(manifest_file)
assert "game" in manifest, ( assert "game" in manifest, (
f"World directory {world_directory} has an archipelago.json manifest file, but it" f"World directory {world_directory} has an archipelago.json manifest file, but it"

View File

@@ -271,7 +271,8 @@ if not is_frozen():
file_name = os.path.split(os.path.dirname(worldtype.__file__))[1] file_name = os.path.split(os.path.dirname(worldtype.__file__))[1]
world_directory = os.path.join("worlds", file_name) world_directory = os.path.join("worlds", file_name)
if os.path.isfile(os.path.join(world_directory, "archipelago.json")): if os.path.isfile(os.path.join(world_directory, "archipelago.json")):
manifest = json.load(open(os.path.join(world_directory, "archipelago.json"))) with open(os.path.join(world_directory, "archipelago.json"), mode="r", encoding="utf-8") as manifest_file:
manifest = json.load(manifest_file)
assert "game" in manifest, ( assert "game" in manifest, (
f"World directory {world_directory} has an archipelago.json manifest file, but it" f"World directory {world_directory} has an archipelago.json manifest file, but it"

View File

@@ -122,7 +122,8 @@ for world_source in world_sources:
for dirpath, dirnames, filenames in os.walk(world_source.resolved_path): for dirpath, dirnames, filenames in os.walk(world_source.resolved_path):
for file in filenames: for file in filenames:
if file.endswith("archipelago.json"): if file.endswith("archipelago.json"):
manifest = json.load(open(os.path.join(dirpath, file), "r")) with open(os.path.join(dirpath, file), mode="r", encoding="utf-8") as manifest_file:
manifest = json.load(manifest_file)
break break
if manifest: if manifest:
break break