🚧 Initial work on Steam source

This commit is contained in:
GeoffreyCoulaud
2023-05-20 19:48:03 +02:00
parent 08c4b53cca
commit 604bcfb2e9
6 changed files with 233 additions and 15 deletions

View File

@@ -14,7 +14,7 @@ class MyClass():
"""
from pathlib import Path
from os import PathLike
from os import PathLike, environ
from functools import wraps
@@ -52,3 +52,21 @@ def replaced_by_schema_key(key: str): # Decorator builder
return wrapper
return decorator
def replaced_by_env_path(env_var_name: str, suffix: PathLike | None = None):
"""Replace the method's returned path with a path whose root is the env variable"""
def decorator(original_function): # Built decorator (closure)
@wraps(original_function)
def wrapper(*args, **kwargs): # func's override
try:
env_var = environ[env_var_name]
except KeyError:
return original_function(*args, **kwargs)
override = Path(env_var) / suffix
return replaced_by_path(override)(original_function)(*args, **kwargs)
return wrapper
return decorator