Skip to content

Commit 67e1819

Browse files
ArmavicaricardoV94
authored andcommitted
Fix supplying (base_)compiledir as str
1 parent f35ce26 commit 67e1819

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pytensor/configdefaults.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,14 +1155,14 @@ def _default_compiledirname() -> str:
11551155
return safe
11561156

11571157

1158-
def _filter_base_compiledir(path: Path) -> Path:
1158+
def _filter_base_compiledir(path: str | Path) -> Path:
11591159
# Expand '~' in path
1160-
return path.expanduser()
1160+
return Path(path).expanduser()
11611161

11621162

1163-
def _filter_compiledir(path: Path) -> Path:
1163+
def _filter_compiledir(path: str | Path) -> Path:
11641164
# Expand '~' in path
1165-
path = path.expanduser()
1165+
path = Path(path).expanduser()
11661166
# Turn path into the 'real' path. This ensures that:
11671167
# 1. There is no relative path, which would fail e.g. when trying to
11681168
# import modules from the compile dir.

tests/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import configparser as stdlib_configparser
44
import io
55
import pickle
6+
from pathlib import Path
7+
from tempfile import mkdtemp
68

79
import pytest
810

@@ -19,6 +21,15 @@ def _create_test_config():
1921
)
2022

2123

24+
def test_config_paths():
25+
base_compiledir = mkdtemp()
26+
assert configdefaults._filter_base_compiledir(str(base_compiledir)) == Path(
27+
base_compiledir
28+
)
29+
compiledir = mkdtemp()
30+
assert configdefaults._filter_compiledir(str(compiledir)) == Path(compiledir)
31+
32+
2233
def test_invalid_default():
2334
# Ensure an invalid default value found in the PyTensor code only causes
2435
# a crash if it is not overridden by the user.

0 commit comments

Comments
 (0)