Skip to content

Fix supplying (base_)compiledir as str #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pytensor/configdefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,14 +1155,14 @@ def _default_compiledirname() -> str:
return safe


def _filter_base_compiledir(path: Path) -> Path:
def _filter_base_compiledir(path: str | Path) -> Path:
# Expand '~' in path
return path.expanduser()
return Path(path).expanduser()


def _filter_compiledir(path: Path) -> Path:
def _filter_compiledir(path: str | Path) -> Path:
# Expand '~' in path
path = path.expanduser()
path = Path(path).expanduser()
# Turn path into the 'real' path. This ensures that:
# 1. There is no relative path, which would fail e.g. when trying to
# import modules from the compile dir.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import configparser as stdlib_configparser
import io
import pickle
from pathlib import Path

import pytest

Expand All @@ -19,6 +20,18 @@ def _create_test_config():
)


def test_base_compiledir_str(tmp_path: Path):
base_compiledir = tmp_path
assert (
configdefaults._filter_base_compiledir(str(base_compiledir)) == base_compiledir
)


def test_compiledir_str(tmp_path: Path):
compiledir = tmp_path
assert configdefaults._filter_compiledir(str(compiledir)) == compiledir


def test_invalid_default():
# Ensure an invalid default value found in the PyTensor code only causes
# a crash if it is not overridden by the user.
Expand Down
Loading