Skip to content

Commit

Permalink
Add flake8-commas
Browse files Browse the repository at this point in the history
  • Loading branch information
reweeden committed Jan 24, 2025
1 parent d9c8d94 commit 18526f4
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion mandible/metadata_mapper/format/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions mandible/metadata_mapper/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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]):
Expand Down Expand Up @@ -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}"
Expand All @@ -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 {
Expand Down Expand Up @@ -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]
Expand All @@ -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__)
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mandible/metadata_mapper/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion mandible/metadata_mapper/source_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mandible/metadata_mapper/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
84 changes: 42 additions & 42 deletions tests/test_source_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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() == {
Expand Down Expand Up @@ -237,9 +237,9 @@ def test_config_source_provider_missing_storage():
provider = ConfigSourceProvider({
"source": {
"format": {
"class": "Json"
}
}
"class": "Json",
},
},
})

with pytest.raises(
Expand All @@ -256,17 +256,17 @@ def test_config_source_provider_invalid_storage():
provider = ConfigSourceProvider({
"source": {
"storage": {
"class": "NotARealStorage"
}
}
"class": "NotARealStorage",
},
},
})

with pytest.raises(
SourceProviderError,
match=(
"failed to create source 'source': "
"invalid storage type 'NotARealStorage'"
)
),
):
provider.get_sources()

Expand All @@ -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(
Expand All @@ -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()

Expand All @@ -297,9 +297,9 @@ def test_config_source_provider_missing_format():
provider = ConfigSourceProvider({
"source": {
"storage": {
"class": "S3File"
}
}
"class": "S3File",
},
},
})

with pytest.raises(
Expand All @@ -316,20 +316,20 @@ def test_config_source_provider_invalid_format():
provider = ConfigSourceProvider({
"source": {
"storage": {
"class": "S3File"
"class": "S3File",
},
"format": {
"class": "NotARealFormat"
}
}
"class": "NotARealFormat",
},
},
})

with pytest.raises(
SourceProviderError,
match=(
"failed to create source 'source': "
"invalid format type 'NotARealFormat'"
)
),
):
provider.get_sources()

Expand All @@ -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,
Expand All @@ -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()
Loading

0 comments on commit 18526f4

Please sign in to comment.