Skip to content

Commit

Permalink
fix code style with flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Nov 25, 2022
1 parent 78c00b8 commit 72a3724
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 53 deletions.
83 changes: 43 additions & 40 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ def has_sse2(self) -> bool:
if self.arch in ('X86_32', 'X86_64'):
if not has_cpu_flag('sse2'):
return False # SSE2 not available on host
return (self.__compiler.compiler_type == 'msvc' or
check_compile_flags(self.__compiler, '-msse2'))
return self.__compiler.compiler_type == "msvc" or check_compile_flags(
self.__compiler, "-msse2"
)
if self.machine == 'ppc64le':
return True
return False # Disabled by default
Expand Down Expand Up @@ -220,7 +221,7 @@ def __init__(
use_avx2=None,
use_openmp=None,
use_native=None,
):
):

self.__config_file = str(config_file)

Expand Down Expand Up @@ -307,7 +308,7 @@ def has_config_changed(self) -> bool:
try:
with open(self.__config_file, 'r') as f:
return f.read() != self.get_config_string()
except:
except: # noqa
pass
return True

Expand All @@ -329,7 +330,7 @@ class Build(build):
('sse2=', None, "Deprecated, use HDF5PLUGIN_SSE2 environment variable"),
('avx2=', None, "Deprecated, use HDF5PLUGIN_AVX2 environment variable"),
('cpp11=', None, "Deprecated, use HDF5PLUGIN_CPP11 environment variable"),
]
]
user_options.extend(build.user_options)

boolean_options = build.boolean_options + ['openmp', 'native', 'sse2', 'avx2', 'cpp11']
Expand Down Expand Up @@ -568,12 +569,12 @@ def prefix(directory, files):
sse2_kwargs = {
'sources': [f for f in glob(blosc_dir + 'blosc/*.c') if 'sse2' in f],
'define_macros': [('SHUFFLE_SSE2_ENABLED', 1)],
}
}

avx2_kwargs = {
'sources': [f for f in glob(blosc_dir + 'blosc/*.c') if 'avx2' in f],
'define_macros': [('SHUFFLE_AVX2_ENABLED', 1)],
}
}

# compression libs
# lz4
Expand Down Expand Up @@ -602,9 +603,9 @@ def prefix(directory, files):
'include_dirs': glob(snappy_dir),
'extra_link_args': ['-lstdc++'],
'define_macros': [('HAVE_SNAPPY', 1)],
}
}

#zlib
# zlib
zlib_sources = glob(blosc_dir + 'internal-complibs/zlib*/*.c')
zlib_depends = glob(blosc_dir + 'internal-complibs/zlib*/*.h')
zlib_include_dirs = glob(blosc_dir + 'internal-complibs/zlib*')
Expand All @@ -615,15 +616,15 @@ def prefix(directory, files):
define_macros.append(('HAVE_ZLIB', 1))

# zstd
zstd_sources = glob(blosc_dir +'internal-complibs/zstd*/*/*.c')
zstd_sources = glob(blosc_dir + 'internal-complibs/zstd*/*/*.c')
if os.environ.get("HDF5PLUGIN_BMI2", 'True') == 'True' and (sys.platform.startswith('linux') or sys.platform.startswith('macos')):
zstd_extra_objects = glob(blosc_dir +'internal-complibs/zstd*/*/*.S')
zstd_extra_objects = glob(blosc_dir + 'internal-complibs/zstd*/*/*.S')
zstd_define_macros = []
else:
zstd_extra_objects = []
zstd_define_macros = [('ZSTD_DISABLE_ASM', 1)]

zstd_depends = glob(blosc_dir +'internal-complibs/zstd*/*/*.h')
zstd_depends = glob(blosc_dir + 'internal-complibs/zstd*/*/*.h')
zstd_include_dirs = glob(blosc_dir + 'internal-complibs/zstd*')
zstd_include_dirs += glob(blosc_dir + 'internal-complibs/zstd*/common')

Expand All @@ -641,19 +642,19 @@ def prefix(directory, files):

blosc_plugin = HDF5PluginExtension(
"hdf5plugin.plugins.libh5blosc",
sources=sources + \
prefix(hdf5_blosc_dir,['blosc_filter.c', 'blosc_plugin.c']),
sources=sources + prefix(
hdf5_blosc_dir, ['blosc_filter.c', 'blosc_plugin.c']),
extra_objects=zstd_extra_objects,
depends=depends + \
prefix(hdf5_blosc_dir, ['blosc_filter.h', 'blosc_plugin.h']),
depends=depends + prefix(
hdf5_blosc_dir, ['blosc_filter.h', 'blosc_plugin.h']),
include_dirs=include_dirs + [hdf5_blosc_dir],
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
sse2=sse2_kwargs,
avx2=avx2_kwargs,
cpp11=cpp11_kwargs,
)
)
PLUGIN_LIB_DEPENDENCIES['blosc'] = 'snappy'


Expand All @@ -670,7 +671,7 @@ def prefix(directory, files):
depends=zstandard_depends,
include_dirs=zstd_include_dirs,
define_macros=zstd_define_macros,
)
)

# bitshuffle (+lz4 or zstd) plugin
# Plugins from https://github.com/kiyo-masui/bitshuffle
Expand All @@ -681,30 +682,31 @@ def prefix(directory, files):
extra_compile_args += ['/Ox', '/fp:fast', '/openmp']
if platform.machine() == "ppc64le":
# Required on ppc64le
sse2_options = {'extra_compile_args': ['-DUSESSE2'] }
sse2_options = {'extra_compile_args': ['-DUSESSE2']}
else:
sse2_options = {}
extra_link_args = ['-fopenmp', '/openmp']
define_macros = [("ZSTD_SUPPORT", 1)]

bithsuffle_plugin = HDF5PluginExtension(
"hdf5plugin.plugins.libh5bshuf",
sources=prefix(bithsuffle_dir,
["src/bshuf_h5plugin.c", "src/bshuf_h5filter.c",
"src/bitshuffle.c", "src/bitshuffle_core.c",
"src/iochain.c", "lz4/lz4.c"]) + zstd_sources,
sources=prefix(bithsuffle_dir, [
"src/bshuf_h5plugin.c", "src/bshuf_h5filter.c",
"src/bitshuffle.c", "src/bitshuffle_core.c",
"src/iochain.c", "lz4/lz4.c"
]) + zstd_sources,
extra_objects=zstd_extra_objects,
depends=prefix(bithsuffle_dir,
["src/bitshuffle.h", "src/bitshuffle_core.h",
"src/iochain.h", 'src/bshuf_h5filter.h',
"lz4/lz4.h"]) + zstd_depends,
depends=prefix(bithsuffle_dir, [
"src/bitshuffle.h", "src/bitshuffle_core.h",
"src/iochain.h", 'src/bshuf_h5filter.h',
"lz4/lz4.h"
]) + zstd_depends,
include_dirs=prefix(bithsuffle_dir, ['src/', 'lz4/']) + zstd_include_dirs,
define_macros=define_macros + zstd_define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
sse2=sse2_options,
)

)


# lz4 plugin
Expand All @@ -721,7 +723,7 @@ def prefix(directory, files):
include_dirs=lz4_include_dirs,
extra_compile_args=extra_compile_args,
libraries=['Ws2_32'] if sys.platform.startswith('win') else [],
)
)


# BZIP2
Expand All @@ -746,7 +748,7 @@ def prefix(directory, files):
include_dirs=['src/PyTables/src/'] + bzip2_include_dirs,
define_macros=[('HAVE_BZ2_LIB', 1)],
extra_compile_args=bzip2_extra_compile_args,
)
)

# FCIDECOMP
fcidecomp_dir = 'src/fcidecomp/FCIDECOMP_V1.0.2/Software/FCIDECOMP_SOURCES'
Expand All @@ -765,10 +767,10 @@ def prefix(directory, files):
depends += glob(fcidecomp_dir + "/" + item + "/include/*.h")
include_dirs += [fcidecomp_dir + "/" + item + "/include",
"src/charls/src"]
#include_dirs += ["src/hdf5"]
# include_dirs += ["src/hdf5"]
cpp11_kwargs = {
'extra_link_args': ['-lstdc++'],
}
}
fcidecomp_plugin = HDF5PluginExtension(
"hdf5plugin.plugins.libh5fcidecomp",
sources=sources,
Expand All @@ -780,7 +782,7 @@ def prefix(directory, files):
cpp11=cpp11_kwargs,
cpp11_required=True,
define_macros=[('CHARLS_STATIC', 1)],
)
)
PLUGIN_LIB_DEPENDENCIES['fcidecomp'] = 'charls'


Expand All @@ -796,7 +798,7 @@ def prefix(directory, files):
cpp11_kwargs = {
'include_dirs': glob('charls_dir/src'),
'extra_link_args': ['-lstdc++'],
}
}

# H5Z-ZFP
h5zfp_dir = 'src/H5Z-ZFP/src'
Expand All @@ -814,7 +816,7 @@ def prefix(directory, files):
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
)
PLUGIN_LIB_DEPENDENCIES['zfp'] = 'zfp'

# zfp
Expand All @@ -825,7 +827,7 @@ def prefix(directory, files):
'sources': zfp_sources,
'include_dirs': zfp_include_dirs,
'cflags': ['-DBIT_STREAM_WORD_TYPE=uint8'],
})
})

# SZ library and its hdf5 filter
sz_dir = os.path.join("src", "SZ", "sz")
Expand Down Expand Up @@ -891,10 +893,11 @@ def apply_filter_strip(libraries, extensions, dependencies):
# Filter out stripped filters
extensions = [
ext for ext in extensions
if isinstance(ext, HDF5PluginExtension) and ext.hdf5_plugin_name not in stripped_filters
if isinstance(ext, HDF5PluginExtension) and ext.hdf5_plugin_name not in stripped_filters
]
return libraries, extensions


libraries, extensions = apply_filter_strip(
libraries=[snappy_lib, charls_lib, zfp_lib],
extensions=[
Expand Down Expand Up @@ -992,9 +995,9 @@ def make_distribution(self):
author = "ESRF - Data Analysis Unit"
author_email = "silx@esrf.fr"
description = "HDF5 Plugins for Windows, MacOS, and Linux"
url='https://github.com/silx-kit/hdf5plugin'
url = 'https://github.com/silx-kit/hdf5plugin'
f = open("README.rst")
long_description=f.read()
long_description = f.read()
f.close()
license = "https://github.com/silx-kit/hdf5plugin/blob/master/LICENSE"
classifiers = ["Development Status :: 5 - Production/Stable",
Expand Down
1 change: 1 addition & 0 deletions src/hdf5plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# Backward compatibility
PLUGINS_PATH = PLUGIN_PATH


def __getattr__(name):
if name == "config":
_logging.getLogger(__name__).warning(
Expand Down
6 changes: 3 additions & 3 deletions src/hdf5plugin/_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ def __init__(self,
minexp = struct.unpack('I', struct.pack('i', int(minexp)))[0]
self.filter_options = 4, 0, minbits, maxbits, maxprec, minexp
logger.info("ZFP mode 4 used. H5Z_ZFP_MODE_EXPERT")

else:
logger.info("ZFP default used")
logger.info("ZFP default used")

logger.info(f"filter options = {self.filter_options}")


Expand Down
14 changes: 8 additions & 6 deletions src/hdf5plugin/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


PLUGIN_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'plugins'))
os.path.join(os.path.dirname(__file__), 'plugins'))
"""Directory where the provided HDF5 filter plugins are stored."""


Expand All @@ -56,7 +56,7 @@ def is_filter_available(name):

hdf5_version = h5py.h5.get_libversion()
if hdf5_version < (1, 8, 20) or (1, 10) <= hdf5_version < (1, 10, 2):
return None # h5z.filter_avail not available
return None # h5z.filter_avail not available
return h5py.h5z.filter_avail(filter_id) > 0


Expand Down Expand Up @@ -177,10 +177,11 @@ def get_filters(filters=tuple(FILTERS.keys())):
raise ValueError(f"Expected int or str, not {type(name_or_id)}")

for cls in FILTER_CLASSES:
if ((isinstance(name_or_id, str) and cls.filter_name == name_or_id.lower()) or
(isinstance(name_or_id, int) and cls.filter_id == name_or_id)):
filter_classes.append(cls)
break
if (
isinstance(name_or_id, str) and cls.filter_name == name_or_id.lower()
) or (isinstance(name_or_id, int) and cls.filter_id == name_or_id):
filter_classes.append(cls)
break
else:
raise ValueError(f"Unknown filter: {name_or_id}")

Expand Down Expand Up @@ -209,4 +210,5 @@ def register(filters=tuple(FILTERS.keys()), force=True):
status = register_filter(filter_name) and status
return status


register(force=False)
2 changes: 1 addition & 1 deletion src/hdf5plugin/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Thus 2.1.0a3 is hexversion 0x020100a3.
"""
from collections import namedtuple

__authors__ = ["Jérôme Kieffer"]
__license__ = "MIT"
Expand Down Expand Up @@ -77,7 +78,6 @@

date = __date__

from collections import namedtuple
_version_info = namedtuple("version_info", ["major", "minor", "micro", "releaselevel", "serial"])

version_info = _version_info(MAJOR, MINOR, MICRO, RELEV, SERIAL)
Expand Down
6 changes: 3 additions & 3 deletions src/hdf5plugin/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def testBitshuffle(self):
for dtype in (numpy.int8, numpy.int16, numpy.int32, numpy.int64):
for nelems in (1024, 2048):
with self.subTest(cname=cname, dtype=dtype, nelems=nelems):
filter_ = self._test('bshuf', dtype, compressed=cname!='none', nelems=nelems, cname=cname)
filter_ = self._test('bshuf', dtype, compressed=cname != 'none', nelems=nelems, cname=cname)
self.assertEqual(filter_[2][3:5], (nelems, compression_ids[cname]))

@unittest.skipUnless(should_test("blosc"), "Blosc filter not available")
Expand All @@ -169,7 +169,7 @@ def testBlosc(self):
self.skipTest("snappy unavailable without C++11")
filter_ = self._test(
'blosc',
compressed=clevel!=0, # No compression for clevel=0
compressed=clevel != 0, # No compression for clevel=0
cname=cname,
clevel=clevel,
shuffle=shuffle)
Expand Down Expand Up @@ -227,7 +227,7 @@ def testZfp(self):
{'lossless': True, 'reversible': True}, # Reversible
# Expert: with default parameters
{'lossless': False, 'minbits': 1, 'maxbits': 16657, 'maxprec': 64, 'minexp': -1074},
]
]
for options in tests:
for dtype in (numpy.float32, numpy.float64):
with self.subTest(options=options, dtype=dtype):
Expand Down

0 comments on commit 72a3724

Please sign in to comment.