Skip to content

Commit

Permalink
fixed up handling of multiple registrations of the same converter fro…
Browse files Browse the repository at this point in the history
…m different import paths
  • Loading branch information
tclose committed May 29, 2024
1 parent 7e7deb7 commit d353f99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion fileformats/core/fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import struct
from enum import Enum, IntEnum
from warnings import warn
import inspect
import tempfile
from collections import Counter
import typing as ty
Expand Down Expand Up @@ -625,7 +626,8 @@ def register_converter(
raise FormatConversionError(
f"Cannot register converter from {source_format.__name__} "
f"to {cls.__name__}, {describe_task(task)}, because there is already "
f"one registered from {describe_task(prev_task)}"
f"one registered from {describe_task(prev_task)}:"
f"\n\n{inspect.getsource(task)}\n\nand{inspect.getsource(prev_task)}\n\n"
)
converters_dict[source_format] = converter_tuple

Expand Down
10 changes: 6 additions & 4 deletions fileformats/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ def describe_task(task):
if inspect.isfunction(task):
import cloudpickle

task = cloudpickle.loads(task().inputs._func)
try:
task = cloudpickle.loads(task().inputs._func)
except Exception as e:
return f"{task} (Failed to load task function: {e})"

Check warning on line 145 in fileformats/core/utils.py

View check run for this annotation

Codecov / codecov/patch

fileformats/core/utils.py#L144-L145

Added lines #L144 - L145 were not covered by tests
src_file = inspect.getsourcefile(task)
src_line = inspect.getsourcelines(task)[-1]
return f"{task} (defined at line {src_line} of {src_file})"
Expand All @@ -148,9 +151,8 @@ def describe_task(task):
def matching_source(task1, task2) -> bool:
"""Checks to see if the tasks share the same source code but are just getting reimported
for some unknown reason"""
return (
inspect.getsourcefile(task1) == inspect.getsourcefile(task2)
and inspect.getsourcelines(task1)[-1] == inspect.getsourcelines(task2)[-1]
return inspect.getsource(inspect.getmodule(task1)) == inspect.getsource(
inspect.getmodule(task2)
)


Expand Down

0 comments on commit d353f99

Please sign in to comment.