Skip to content

Commit

Permalink
Merge pull request #5 from ArcanaFramework/mypy-ci
Browse files Browse the repository at this point in the history
Updated to use Binary|UnicodeFile types and validated_property
  • Loading branch information
tclose authored Sep 17, 2024
2 parents 5f464fb + 5b6363e commit 38fab81
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 47 deletions.
31 changes: 19 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- id: black
exclude: ^(arcana/_version\.py|versioneer\.py)$
args:
- -l 88
- repo: https://github.com/codespell-project/codespell
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
- id: codespell
exclude: ^(xnat_checks/_version\.py|versioneer\.py)$
args:
- --ignore-words=.codespell-ignorewords
- repo: https://github.com/PyCQA/flake8
- --ignore-words=.codespell-ignorewords
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
args: [--strict, --install-types, --non-interactive]
exclude: tests
additional_dependencies: [pytest, fileformats>=0.13.0]
10 changes: 6 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging
from pathlib import Path
import typing as ty
import tempfile
import pytest

Expand All @@ -23,15 +24,16 @@
if os.getenv("_PYTEST_RAISE", "0") != "0":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value


@pytest.fixture
def work_dir():
def work_dir() -> Path:
work_dir = tempfile.mkdtemp()
return Path(work_dir)
20 changes: 15 additions & 5 deletions fileformats/datascience/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
MatFile,
RData,
DatFile,
Hdf5,
)
from .scripts import (
RFile
Hdf5,
)
from .scripts import RFile
from .object_serialization import (
Pickle,
Pickle__Gzip,
)
)

__all__ = [
"__version__",
"TextMatrix",
"MatFile",
"RData",
"DatFile",
"Hdf5",
"RFile",
"Pickle",
"Pickle__Gzip",
]
38 changes: 19 additions & 19 deletions fileformats/datascience/data.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
from fileformats.core.mixin import WithMagicNumber
from fileformats.generic import File
from fileformats.generic import UnicodeFile, BinaryFile


class Data(File):
iana_mime = None
binary = True
class Data:
...


class TextVector(Data):
class TextVector(Data, UnicodeFile):
"""space-delimited text file containing a single vector of values"""
binary = False

...


class TextArray(Data):
class TextArray(Data, UnicodeFile):
"""space-delimited text file containing a 2-d array of values"""
binary = False

...


class TextMatrix(Data):
class TextMatrix(Data, UnicodeFile):
ext = ".mat"
binary = False


class RData(WithMagicNumber, Data):
class RData(WithMagicNumber, Data, BinaryFile):
"""Data-file created by the R statistical package"""

ext = ".rData"
binary = True
magic_number = "1f8b0800"


class MatFile(WithMagicNumber, Data):
class MatFile(WithMagicNumber, Data, BinaryFile):
"""MATLAB Mat-File (https://au.mathworks.com/help/matlab/import_export/mat-file-versions.html)"""

ext = ".mat"
magic_number = "4D41544C"
binary = True


class DatFile(Data):
"""Generic binary data file"""
binary = True

ext = ".dat"


class Hdf5(WithMagicNumber, Data):
class Hdf5(WithMagicNumber, Data, BinaryFile):
"""Hierarchical Data Format (HDF) Version 5
An open source file format that supports large, complex, heterogeneous data.
HDF5 uses a "file directory" like structure that allows you to organize data within
the file in many different structured ways, as you might do with files on your computer."""
the file in many different structured ways, as you might do with files on your computer.
"""

binary = True
ext = ".h5"
magic_number = "894844460d0a1a0a"


class VtkDataFile(WithMagicNumber, Data):
class VtkDataFile(WithMagicNumber, Data, BinaryFile):

binary = True
ext = ".vtk"
magic_number = b"#vtk DataFile Version"
11 changes: 6 additions & 5 deletions fileformats/datascience/object_serialization.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from fileformats.generic import File
from fileformats.generic import BinaryFile
from fileformats.core.mixin import WithMagicNumber
from fileformats.application import Gzip


class ObjectSerialisation(File):
iana_mime = None
binary = True
class ObjectSerialisation(BinaryFile):
...


class Pickle(WithMagicNumber, ObjectSerialisation):
"""Python's native byte-encoded serialization format"""

ext = ".pkl"
magic_number = "8004"


class Pickle__Gzip(Gzip[Pickle]):
class Pickle__Gzip(Gzip[Pickle]): # type: ignore[type-arg]
"""Python pickle file that has been gzipped"""

ext = "pkl.gz"
alternate_exts = (".pklz",)
iana_mime = "application/x-pickle+gzip"
3 changes: 2 additions & 1 deletion fileformats/datascience/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@


class Script(Plain):
iana_mime = None
iana_mime = None # type: ignore[assignment]


class RFile(Script):
"""R statistical package script file"""

ext = ".r"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ doctests = true
per-file-ignores = ["__init__.py:F401"]
max-line-length = 88
select = "C,E,F,W,B,B950"
extend-ignore = ['E203', 'E501', 'E129']
extend-ignore = ['E203', 'E501', 'E129', 'E701', 'W503']


[tool.mypy]
Expand Down

0 comments on commit 38fab81

Please sign in to comment.