Skip to content
Snippets Groups Projects
Commit 2c43ac85 authored by Yannick DAYER's avatar Yannick DAYER
Browse files

Remove the Filename preprocessor

parent 0acddfaf
No related branches found
No related tags found
1 merge request!299Remove invalid entry-points from setup.py
Pipeline #61982 failed
# @date Wed May 11 12:39:37 MDT 2016
# @author Manuel Gunther <siebenkopf@googlemail.com>
import os
from .Preprocessor import Preprocessor
class Filename(Preprocessor):
"""This preprocessor is simply passing over the file name, in order to be used in an extractor that loads the data from file.
The file name that will be returned by the :py:meth:`read_data` function will contain the path of the :py:class:`bob.bio.base.database.BioFile`, but it might contain more paths (such as the ``--preprocessed-directory`` passed on command line).
"""
def __init__(self):
# call base class constructor, using a custom ``read_original_data`` that does nothing and always returns None
super(Filename, self).__init__(
writes_data=False, read_original_data=lambda x, y, z: None
)
# The call function (i.e. the operator() in C++ terms)
def __call__(self, data, annotations=None):
"""__call__(data, annotations) -> data
This function appears to do something, but it simply returns ``1``, which is used nowhere.
We could also return ``None``, but this might trigger warnings in the calling function.
**Parameters:**
``data`` : ``None``
The file name returned by :py:meth:`read_original_data`.
``annotations`` : any
ignored.
**Returns:**
``data`` : int
1 throughout
"""
return 1
def write_data(self, data, data_file):
"""Does **not** write any data.
``data`` : any
ignored.
``data_file`` : any
ignored.
"""
pass
def read_data(self, data_file):
"""read_data(data_file) -> data
Returns the name of the data file without its filename extension.
**Parameters:**
``data_file`` : str
The name of the preprocessed data file.
**Returns:**
``data`` : str
The preprocessed data read from file.
"""
return os.path.splitext(data_file)[0]
# isort: skip_file
from .Preprocessor import Preprocessor
from .Filename import Filename
# gets sphinx autodoc done right - don't remove it
......@@ -21,6 +20,5 @@ def __appropriate__(*args):
__appropriate__(
Preprocessor,
Filename,
)
__all__ = [_ for _ in dir() if not _.startswith("_")]
import bob.bio.base
def test_filename():
# load extractor
preprocessor = bob.bio.base.preprocessor.Filename()
assert isinstance(preprocessor, bob.bio.base.preprocessor.Preprocessor)
assert isinstance(preprocessor, bob.bio.base.preprocessor.Filename)
# try to load the original image
assert (
preprocessor.read_original_data(
bob.bio.base.database.file.BioFile(1, "2", 3),
"/any/path",
".any.extension",
)
is None
)
# try to process
assert preprocessor(None, None) == 1
# try to write
preprocessor.write_data(None, "/any/path")
# read a file
assert preprocessor.read_data("/any/file.name") == "/any/file"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment