Skip to content

Commit

Permalink
Merge pull request #582 from kif/extensions
Browse files Browse the repository at this point in the history
Fix extention manipulation
  • Loading branch information
kif authored Aug 27, 2024
2 parents 8a3a5eb + 4a14d51 commit 96679bf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.9"
python: "3.10"

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand Down
9 changes: 6 additions & 3 deletions src/fabio/app/densify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
__author__ = "Jerome Kieffer"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__licence__ = "MIT"
__date__ = "18/10/2022"
__date__ = "27/08/2024"
__status__ = "production"

FOOTER = """
Expand Down Expand Up @@ -90,7 +90,7 @@ def parse_args():
group.add_argument("-l", "--list", action="store_true", dest="list", default=None,
help="show the list of available output formats and exit")
group.add_argument("-o", "--output", default=None, type=str,
help="output filename, by default {baseame}_densify.h5")
help="output filename, by default {basename}_densify.h5")
group.add_argument("-O", "--output-format", dest="format", default='lima', type=str,
help="output format among 'lima', 'eiger' ...")
group.add_argument("-D", "--dummy", type=int, default=None,
Expand Down Expand Up @@ -248,11 +248,14 @@ def decompress_one(self, filename):
# dest.set_data
t2 = time.perf_counter()
output = self.args.output
if self.args.output is None:
if self.args.output is None or "{basename}" not in self.args.output:
if self.args.format.startswith("lima"):
output = os.path.splitext(filename)[0] + "_dense.h5"
elif self.args.format.startswith("eiger"):
output = os.path.splitext(filename)[0] + "_000001.h5"
else:
base = os.path.basename(os.path.splitext(filename)[0])
output = output.replace("{basename}", base)

self.pb.update(self.pb.max_value, f"Save {output}")
dest.save(output)
Expand Down
4 changes: 2 additions & 2 deletions src/fabio/esperantoimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
__authors__ = ["Florian Plaswig", "Jérôme Kieffer"]
__license__ = "MIT"
__copyright__ = "2019-2020 ESRF"
__date__ = "09/02/2023"
__date__ = "27/08/2024"

import io
from collections import OrderedDict
Expand All @@ -43,7 +43,7 @@ class EsperantoImage(FabioImage):
"""FabIO image class for Esperanto image files
"""
DESCRIPTION = "CrysAlis Pro Esperanto file format"
DEFAULT_EXTENSIONS = [".eseperanto", ".esper"]
DEFAULT_EXTENSIONS = ["eseperanto", "esper"]
HEADER_SEPARATOR = "\x0d\x0a"
HEADER_END = b"\x0d\x1a"
HEADER_LINES = 25
Expand Down
9 changes: 4 additions & 5 deletions src/fabio/fabioformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
__contact__ = "valentin.valls@esrf.eu"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "02/05/2024"
__date__ = "23/08/2024"
__status__ = "stable"
__docformat__ = 'restructuredtext'

Expand Down Expand Up @@ -195,6 +195,7 @@ def _get_extension_mapping():
if not hasattr(codec, "DEFAULT_EXTENSIONS"):
continue
for ext in codec.DEFAULT_EXTENSIONS:
ext = ext.strip(".")
if ext not in _extension_cache:
_extension_cache[ext] = []
_extension_cache[ext].append(codec)
Expand All @@ -208,8 +209,8 @@ def get_classes_from_extension(extension):
:param str extension: File extension, for example "edf"
:return: fabio image class
"""
extension = extension.lower().strip(".")
mapping = _get_extension_mapping()
extension = extension.lower()
if extension in mapping:
# clone the list
return list(mapping[extension])
Expand All @@ -224,9 +225,7 @@ def is_extension_supported(extension):
:param str format_name: Format name, for example, "edfimage"
:return: instance of the new class
"""
mapping = _get_extension_mapping()
extension = extension.lower()
return extension in mapping
return bool(get_classes_from_extension(extension))


def factory(name):
Expand Down
4 changes: 2 additions & 2 deletions src/fabio/sparseimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
__contact__ = "jerome.kieffer@esrf.fr"
__license__ = "MIT"
__copyright__ = "2020 ESRF"
__date__ = "19/03/2024"
__date__ = "23/08/2024"

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -119,7 +119,7 @@ class SparseImage(FabioImage):

DESCRIPTION = "spasify-Bragg"

DEFAULT_EXTENSIONS = [".h5", ".hdf5", ".nxs"]
DEFAULT_EXTENSIONS = ["h5", "hdf5", "nxs"]

NOISY = False

Expand Down
3 changes: 3 additions & 0 deletions src/fabio/test/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class MyFormat2(fabio.fabioimage.FabioImage):
fabio.register(MyFormat2)
self.assertIsNotNone(fabioformats.get_class_by_name("myformat2"))

def test_extenstion_registry(self):
for ext in fabioformats._get_extension_mapping():
self.assertFalse("." in ext)

def suite():
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
Expand Down

0 comments on commit 96679bf

Please sign in to comment.