Windows path fixes (#129)

* Change uses of os.path to use Pathlib

* Add return types and type hints

* Add more docstrings

* Add missing import to api_server
This commit is contained in:
2026-01-18 00:18:43 -06:00
committed by GitHub
parent ee9f44e4c4
commit 74dce5cc3d
15 changed files with 536 additions and 262 deletions

View File

@@ -1,4 +1,6 @@
import os
from pathlib import Path
import yaml
from src.utilities.misc_helper import current_system_os, copy_directory_contents
@@ -23,7 +25,7 @@ class Config:
with open(config_path, 'r') as ymlfile:
cfg = yaml.safe_load(ymlfile)
cls.upload_folder = os.path.expanduser(cfg.get('upload_folder', cls.upload_folder))
cls.upload_folder = str(Path(cfg.get('upload_folder', cls.upload_folder)).expanduser())
cls.update_engines_on_launch = cfg.get('update_engines_on_launch', cls.update_engines_on_launch)
cls.max_content_path = cfg.get('max_content_path', cls.max_content_path)
cls.server_log_level = cfg.get('server_log_level', cls.server_log_level)
@@ -37,14 +39,14 @@ class Config:
cls.download_timeout_seconds = cfg.get('download_timeout_seconds', cls.download_timeout_seconds)
@classmethod
def config_dir(cls):
def config_dir(cls) -> Path:
# Set up the config path
if current_system_os() == 'macos':
local_config_path = os.path.expanduser('~/Library/Application Support/Zordon')
local_config_path = Path('~/Library/Application Support/Zordon').expanduser()
elif current_system_os() == 'windows':
local_config_path = os.path.join(os.environ['APPDATA'], 'Zordon')
local_config_path = Path(os.environ['APPDATA']) / 'Zordon'
else:
local_config_path = os.path.expanduser('~/.config/Zordon')
local_config_path = Path('~/.config/Zordon').expanduser()
return local_config_path
@classmethod
@@ -61,10 +63,9 @@ class Config:
# Determine the template path
resource_environment_path = os.environ.get('RESOURCEPATH')
if resource_environment_path:
template_path = os.path.join(resource_environment_path, 'config')
template_path = Path(resource_environment_path) / 'config'
else:
template_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'config')
template_path = Path(__file__).resolve().parents[2] / 'config'
# Copy contents from the template to the local configuration directory
copy_directory_contents(template_path, local_config_dir)