🚧 Initial work on Steam source
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user