Skip to content

Commit

Permalink
renamed "mark" module with "hook"
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Nov 15, 2023
1 parent 69e0e26 commit bde68a8
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 65 deletions.
26 changes: 13 additions & 13 deletions extras/fileformats/extras/application/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pydra.engine.specs
from fileformats.generic import FsObject
from fileformats.core.utils import set_cwd
from fileformats.core import mark, FileSet
from fileformats.core import hook, FileSet
from fileformats.application import Zip, Tar, TarGzip


Expand Down Expand Up @@ -47,10 +47,10 @@
Compressed = FileSet.type_var("Compressed")


@mark.converter(source_format=FsObject, target_format=Tar)
@mark.converter(source_format=FsObject, target_format=TarGzip, compression="gz")
@mark.converter(source_format=Compressed, target_format=Tar[Compressed])
@mark.converter(
@hook.converter(source_format=FsObject, target_format=Tar)
@hook.converter(source_format=FsObject, target_format=TarGzip, compression="gz")
@hook.converter(source_format=Compressed, target_format=Tar[Compressed])
@hook.converter(
source_format=Compressed, target_format=TarGzip[Compressed], compression="gz"
)
@pydra.mark.task
Expand Down Expand Up @@ -102,10 +102,10 @@ def create_tar(
return Path(out_file)


@mark.converter(source_format=Tar, target_format=FsObject)
@mark.converter(source_format=TarGzip, target_format=FsObject)
@mark.converter(source_format=Tar[Compressed], target_format=Compressed)
@mark.converter(source_format=TarGzip[Compressed], target_format=Compressed)
@hook.converter(source_format=Tar, target_format=FsObject)
@hook.converter(source_format=TarGzip, target_format=FsObject)
@hook.converter(source_format=Tar[Compressed], target_format=Compressed)
@hook.converter(source_format=TarGzip[Compressed], target_format=Compressed)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": Path}})
def extract_tar(
Expand Down Expand Up @@ -136,8 +136,8 @@ def extract_tar(
return extracted[0]


@mark.converter(source_format=FsObject, target_format=Zip)
@mark.converter(source_format=Compressed, target_format=Zip[Compressed])
@hook.converter(source_format=FsObject, target_format=Zip)
@hook.converter(source_format=Compressed, target_format=Zip[Compressed])
@pydra.mark.task
@pydra.mark.annotate(
{
Expand Down Expand Up @@ -198,8 +198,8 @@ def create_zip(
return Path(out_file)


@mark.converter(source_format=Zip, target_format=FsObject)
@mark.converter(source_format=Zip[Compressed], target_format=Compressed)
@hook.converter(source_format=Zip, target_format=FsObject)
@hook.converter(source_format=Zip[Compressed], target_format=Compressed)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": Path}})
def extract_zip(in_file: Zip, extract_dir: Path) -> Path:
Expand Down
6 changes: 3 additions & 3 deletions extras/fileformats/extras/application/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import yaml
import pydra.mark
import pydra.engine.specs
from fileformats.core import mark
from fileformats.core import hook
from fileformats.application import DataSerialization, Json, Yaml


@mark.converter(target_format=Json, output_format=Json)
@mark.converter(target_format=Yaml, output_format=Yaml)
@hook.converter(target_format=Json, output_format=Json)
@hook.converter(target_format=Yaml, output_format=Yaml)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": DataSerialization}})
def convert_data_serialization(
Expand Down
12 changes: 6 additions & 6 deletions extras/fileformats/extras/image/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import tempfile
import pydra.mark
import pydra.engine.specs
from fileformats.core import mark
from fileformats.core import hook
from fileformats.image.raster import RasterImage, Bitmap, Gif, Jpeg, Png, Tiff


@mark.converter(target_format=Bitmap, output_format=Bitmap)
@mark.converter(target_format=Gif, output_format=Gif)
@mark.converter(target_format=Jpeg, output_format=Jpeg)
@mark.converter(target_format=Png, output_format=Png)
@mark.converter(target_format=Tiff, output_format=Tiff)
@hook.converter(target_format=Bitmap, output_format=Bitmap)
@hook.converter(target_format=Gif, output_format=Gif)
@hook.converter(target_format=Jpeg, output_format=Jpeg)
@hook.converter(target_format=Png, output_format=Png)
@hook.converter(target_format=Tiff, output_format=Tiff)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": RasterImage}})
def convert_image(
Expand Down
8 changes: 4 additions & 4 deletions fileformats/application/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing as ty
from random import Random
from pathlib import Path
from ..core import mark, DataType
from ..core import hook, DataType
from ..core.mixin import WithClassifiers
from ..generic import File
from ..core.exceptions import FormatMismatchError
Expand Down Expand Up @@ -41,12 +41,12 @@ class DataSerialization(WithClassifiers, File):

iana_mime = None

@mark.extra
@hook.extra
def load(self):
"""Load the contents of the file into a dictionary"""
raise NotImplementedError

@mark.extra
@hook.extra
def save(data):
"""Serialise a dictionary to a new file"""
raise NotImplementedError
Expand All @@ -68,7 +68,7 @@ class Json(DataSerialization):
ext = ".json"
allowed_classifiers = (JsonSchema, InformalSchema)

@mark.check
@hook.check
def load(self):
try:
with open(self.fspath) as f:
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def register_converter(
source_format: type,
converter_tuple: ty.Tuple[ty.Callable, ty.Dict[str, ty.Any]],
):
"""Registers a converter task within a class attribute. Called by the @fileformats.mark.converter
"""Registers a converter task within a class attribute. Called by the @fileformats.hook.converter
decorator.
Parameters
Expand Down
10 changes: 5 additions & 5 deletions fileformats/core/fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
FileFormatsExtrasPkgNotCheckedError,
)
from .datatype import DataType
from . import mark
from . import hook

try:
from typing import Self
Expand Down Expand Up @@ -188,7 +188,7 @@ def metadata(self) -> ty.Dict[str, ty.Any]:
metadata = None
return metadata

@mark.extra
@hook.extra
def read_metadata(self) -> ty.Dict[str, ty.Any]:
"""Reads any metadata associated with the fileset and returns it as a dict"""
raise NotImplementedError
Expand Down Expand Up @@ -518,7 +518,7 @@ def register_converter(
converter_tuple: ty.Tuple[ty.Callable, ty.Dict[str, ty.Any]],
):
"""Registers a converter task within a class attribute. Called by the
@fileformats.mark.converter decorator.
@fileformats.hook.converter decorator.
Parameters
----------
Expand Down Expand Up @@ -844,7 +844,7 @@ def sample(
if not dest_dir:
dest_dir = Path(tempfile.mkdtemp())
# Need to use mock to get an instance in order to use the singledispatch-based
# mark.extra decorator
# hook.extra decorator
mock = cls.mock()
fspaths = mock.generate_sample_data(dest_dir, seed, stem)
try:
Expand All @@ -857,7 +857,7 @@ def sample(
)
return obj

@mark.extra
@hook.extra
def generate_sample_data(
self, dest_dir: Path, seed: int = 0, stem: str = None
) -> ty.Iterable[Path]:
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/mark.py → fileformats/core/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def check(method):
Parameters
----------
method : Function
the method to mark as a check
the method to hook as a check
"""
method.__annotations__[DataType.CHECK_ANNOTATION] = None
return method
Expand Down
12 changes: 6 additions & 6 deletions fileformats/core/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import typing as ty
from collections import defaultdict
from . import mark
from . import hook
from .fileset import FileSet
from .utils import classproperty, describe_task, to_mime_format_name
from .converter import SubtypeVar
Expand Down Expand Up @@ -30,7 +30,7 @@ class WithMagicNumber:
binary: bool
magic_number: ty.Union[str, bytes]

@mark.check
@hook.check
def check_magic_number(self):
if self.binary and isinstance(self.magic_number, str):
magic_bytes = bytes.fromhex(self.magic_number)
Expand Down Expand Up @@ -74,7 +74,7 @@ class WithMagicVersion:
magic_pattern_offset = 0
magic_pattern_maxlength = None

@mark.required
@hook.required
@property
def version(self) -> ty.Union[str, ty.Tuple[str]]:
read_length = (
Expand Down Expand Up @@ -169,7 +169,7 @@ class MyFileFormatWithSeparateHeader(WithSeparateHeader, MyFileFormat):
def nested_types(cls):
return (cls.header_type,)

@mark.required
@hook.required
@property
def header(self):
return self.header_type(self.select_by_ext(self.header_type))
Expand Down Expand Up @@ -200,7 +200,7 @@ class MyFileFormatWithSideCars(WithSideCars, MyFileFormat):
the file-formats of the expected side-car files
"""

@mark.required
@hook.required
@property
def side_cars(self):
return [tp(self.select_by_ext(tp)) for tp in self.side_car_types]
Expand Down Expand Up @@ -555,7 +555,7 @@ def register_converter(
source_format: type,
converter_tuple: ty.Tuple[ty.Callable, ty.Dict[str, ty.Any]],
):
"""Registers a converter task within a class attribute. Called by the @fileformats.mark.converter
"""Registers a converter task within a class attribute. Called by the @fileformats.hook.converter
decorator.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/tests/test_classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import pydra.mark
from fileformats.core import from_mime, DataType, FileSet
from fileformats.core.mark import converter
from fileformats.core.hook import converter
from fileformats.application import Zip
from fileformats.generic import DirectoryContaining
from fileformats.field import Array, Integer, Decimal, Text, Boolean
Expand Down
8 changes: 4 additions & 4 deletions fileformats/core/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pydra.engine.specs import File
from fileformats.testing import Foo, Bar, Baz, Qux
from fileformats.core import mark
from fileformats.core import hook
from fileformats.core.exceptions import FormatConversionError
from conftest import write_test_file

Expand All @@ -18,7 +18,7 @@
def foo_bar_converter():
work_dir = Path(tempfile.mkdtemp())

@mark.converter
@hook.converter
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": Bar}})
def foo_bar_converter_(in_file: Foo):
Expand All @@ -31,7 +31,7 @@ def foo_bar_converter_(in_file: Foo):
def baz_bar_converter():
work_dir = Path(tempfile.mkdtemp())

@mark.converter(out_file="out")
@hook.converter(out_file="out")
@pydra.mark.task
@pydra.mark.annotate({"return": {"out": Bar}})
def baz_bar_converter_(in_file: Baz):
Expand Down Expand Up @@ -84,7 +84,7 @@ def FooQuxConverter():
name="Output", fields=output_fields, bases=(specs.ShellOutSpec,)
)

@mark.converter(source_format=Foo, target_format=Qux)
@hook.converter(source_format=Foo, target_format=Qux)
class FooQuxConverter_(ShellCommandTask):

input_spec = FooQux_input_spec
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/tests/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_nested_directories_fail2(work_dir):

# ext = ".foo"

# @mark.required
# @hook.required
# @property
# def bar(self):
# return self.select_by_ext(".bar")
Expand Down
6 changes: 3 additions & 3 deletions fileformats/core/tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fileformats.field import Integer, Boolean, Decimal, Array, Text
from fileformats.testing import Foo
from fileformats.core.exceptions import FileFormatsError, FormatMismatchError
from fileformats.core import mark
from fileformats.core import hook
from conftest import write_test_file


Expand Down Expand Up @@ -162,12 +162,12 @@ def test_header_overwrite(work_dir):


class YFile(ImageWithInlineHeader):
@mark.required
@hook.required
@property
def y(self):
return self.metadata["y"]

@mark.check
@hook.check
def y_value(self):
if self.y <= 10:
raise FormatMismatchError(f"'y' property is not > 10 ({self.y})")
Expand Down
8 changes: 4 additions & 4 deletions fileformats/core/tests/test_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from conftest import write_test_file
from fileformats.generic import File
from fileformats.core import mark
from fileformats.core import hook
from fileformats.core.mixin import WithMagicNumber, WithSeparateHeader, WithSideCars
from fileformats.core.exceptions import FormatMismatchError

Expand Down Expand Up @@ -48,7 +48,7 @@ class FileWithSeparateHeader(WithSeparateHeader, File):
image_type = "sample-image-type"
binary = False

@mark.check
@hook.check
def check_image_type(self):
if self.metadata[self.image_type_key] != self.image_type:
raise FormatMismatchError(
Expand Down Expand Up @@ -121,7 +121,7 @@ class FileWithSideCars(WithSideCars, ImageWithInlineHeader):
experiment_type_key = "experiment-type"
experiment_type = "sample-experiment-type"

@mark.check
@hook.check
def check_image_type(self):
"""Loaded from inline-header"""
if self.metadata[self.image_type_key] != self.image_type:
Expand All @@ -130,7 +130,7 @@ def check_image_type(self):
f"found {self.metadata[self.image_type_key]}"
)

@mark.check
@hook.check
def check_experiment_type(self):
"""Loaded from side-car"""
if self.metadata["header"][self.experiment_type_key] != self.experiment_type:
Expand Down
6 changes: 3 additions & 3 deletions fileformats/core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typing as ty
import time
import pytest
from fileformats.core import FileSet, mark
from fileformats.core import FileSet, hook
from fileformats.generic import File, Directory, FsObject
from fileformats.core.mixin import WithSeparateHeader
from fileformats.core.utils import find_matching, to_mime, from_mime, from_paths
Expand Down Expand Up @@ -260,12 +260,12 @@ class LuigiMario(File):
ext = ".luigi.mario"

class DoubleMario(FileSet):
@mark.required
@hook.required
@property
def bar(self):
return Mario(self.select_by_ext(Mario))

@mark.required
@hook.required
@property
def luigi_bar(self):
return LuigiMario(self.select_by_ext(LuigiMario))
Expand Down
Loading

0 comments on commit bde68a8

Please sign in to comment.