Skip to content

Commit

Permalink
ENH: add support for pathlib.Path inputs in import_file
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Sep 5, 2024
1 parent e6996c5 commit e32444a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extension_helpers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def import_file(filename, name=None):
if not os.path.exists(filename):
raise ImportError(f"Could not import file {filename}")

loader = import_machinery.SourceFileLoader(name, filename)
loader = import_machinery.SourceFileLoader(name, os.fspath(filename))
spec = spec_from_file_location(name, filename)
mod = module_from_spec(spec)
loader.exec_module(mod)
Expand Down
4 changes: 2 additions & 2 deletions extension_helpers/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@


def test_import_file(tmp_path):
filename = str(tmp_path / "spam.py")
filename = tmp_path / "spam.py"
with open(filename, "w") as f:
f.write("magic = 12345")
module = import_file(filename)
assert module.magic == 12345


def test_write_if_different(tmp_path):
filename = str(tmp_path / "test.txt")
filename = tmp_path / "test.txt"
write_if_different(filename, b"abc")
time1 = os.path.getmtime(filename)
time.sleep(0.01)
Expand Down

0 comments on commit e32444a

Please sign in to comment.