Skip to content

Commit 8fc9dc9

Browse files
authored
Merge pull request #66 from ArcanaFramework/develop
Bug fix for converter registration
2 parents 1e75998 + 22246a3 commit 8fc9dc9

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

.github/workflows/ci-cd.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ jobs:
3939
with:
4040
python-version: ${{ matrix.python-version }}
4141
- name: Update build tools
42-
run: python3 -m pip install --upgrade pip
42+
run: python3 -m pip install --break-system-packages --upgrade pip
4343
- name: Install Package
44-
run: python3 -m pip install -e .[test]
44+
run: python3 -m pip install --break-system-packages -e .[test]
4545
- name: Install Extras Package
46-
run: python3 -m pip install -e ./extras[test]
46+
run: python3 -m pip install --break-system-packages -e ./extras[test]
4747
- name: Change out of root directory
4848
run: cd docs
4949
- name: Pytest
@@ -76,7 +76,7 @@ jobs:
7676
with:
7777
python-version: '3.12'
7878
- name: Install build tools
79-
run: python3 -m pip install build twine
79+
run: python3 -m pip install --break-system-packages build twine
8080
- name: Build source and wheel distributions
8181
run: python3 -m build ${{ matrix.pkg[1] }}
8282
- name: Check distributions
@@ -102,7 +102,7 @@ jobs:
102102
python-version: 3.x
103103
- name: Install dependencies
104104
run: |
105-
python3 -m pip install --upgrade pip
105+
python3 -m pip install --break-system-packages --upgrade pip
106106
pip install .[docs]
107107
- name: Build documentation
108108
run: |

fileformats/core/datatype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def from_mime(cls, mime_string):
141141
# treats it). Therefore, we loop through all subclasses across the different
142142
# namespaces to find one that matches the name.
143143
format_name = format_name[2:] # remove "x-" prefix
144-
matching_name = FileSet.formats_by_name[format_name]
144+
matching_name = FileSet.formats_by_name.get(format_name, ())
145145
matching_name = [
146146
m
147147
for m in matching_name

fileformats/core/fileset.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import struct
44
from enum import Enum, IntEnum
55
from warnings import warn
6+
import inspect
67
import tempfile
78
from collections import Counter
89
import typing as ty
@@ -625,7 +626,8 @@ def register_converter(
625626
raise FormatConversionError(
626627
f"Cannot register converter from {source_format.__name__} "
627628
f"to {cls.__name__}, {describe_task(task)}, because there is already "
628-
f"one registered from {describe_task(prev_task)}"
629+
f"one registered from {describe_task(prev_task)}:"
630+
f"\n\n{inspect.getsource(task)}\n\nand{inspect.getsource(prev_task)}\n\n"
629631
)
630632
converters_dict[source_format] = converter_tuple
631633

@@ -905,7 +907,10 @@ def mock(cls, *fspaths: ty.Tuple[ty.Union[Path, str]]) -> "FileSet":
905907

906908
@classmethod
907909
def sample(
908-
cls, dest_dir: ty.Optional[Path] = None, seed: int = 0, stem: str = None
910+
cls,
911+
dest_dir: ty.Optional[Path] = None,
912+
seed: ty.Union[int, str] = 0,
913+
stem: str = None,
909914
) -> Self:
910915
"""Return an sample instance of the file-set type for classes where the
911916
`test_data` extra has been implemented

fileformats/core/mixin.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,13 @@ def namespace(cls): # pylint: disable=no-self-argument
659659
namespace = super().namespace
660660
return namespace
661661

662-
@property
663-
def type_name(self):
662+
@classproperty
663+
def type_name(cls):
664664
"""Name of type including classifiers to be used in __repr__"""
665-
if self.is_classified:
666-
unclassified = self.unclassified.__name__
665+
if cls.is_classified:
666+
unclassified = cls.unclassified.__name__
667667
else:
668-
unclassified = type(self).__name__
668+
unclassified = type(cls).__name__
669669
return (
670-
unclassified + "[" + ", ".join(t.type_name for t in self.classifiers) + "]"
670+
unclassified + "[" + ", ".join(t.type_name for t in cls.classifiers) + "]"
671671
)

fileformats/core/sampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SampleFileGenerator:
2020
"""
2121

2222
dest_dir: Path
23-
seed: int
23+
seed: ty.Union[int, str]
2424
fname_stem: str
2525

2626
FNAME_STEM_LENGTH = 24

fileformats/core/utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
logger = logging.getLogger("fileformats")
1515

1616

17-
_excluded_subpackages = set(["core", "testing", "serialization", "archive", "document"])
17+
_excluded_subpackages = set(
18+
["core", "testing", "serialization", "archive", "document", "conftest"]
19+
)
1820

1921

2022
def include_testing_package(flag: bool = True):
@@ -137,7 +139,10 @@ def describe_task(task):
137139
if inspect.isfunction(task):
138140
import cloudpickle
139141

140-
task = cloudpickle.loads(task().inputs._func)
142+
try:
143+
task = cloudpickle.loads(task().inputs._func)
144+
except Exception as e:
145+
return f"{task} (Failed to load task function: {e})"
141146
src_file = inspect.getsourcefile(task)
142147
src_line = inspect.getsourcelines(task)[-1]
143148
return f"{task} (defined at line {src_line} of {src_file})"
@@ -146,9 +151,8 @@ def describe_task(task):
146151
def matching_source(task1, task2) -> bool:
147152
"""Checks to see if the tasks share the same source code but are just getting reimported
148153
for some unknown reason"""
149-
return (
150-
inspect.getsourcefile(task1) == inspect.getsourcefile(task2)
151-
and inspect.getsourcelines(task1)[-1] == inspect.getsourcelines(task2)[-1]
154+
return inspect.getsource(inspect.getmodule(task1)) == inspect.getsource(
155+
inspect.getmodule(task2)
152156
)
153157

154158

0 commit comments

Comments
 (0)