-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul of directories to use relative directories wherever possible…
…; regenerated test benchmarks
- Loading branch information
Showing
8,411 changed files
with
731 additions
and
539 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,18 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import dill | ||
|
||
|
||
class PicklerWithRelativePaths(dill.Pickler): | ||
def __init__(self, base_directory, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.base_directory = base_directory | ||
|
||
def reducer_override(self, obj): | ||
if isinstance(obj, Path): | ||
return Path, pickle_path(obj, self.base_directory) | ||
else: | ||
return NotImplemented | ||
|
||
|
||
def pickle_path(path: Path, base_directory: Path): | ||
# Convert the path to relative if it's absolute | ||
if path.is_absolute(): | ||
try: | ||
rel_path = path.relative_to(base_directory.resolve()) | ||
except ValueError: | ||
rel_path = path | ||
return (str(rel_path),) | ||
else: | ||
# Return relative paths as-is | ||
return (str(path),) | ||
|
||
|
||
def read_pkl(filename: Path | str) -> Any: | ||
with open(filename, 'rb') as fd: | ||
out = dill.load(fd) | ||
return out | ||
|
||
|
||
def write_pkl(obj: Any, filename: Path | str, base_directory: Path | None = None): | ||
def write_pkl(obj: Any, filename: Path | str): | ||
filename = Path(filename) if not isinstance(filename, Path) else filename | ||
|
||
if base_directory is None: | ||
base_directory = filename.parent | ||
|
||
with open(filename, 'wb') as fd: | ||
pickler = PicklerWithRelativePaths(base_directory, fd) | ||
pickler.dump(obj) | ||
dill.dump(obj, fd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.