diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 572d098..9913b44 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,4 +17,4 @@ jobs: - uses: TrueBrain/actions-flake8@v2 with: flake8_version: 6.0.0 - plugins: flake8-isort==6.1.1 flake8-quotes==3.4.0 + plugins: flake8-isort==6.1.1 flake8-quotes==3.4.0 flake8-commas==4.0.0 diff --git a/mandible/metadata_mapper/format/format.py b/mandible/metadata_mapper/format/format.py index cda2cb1..9bf54bc 100644 --- a/mandible/metadata_mapper/format/format.py +++ b/mandible/metadata_mapper/format/format.py @@ -124,7 +124,7 @@ class _PlaceholderBase(FileFormat, register=False): def __init__(self, dep: str): raise Exception( f"{dep} must be installed to use the {self.__class__.__name__} " - "format class" + "format class", ) @staticmethod diff --git a/mandible/metadata_mapper/mapper.py b/mandible/metadata_mapper/mapper.py index 7f71d0e..a84dc62 100644 --- a/mandible/metadata_mapper/mapper.py +++ b/mandible/metadata_mapper/mapper.py @@ -48,7 +48,7 @@ def get_metadata(self, context: Context) -> Template: raise except Exception as e: raise MetadataMapperError( - f"failed to cache source keys: {e}" + f"failed to cache source keys: {e}", ) from e for name, source in sources.items(): @@ -66,7 +66,7 @@ def get_metadata(self, context: Context) -> Template: raise except Exception as e: raise MetadataMapperError( - f"failed to evaluate template: {e}" + f"failed to evaluate template: {e}", ) from e def _prepare_directives(self, context: Context, sources: dict[str, Source]): @@ -95,7 +95,7 @@ def _replace_template( if isinstance(template, dict): directive_name = self._get_directive_name( template, - debug_path + debug_path, ) if directive_name is not None: debug_path = f"{debug_path}.{directive_name}" @@ -112,13 +112,13 @@ def _replace_template( ) for k, v in template[directive_name].items() }, - debug_path + debug_path, ) try: return directive.call() except Exception as e: raise MetadataMapperError( - f"failed to call directive at {debug_path}: {e}" + f"failed to call directive at {debug_path}: {e}", ) from e return { @@ -160,7 +160,7 @@ def _get_directive_name( raise TemplateError( "multiple directives found in config: " f"{', '.join(repr(d) for d in directive_names)}", - debug_path + debug_path, ) return directive_names[0] @@ -177,7 +177,7 @@ def _get_directive( if cls is None: raise TemplateError( f"invalid directive {repr(directive_name)}", - debug_path + debug_path, ) argspec = inspect.getfullargspec(cls.__init__) @@ -186,7 +186,7 @@ def _get_directive( required_keys = set( argspec.args[3:-len(argspec.defaults)] if argspec.defaults else - argspec.args[3:] + argspec.args[3:], ) config_keys = set(config.keys()) diff = required_keys - config_keys @@ -198,7 +198,7 @@ def _get_directive( raise TemplateError( f"missing key{s}: " f"{', '.join(repr(d) for d in sorted(diff))}", - debug_path + debug_path, ) # For forward compatibility, ignore any unexpected keys diff --git a/mandible/metadata_mapper/source.py b/mandible/metadata_mapper/source.py index f702996..acbe500 100644 --- a/mandible/metadata_mapper/source.py +++ b/mandible/metadata_mapper/source.py @@ -55,6 +55,6 @@ def query_all_values(self, context: Context): "%s: using keys %r, got new values %r", self, keys, - new_values + new_values, ) self._values.update(new_values) diff --git a/mandible/metadata_mapper/source_provider.py b/mandible/metadata_mapper/source_provider.py index a32accf..b3a2a47 100644 --- a/mandible/metadata_mapper/source_provider.py +++ b/mandible/metadata_mapper/source_provider.py @@ -72,7 +72,7 @@ def _create_object( cls_name = config.get("class") if cls_name is None: raise SourceProviderError( - f"missing key 'class' in config {config}" + f"missing key 'class' in config {config}", ) # TODO(reweeden): As of python3.10, inspect.get_annotations(parent_cls) diff --git a/mandible/metadata_mapper/storage/storage.py b/mandible/metadata_mapper/storage/storage.py index a6854ae..3feb5b6 100644 --- a/mandible/metadata_mapper/storage/storage.py +++ b/mandible/metadata_mapper/storage/storage.py @@ -43,7 +43,7 @@ class _PlaceholderBase(Storage, register=False): def __init__(self, dep: str): raise Exception( f"{dep} must be installed to use the {self.__class__.__name__} " - "format class" + "format class", ) def open_file(self, context: Context) -> IO[bytes]: diff --git a/tests/test_source_provider.py b/tests/test_source_provider.py index 888639d..5b3e404 100644 --- a/tests/test_source_provider.py +++ b/tests/test_source_provider.py @@ -56,23 +56,23 @@ def test_config_source_provider(sources): "storage": { "class": "LocalFile", "filters": { - "name": "foo" - } + "name": "foo", + }, }, "format": { - "class": "Json" - } + "class": "Json", + }, }, "bar": { "storage": { "class": "LocalFile", "filters": { - "name": "bar" - } + "name": "bar", + }, }, "format": { - "class": "Json" - } + "class": "Json", + }, }, "baz": { "storage": { @@ -145,35 +145,35 @@ def test_config_source_provider_all_formats(): "storage": { "class": "LocalFile", "filters": { - "name": "foo" - } + "name": "foo", + }, }, "format": { - "class": "Json" - } + "class": "Json", + }, }, "xml": { "storage": { "class": "LocalFile", "filters": { - "name": "bar" - } + "name": "bar", + }, }, "format": { - "class": "Xml" - } + "class": "Xml", + }, }, "h5": { "storage": { "class": "LocalFile", "filters": { - "name": "baz" - } + "name": "baz", + }, }, "format": { - "class": "H5" - } - } + "class": "H5", + }, + }, }) assert provider.get_sources() == { @@ -237,9 +237,9 @@ def test_config_source_provider_missing_storage(): provider = ConfigSourceProvider({ "source": { "format": { - "class": "Json" - } - } + "class": "Json", + }, + }, }) with pytest.raises( @@ -256,9 +256,9 @@ def test_config_source_provider_invalid_storage(): provider = ConfigSourceProvider({ "source": { "storage": { - "class": "NotARealStorage" - } - } + "class": "NotARealStorage", + }, + }, }) with pytest.raises( @@ -266,7 +266,7 @@ def test_config_source_provider_invalid_storage(): match=( "failed to create source 'source': " "invalid storage type 'NotARealStorage'" - ) + ), ): provider.get_sources() @@ -277,9 +277,9 @@ def test_config_source_provider_invalid_storage_kwargs(cls_name): "source": { "storage": { "class": cls_name, - "invalid_arg": 1 - } - } + "invalid_arg": 1, + }, + }, }) with pytest.raises( @@ -288,7 +288,7 @@ def test_config_source_provider_invalid_storage_kwargs(cls_name): "failed to create source 'source': " rf"({cls_name}\.)?__init__\(\) got an unexpected keyword argument " "'invalid_arg'" - ) + ), ): provider.get_sources() @@ -297,9 +297,9 @@ def test_config_source_provider_missing_format(): provider = ConfigSourceProvider({ "source": { "storage": { - "class": "S3File" - } - } + "class": "S3File", + }, + }, }) with pytest.raises( @@ -316,12 +316,12 @@ def test_config_source_provider_invalid_format(): provider = ConfigSourceProvider({ "source": { "storage": { - "class": "S3File" + "class": "S3File", }, "format": { - "class": "NotARealFormat" - } - } + "class": "NotARealFormat", + }, + }, }) with pytest.raises( @@ -329,7 +329,7 @@ def test_config_source_provider_invalid_format(): match=( "failed to create source 'source': " "invalid format type 'NotARealFormat'" - ) + ), ): provider.get_sources() @@ -339,7 +339,7 @@ def test_config_source_provider_invalid_format_kwargs(cls_name): provider = ConfigSourceProvider({ "source": { "storage": { - "class": "S3File" + "class": "S3File", }, "format": { "class": cls_name, @@ -354,6 +354,6 @@ def test_config_source_provider_invalid_format_kwargs(cls_name): "failed to create source 'source': " rf"({cls_name}\.)?__init__\(\) got an unexpected keyword argument " "'invalid_arg'" - ) + ), ): provider.get_sources() diff --git a/tests/test_storage.py b/tests/test_storage.py index ff6b0e6..7e5baa9 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -42,8 +42,8 @@ def test_local_file(data_path): context = Context( files=[{ "name": "local_file", - "path": str(data_path / "local_file.txt") - }] + "path": str(data_path / "local_file.txt"), + }], ) storage = LocalFile(filters={"name": "local_file"}) @@ -55,8 +55,8 @@ def test_local_file_name_match(data_path): context = Context( files=[{ "name": "local_file", - "path": str(data_path / "local_file.txt") - }] + "path": str(data_path / "local_file.txt"), + }], ) storage = LocalFile(filters={"name": "local_.*"}) @@ -68,8 +68,8 @@ def test_local_file_int_filter(data_path): context = Context( files=[{ "type": 0, - "path": str(data_path / "local_file.txt") - }] + "path": str(data_path / "local_file.txt"), + }], ) storage = LocalFile(filters={"type": 0}) @@ -84,7 +84,7 @@ def test_local_file_creation(): def test_local_file_name_match_error(): context = Context( - files=[{"name": "local_file"}] + files=[{"name": "local_file"}], ) storage = LocalFile(filters={"name": "foo.*"}) @@ -110,8 +110,8 @@ def test_s3_file_s3uri(s3_resource): files=[{ "name": "s3_file", "bucket": "test-bucket", - "key": "bucket_file.txt" - }] + "key": "bucket_file.txt", + }], ) storage = S3File(filters={"name": "s3_file"}) @@ -129,8 +129,8 @@ def test_s3_file_s3fs_kwargs(s3_resource): files=[{ "name": "s3_file", "bucket": "test-bucket", - "key": "bucket_file.txt" - }] + "key": "bucket_file.txt", + }], ) storage = S3File( filters={"name": "s3_file"}, @@ -161,24 +161,24 @@ def create_file(bucket, name, contents=None, type="data"): "type": type, "uri": f"https://example.asf.alaska.edu/{name}", "bucket": bucket.name, - "key": name + "key": name, } context = Context( files=[ create_file(bucket, "file1.txt"), create_file(bucket, "file2.txt", type="metadata"), - ] + ], ) storage = S3File(filters={ - "name": "file1.txt" + "name": "file1.txt", }) with storage.open_file(context) as f: assert f.read() == b"Content from file1.txt\n" storage = S3File(filters={ - "type": "metadata" + "type": "metadata", }) with storage.open_file(context) as f: assert f.read() == b"Content from file2.txt\n"