From 6bb11e49a3d5b200769e804e5e74597bd375850f Mon Sep 17 00:00:00 2001 From: Maxim De Clercq Date: Wed, 19 Apr 2023 21:18:44 +0200 Subject: [PATCH] Add support for when cwd is outside the project E.g. Pycharm runs `/.../haldis/venv/bin/python /.../haldis/app/app.py` when no working directory is set. --- app/hlds/definitions.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/hlds/definitions.py b/app/hlds/definitions.py index 961d14b..7f6e0c1 100644 --- a/app/hlds/definitions.py +++ b/app/hlds/definitions.py @@ -1,7 +1,6 @@ # Import this class to load the standard HLDS definitions - import subprocess -from os import path +from pathlib import Path from typing import List from .models import Location @@ -12,10 +11,11 @@ __all__ = ["location_definitions", "location_definition_version"] # pylint: disable=invalid-name # TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674 -DATA_DIR = path.join(path.dirname(__file__), "..", "..", "menus") +ROOT_DIR = Path(__file__).parent.parent.parent +DATA_DIR = ROOT_DIR / "menus" -location_definitions: List[Location] = parse_all_directory(DATA_DIR) +location_definitions: List[Location] = parse_all_directory(str(DATA_DIR)) location_definitions.sort(key=lambda l: l.name) -proc = subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, check=True) +proc = subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, cwd=str(ROOT_DIR), check=True) location_definition_version = proc.stdout.decode().strip()