Skip to content
Snippets Groups Projects
Commit 170bfc8d authored by Andi Gerken's avatar Andi Gerken
Browse files

Merge branch 'error-codes' into 'master'

Fix #12: Return error codes instead of ouput text

Closes #12

See merge request !13
parents 81dec7eb 636b8416
No related branches found
No related tags found
1 merge request!13Fix #12: Return error codes instead of ouput text
Pipeline #37802 passed
...@@ -8,7 +8,7 @@ from setuptools import setup, find_packages ...@@ -8,7 +8,7 @@ from setuptools import setup, find_packages
entry_points = { entry_points = {
"console_scripts": [ "console_scripts": [
"robofish-io-validate=robofish.io.app:validate", "robofish-io-validate=robofish.io.app:validate",
"robofish-io-print=robofish.io.app:print", "robofish-io-print=robofish.io.app:print_file",
# TODO: This should be called robofish-evaluate which is not possible because of the package name (guess) ask moritzs # TODO: This should be called robofish-evaluate which is not possible because of the package name (guess) ask moritzs
"robofish-io-evaluate=robofish.evaluate.app:evaluate", "robofish-io-evaluate=robofish.evaluate.app:evaluate",
] ]
...@@ -48,7 +48,14 @@ setup( ...@@ -48,7 +48,14 @@ setup(
version=source_version(), version=source_version(),
author="", author="",
author_email="", author_email="",
install_requires=["h5py>=3.1.0", "numpy", "seaborn", "pandas", "deprecation"], install_requires=[
"h5py>=3.1.0",
"numpy",
"seaborn",
"pandas",
"deprecation",
"tqdm",
],
classifiers=[ classifiers=[
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research", "Intended Audience :: Science/Research",
......
...@@ -15,7 +15,7 @@ import argparse ...@@ -15,7 +15,7 @@ import argparse
import logging import logging
def print(args=None): def print_file(args=None):
"""This function can be used to print hdf5 files from the command line """This function can be used to print hdf5 files from the command line
Returns: Returns:
...@@ -39,12 +39,11 @@ def print(args=None): ...@@ -39,12 +39,11 @@ def print(args=None):
sf = robofish.io.File(path=args.path, strict_validate=False) sf = robofish.io.File(path=args.path, strict_validate=False)
output_str = sf.to_string(args.output_format) print(sf.to_string(args.output_format))
output_str += "\n" print()
output_str += ( valid = sf.validate(strict_validate=False)[0]
"Valid file" if sf.validate(strict_validate=False)[0] else "Invalid file" print("Valid file" if valid else "Invalid file")
) return not valid
return output_str
def validate(args=None): def validate(args=None):
...@@ -93,10 +92,11 @@ def validate(args=None): ...@@ -93,10 +92,11 @@ def validate(args=None):
return sf_dict return sf_dict
max_filename_width = max([len((str)(f)) for f in sf_dict.keys()]) max_filename_width = max([len((str)(f)) for f in sf_dict.keys()])
text = "" error_code = 0
for file, sf in sf_dict.items(): for file, sf in sf_dict.items():
filled_file = (str)(file).ljust(max_filename_width + 3) filled_file = (str)(file).ljust(max_filename_width + 3)
validity, validity_message = sf.validate(strict_validate=False) validity, validity_message = sf.validate(strict_validate=False)
text += f"{filled_file}:{validity}\t{validity_message}\n" if not validity:
error_code = 1
return text print(f"{filled_file}:{validity}\t{validity_message}")
return error_code
...@@ -32,9 +32,9 @@ def test_app_print(): ...@@ -32,9 +32,9 @@ def test_app_print():
self.path = path self.path = path
self.output_format = output_format self.output_format = output_format
app.print( app.print_file(
DummyArgs(utils.full_path(__file__, "../../resources/valid.hdf5"), "full") DummyArgs(utils.full_path(__file__, "../../resources/valid.hdf5"), "full")
) )
app.print( app.print_file(
DummyArgs(utils.full_path(__file__, "../../resources/valid.hdf5"), "shape") DummyArgs(utils.full_path(__file__, "../../resources/valid.hdf5"), "shape")
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment