Skip to content

Commit ef40067

Browse files
committed
WIP: TODO: Use Pathlib more, rework handling of filepaths entirely
1 parent f40ae4d commit ef40067

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

coq_tools/import_util.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,12 @@ def filenames_of_lib_helper(lib, non_recursive_libnames, ext):
236236
*libprefix, lib = lib.split(".")
237237
if ".".join(libprefix) == logical_name:
238238
cur_lib = os.path.join(physical_name, lib)
239+
# TODO HERE USE pathlib
239240
yield fix_path(os.path.relpath(os.path.normpath(cur_lib + ext), "."))
240241

241242

242243
@memoize
243-
def filename_of_lib_helper(lib, non_recursive_libnames, ext):
244+
def filename_of_lib_helper(lib, non_recursive_libnames, ext, base_dir):
244245
filenames = list(filenames_of_lib_helper(lib, non_recursive_libnames, ext))
245246
existing_filenames = [f for f in filenames if os_path_isfile(f) or os_path_isfile(os.path.splitext(f)[0] + ".v")]
246247
if len(existing_filenames) > 0:
@@ -271,7 +272,7 @@ def filename_of_lib_helper(lib, non_recursive_libnames, ext):
271272
level=LOG_ALWAYS,
272273
)
273274
return retval
274-
return fix_path(os.path.relpath(os.path.normpath(lib.replace(".", os.sep) + ext), "."))
275+
return fix_path(os.path.relpath(os.path.normpath(lib.replace(".", os.sep) + ext), base_dir))
275276

276277

277278
def filename_of_lib(lib, ext=".v", **kwargs):
@@ -284,7 +285,7 @@ def filename_of_lib(lib, ext=".v", **kwargs):
284285

285286

286287
@memoize
287-
def lib_of_filename_helper(filename, non_recursive_libnames, exts):
288+
def lib_of_filename_helper(filename, non_recursive_libnames, exts, base_dir):
288289
for ext in exts:
289290
if filename.endswith(ext):
290291
filename = filename[: -len(ext)]
@@ -301,10 +302,12 @@ def lib_of_filename_helper(filename, non_recursive_libnames, exts):
301302
if close_matches:
302303
DEFAULT_LOG(f"Close matches: {close_matches}", level=LOG_ALWAYS)
303304
else:
304-
DEFAULT_LOG(f"Looked in {non_recursive_libnames}", level=1)
305-
raise Exception
306-
if os.path.relpath(os.path.normpath(filename), ".").startswith(".." + os.sep) and not os.path.isabs(filename):
305+
DEFAULT_LOG(f"Looked in {non_recursive_libnames}", level=3)
306+
# if not allow_nomatch:
307+
# raise RuntimeError(f"Could not find logical name for physical name {filename}")
308+
if os.path.relpath(os.path.normpath(filename), base_dir).startswith(".." + os.sep) and not os.path.isabs(filename):
307309
filename = os.path.abspath(filename)
310+
DEFAULT_LOG(f"Returning {filename.replace(os.sep, '.')}", level=LOG_ALWAYS)
308311
return filename, filename.replace(os.sep, ".")
309312

310313

0 commit comments

Comments
 (0)