Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into blockmiddleware-exten…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
MiWeiss committed Jan 18, 2024
2 parents 66251a8 + ab3c73c commit b7d20cb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
8 changes: 4 additions & 4 deletions bibtexparser/middlewares/enclosing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def __init__(self, allow_inplace_modification: bool = True):
)

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return REMOVED_ENCLOSING_KEY

@staticmethod
Expand Down Expand Up @@ -109,8 +109,8 @@ def __init__(
self._enclose_integers = enclose_integers

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "remove_enclosing"

def _enclose(
Expand Down
4 changes: 2 additions & 2 deletions bibtexparser/middlewares/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def __init__(self, allow_inplace_modification: bool = True):
super().__init__(allow_inplace_modification)

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "ResolveStringReferences"

# docstr-coverage: inherited
Expand Down
8 changes: 3 additions & 5 deletions bibtexparser/middlewares/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ class BlockMiddleware(Middleware, abc.ABC):
except if `allow_inplace_modification` is true.
"""

@staticmethod
@abc.abstractmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
"""Identifier of the middleware.
This key is used to identify the middleware in a blocks metadata.
"""
pass
return cls.__name__

# docstr-coverage: inherited
def transform(self, library: "Library") -> "Library":
Expand Down
12 changes: 6 additions & 6 deletions bibtexparser/middlewares/month.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class MonthLongStringMiddleware(_MonthInterpolator):
and unenclosed."""

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "MonthLongStringMiddleware"

# docstr-coverage: inherited
Expand Down Expand Up @@ -124,8 +124,8 @@ class MonthAbbreviationMiddleware(_MonthInterpolator):
The created abbreviations are always lowercase and unenclosed."""

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "MonthAbbreviationMiddleware"

# docstr-coverage: inherited
Expand Down Expand Up @@ -159,8 +159,8 @@ class MonthIntMiddleware(_MonthInterpolator):
The created int-months are always integers and unenclosed."""

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "MonthIntMiddleware"

# docstr-coverage: inherited
Expand Down
16 changes: 8 additions & 8 deletions bibtexparser/middlewares/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class SeparateCoAuthors(_NameTransformerMiddleware):
"""Middleware to separate multi-person fields (e.g. co-authors, co-editors)."""

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "separate_coauthors"

# docstr-coverage: inherited
Expand All @@ -75,8 +75,8 @@ class MergeCoAuthors(_NameTransformerMiddleware):
"""Middleware to merge multi-person-list fields (e.g. co-authors, co-editors)."""

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "merge_coauthors"

# docstr-coverage: inherited
Expand Down Expand Up @@ -123,8 +123,8 @@ class SplitNameParts(_NameTransformerMiddleware):
"""

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "split_name_parts"

def _transform_field_value(self, name) -> List[NameParts]:
Expand All @@ -145,8 +145,8 @@ class MergeNameParts(_NameTransformerMiddleware):
"""

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "merge_name_parts"

def _transform_field_value(self, name) -> List[str]:
Expand Down
8 changes: 4 additions & 4 deletions bibtexparser/middlewares/sorting_entry_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def transform_entry(self, entry: Entry, library: Library) -> Block:
return entry

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "sorted_fields_alphabetically"


Expand Down Expand Up @@ -71,6 +71,6 @@ def _sort_key(field):
return entry

# docstr-coverage: inherited
@staticmethod
def metadata_key() -> str:
@classmethod
def metadata_key(cls) -> str:
return "sorted_fields_custom"
6 changes: 0 additions & 6 deletions tests/middleware_tests/test_block_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def __init__(self, const):
def transform_block(self, block, library):
return self._const

def metadata_key():
return "ConstantBlockMiddleware"


class LambdaBlockMiddleware(BlockMiddleware):
"""A middleware that applies a lambda to the input block"""
Expand All @@ -44,9 +41,6 @@ def __init__(self, f):
def transform_block(self, block, library):
return self._f(block)

def metadata_key():
return "LambdaBlockMiddleware"


@pytest.mark.parametrize(
("middleware", "expected"),
Expand Down

0 comments on commit b7d20cb

Please sign in to comment.