Skip to content

Commit 1dbca8f

Browse files
committed
WIP: TODO: Use Pathlib more, rework handling of filepaths entirely
1 parent 7ac6397 commit 1dbca8f

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
@@ -234,11 +234,12 @@ def filenames_of_lib_helper(lib, non_recursive_libnames, ext):
234234
*libprefix, lib = lib.split(".")
235235
if ".".join(libprefix) == logical_name:
236236
cur_lib = os.path.join(physical_name, lib)
237+
# TODO HERE USE pathlib
237238
yield fix_path(os.path.relpath(os.path.normpath(cur_lib + ext), "."))
238239

239240

240241
@memoize
241-
def filename_of_lib_helper(lib, non_recursive_libnames, ext):
242+
def filename_of_lib_helper(lib, non_recursive_libnames, ext, base_dir):
242243
filenames = list(filenames_of_lib_helper(lib, non_recursive_libnames, ext))
243244
existing_filenames = [f for f in filenames if os_path_isfile(f) or os_path_isfile(os.path.splitext(f)[0] + ".v")]
244245
if len(existing_filenames) > 0:
@@ -269,7 +270,7 @@ def filename_of_lib_helper(lib, non_recursive_libnames, ext):
269270
level=LOG_ALWAYS,
270271
)
271272
return retval
272-
return fix_path(os.path.relpath(os.path.normpath(lib.replace(".", os.sep) + ext), "."))
273+
return fix_path(os.path.relpath(os.path.normpath(lib.replace(".", os.sep) + ext), base_dir))
273274

274275

275276
def filename_of_lib(lib, ext=".v", **kwargs):
@@ -282,7 +283,7 @@ def filename_of_lib(lib, ext=".v", **kwargs):
282283

283284

284285
@memoize
285-
def lib_of_filename_helper(filename, non_recursive_libnames, exts):
286+
def lib_of_filename_helper(filename, non_recursive_libnames, exts, base_dir):
286287
for ext in exts:
287288
if filename.endswith(ext):
288289
filename = filename[: -len(ext)]
@@ -299,10 +300,12 @@ def lib_of_filename_helper(filename, non_recursive_libnames, exts):
299300
if close_matches:
300301
DEFAULT_LOG(f"Close matches: {close_matches}", level=LOG_ALWAYS)
301302
else:
302-
DEFAULT_LOG(f"Looked in {non_recursive_libnames}", level=1)
303-
raise Exception
304-
if os.path.relpath(os.path.normpath(filename), ".").startswith(".." + os.sep) and not os.path.isabs(filename):
303+
DEFAULT_LOG(f"Looked in {non_recursive_libnames}", level=3)
304+
# if not allow_nomatch:
305+
# raise RuntimeError(f"Could not find logical name for physical name {filename}")
306+
if os.path.relpath(os.path.normpath(filename), base_dir).startswith(".." + os.sep) and not os.path.isabs(filename):
305307
filename = os.path.abspath(filename)
308+
DEFAULT_LOG(f"Returning {filename.replace(os.sep, '.')}", level=LOG_ALWAYS)
306309
return filename, filename.replace(os.sep, ".")
307310

308311

0 commit comments

Comments
 (0)