Skip to content

Commit

Permalink
Removed the resolve_symlinks option, instead test both paths (.resolv…
Browse files Browse the repository at this point in the history
…e()'d and not)
  • Loading branch information
Maxime Trebitsch authored and cphyc committed Feb 14, 2022
1 parent 1de7e4f commit 03c41c0
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions yt/frontends/ramses/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import weakref
from collections import defaultdict
from itertools import product
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -41,20 +42,21 @@ class RAMSESFileSanitizer:
info_fname = None # Path | None: path to the info file
group_name = None # str | None: name of the first group folder (if any)

def __init__(self, filename, resolve_symlinks=True):
def __init__(self, filename):

filename = Path(filename)
# Resolve so that it works with symlinks
if resolve_symlinks:
filename = Path(filename).resolve()
# Make the resolve optional, so that it works with symlinks
paths_to_try = (Path(filename), Path(filename).resolve())

self.original_filename = filename

self.output_dir = None
self.info_fname = None

for check_fun in (self.test_with_standard_file, self.test_with_folder_name):
ok, output_dir, info_fname = check_fun(filename)
check_functions = (self.test_with_standard_file, self.test_with_folder_name)

# Loop on both the functions and the tested paths
for path, check_fun in product(paths_to_try, check_functions):
ok, output_dir, info_fname = check_fun(path)
if ok:
break

Expand Down Expand Up @@ -684,8 +686,6 @@ def __init__(
max_level=None,
max_level_convention=None,
default_species_fields=None,
*,
resolve_symlinks=True,
):
# Here we want to initiate a traceback, if the reader is not built.
if isinstance(fields, str):
Expand All @@ -702,10 +702,6 @@ def __init__(
cosmological:
If set to None, automatically detect cosmological simulation.
If a boolean, force its value.
resolve_symlinks:
If set to True, resolves the symlinks in the filenames.
Default value is True.
"""

self._fields_in_file = fields
Expand All @@ -719,7 +715,7 @@ def __init__(
max_level, max_level_convention
)

file_handler = RAMSESFileSanitizer(filename, resolve_symlinks=resolve_symlinks)
file_handler = RAMSESFileSanitizer(filename)

# ensure validation happens even if the class is instanciated
# directly rather than from yt.load
Expand Down Expand Up @@ -1013,5 +1009,5 @@ def read_namelist(self):
self.parameters["namelist"] = nml

@classmethod
def _is_valid(cls, filename, *args, resolve_symlinks=True, **kwargs):
return RAMSESFileSanitizer(filename, resolve_symlinks).is_valid
def _is_valid(cls, filename, *args, **kwargs):
return RAMSESFileSanitizer(filename).is_valid

0 comments on commit 03c41c0

Please sign in to comment.