Skip to content

Utilities API

Helper functions and utilities for EldenGym.

File Path Resolution

resolve_file_path

resolve_file_path(filepath, relative_to_package=True)

Resolve a file path relative to the package or as absolute path.

Parameters:

Name Type Description Default
filepath

str or Path, file path to resolve

required
relative_to_package

bool, if True resolves relative to eldengym package

True

Returns:

Name Type Description
Path

Resolved absolute path

Example

path = resolve_file_path("files/config.toml") print(path)

Source code in eldengym/utils.py
def resolve_file_path(filepath, relative_to_package=True):
    """
    Resolve a file path relative to the package or as absolute path.

    Args:
        filepath: str or Path, file path to resolve
        relative_to_package: bool, if True resolves relative to eldengym package

    Returns:
        Path: Resolved absolute path

    Example:
        >>> path = resolve_file_path("files/config.toml")
        >>> print(path)
    """
    path = Path(filepath)

    if path.is_absolute():
        return path

    if relative_to_package:
        # Resolve relative to eldengym package directory
        package_dir = Path(__file__).parent
        return (package_dir / path).resolve()

    return path.resolve()

Example

from eldengym.utils import resolve_file_path

# Resolve a file path relative to the package
config_path = resolve_file_path("files/Margit-v0/er_siphon_config.toml")
print(f"Resolved path: {config_path}")

# Works with absolute paths too
abs_path = resolve_file_path("/absolute/path/to/config.toml")
print(f"Absolute path: {abs_path}")

This utility ensures file paths work correctly whether: - EldenGym is installed as a package - Running from the project root - Using relative or absolute paths

Use Cases

Loading configuration files:

from eldengym.utils import resolve_file_path

# Resolve keybinds file
keybinds_path = resolve_file_path("files/Margit-v0/keybinds.json")

# Load the file
with open(keybinds_path, 'r') as f:
    keybinds = json.load(f)

Finding scenario files:

from eldengym.utils import resolve_file_path

# Get scenario directory
scenario_dir = resolve_file_path("files/Margit-v0")

# List all files in the scenario
for file in scenario_dir.glob("*"):
    print(file.name)

Configuration Files

EldenGym uses TOML configuration files for the Siphon server. These are handled by pysiphon:

File Structure:

eldengym/files/
├── Margit-v0/
│   ├── er_siphon_config.toml  # Siphon memory configuration
│   └── keybinds.json           # Key bindings
└── (other scenarios)

Loading configs:

import eldengym

# Configs are automatically resolved when using make()
env = eldengym.make("Margit-v0")

# Or manually with EldenClient
from eldengym.client import EldenClient

client = EldenClient()
client.load_config_from_file("files/Margit-v0/er_siphon_config.toml")

Note: Configuration parsing is now handled by pysiphon.SiphonClient.set_process_config(), which reads TOML files directly. EldenGym no longer parses TOML files internally.