Skip to content

Commit

Permalink
fix: ensure scenario dir exists. partial change to pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioseel committed Nov 20, 2024
1 parent 4a6249f commit be5b12b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
3 changes: 0 additions & 3 deletions doom_creator/compile_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import os
import sys
import warnings
from pathlib import Path

from doom_creator.util.config import load
from doom_creator.util.directories import Directories
Expand Down Expand Up @@ -108,8 +107,6 @@ def main():

dirs = Directories(args.out_dir)

Path(dirs.CACHE_DIR).mkdir(parents=True, exist_ok=True)

cfg = load(args.yamls, dirs.SCENARIO_YAML_DIR)
# Check preload flag
do_load, do_make, do_list = args.preload, len(args.yamls) > 0, args.list_yamls
Expand Down
44 changes: 22 additions & 22 deletions doom_creator/util/directories.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import os.path as osp
from dataclasses import dataclass
from typing import Optional
from pathlib import Path


@dataclass
class Directories:
cache_dir: str = "cache"
resource_dir: str = osp.join("doom_creator", "resources") # noqa: RUF009 as this is not really a dynamical call
scenario_out_dir: Optional[str] = None
build_dir: Optional[str] = None
textures_dir: Optional[str] = None
assets_dir: Optional[str] = None
scenario_yaml_dir: Optional[str] = None
dataset_dir: Optional[str] = None
cache_dir: Path = "cache"
resource_dir: Path = Path("doom_creator", "resources")
scenario_out_dir: Optional[Path] = None
build_dir: Optional[Path] = None
textures_dir: Optional[Path] = None
assets_dir: Optional[Path] = None
scenario_yaml_dir: Optional[Path] = None
dataset_dir: Optional[Path] = None

def __post_init__(self):
self.CACHE_DIR = self.cache_dir
self.SCENARIO_OUT_DIR = (
osp.join(self.CACHE_DIR, "scenarios")
self.CACHE_DIR: Path = self.cache_dir
self.SCENARIO_OUT_DIR: Path = (
Path(self.CACHE_DIR, "scenarios")
if self.scenario_out_dir is None
else self.scenario_out_dir
)
self.BUILD_DIR = (
osp.join(self.SCENARIO_OUT_DIR, "build")
self.BUILD_DIR: Path = (
Path(self.SCENARIO_OUT_DIR, "build")
if self.build_dir is None
else self.build_dir
)
self.TEXTURES_DIR = (
osp.join(self.CACHE_DIR, "textures")
self.TEXTURES_DIR: Path = (
Path(self.CACHE_DIR, "textures")
if self.textures_dir is None
else self.textures_dir
)
self.RESOURCE_DIR = self.resource_dir
self.ASSETS_DIR = (
osp.join(self.RESOURCE_DIR, "assets")
self.RESOURCE_DIR: Path = self.resource_dir
self.ASSETS_DIR: Path = (
Path(self.RESOURCE_DIR, "assets")
if self.assets_dir is None
else self.assets_dir
)
self.SCENARIO_YAML_DIR = (
osp.join(self.RESOURCE_DIR, "config")
self.SCENARIO_YAML_DIR: Path = (
Path(self.RESOURCE_DIR, "config")
if self.scenario_yaml_dir is None
else self.scenario_yaml_dir
)
self.DATASET_DIR = (
self.DATASET_DIR: Path = (
self.TEXTURES_DIR if self.dataset_dir is None else self.dataset_dir
)
1 change: 1 addition & 0 deletions doom_creator/util/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def make_scenario(
scenario_name: Optional[str] = None,
):
# Create Zip for output
directories.SCENARIO_OUT_DIR.mkdir(parents=True, exist_ok=True)
out_file = osp.join(directories.SCENARIO_OUT_DIR, scenario_name) + ".zip"
if osp.exists(out_file):
os.remove(out_file)
Expand Down
Empty file modified tests/ci/build_scenario.sh
100644 → 100755
Empty file.

0 comments on commit be5b12b

Please sign in to comment.