diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f8f902..b114b79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,10 +34,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `fiboa validate`: - Is more robust against invalid collections and doesn't abort if not needed - Check NULL values correctly in case of arrays + - Throw an error if no files were provided - `fiboa create-geojson`: - Handles GeoParquet bbox correctly - Converts numpy arrays - Doesn't export empty collections +- Fix recursive import ## [v0.3.10] - 2024-05-06 diff --git a/fiboa_cli/__init__.py b/fiboa_cli/__init__.py index 5e5a08e..1f67f86 100644 --- a/fiboa_cli/__init__.py +++ b/fiboa_cli/__init__.py @@ -119,6 +119,11 @@ def validate(files, schema, ext_schema, fiboa_version, collection, data, timer): "collection": collection, "data": data, } + + if len(files) == 0: + log("No files to validate", "error") + sys.exit(1) + exit = 0 for file in files: log(f"Validating {file}", "info") diff --git a/fiboa_cli/convert.py b/fiboa_cli/convert.py index 3ad6f58..d648ec1 100644 --- a/fiboa_cli/convert.py +++ b/fiboa_cli/convert.py @@ -1,10 +1,11 @@ import importlib import os -from . import datasets + +IGNORED_DATASET_FILES = ["__init__.py", "template.py"] def convert(dataset, output_file, cache_file = None, source_coop_url = None, collection = False, compression = None): - if dataset == "template": - raise Exception(f"Converter for dataset 'template' not available") + if dataset in IGNORED_DATASET_FILES: + raise Exception(f"'{dataset}' is not a converter") try: converter = read_converter(dataset) except ImportError as e: @@ -13,9 +14,9 @@ def convert(dataset, output_file, cache_file = None, source_coop_url = None, col converter.convert(output_file, cache_file = cache_file, source_coop_url = source_coop_url, collection = collection, compression = compression) def list_all_converter_ids(): + datasets = importlib.import_module(".datasets", package="fiboa_cli") files = os.listdir(datasets.__path__[0]) - ignore = ["__init__.py", "template.py"] - return [f[:-3] for f in files if f.endswith(".py") and f not in ignore] + return [f[:-3] for f in files if f.endswith(".py") and f not in IGNORED_DATASET_FILES] def list_all_converters(keys): converters = {} diff --git a/fiboa_cli/datasets/__init__.py b/fiboa_cli/datasets/__init__.py new file mode 100644 index 0000000..e69de29