From f5719ed12a15ab5782c7d859d21af3054f416565 Mon Sep 17 00:00:00 2001 From: Stefano Fiorucci Date: Tue, 9 Apr 2024 14:47:36 +0200 Subject: [PATCH 1/2] fix release notes generation on github release workflow (#7515) --- .github/workflows/github_release.yml | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github_release.yml b/.github/workflows/github_release.yml index 1db8cd555f..0c33fdfb88 100644 --- a/.github/workflows/github_release.yml +++ b/.github/workflows/github_release.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: # this is useful to re-generate the release page without a new tag being pushed push: tags: - - "v2.0.0-beta*" + - "v2.[0-9]+.[0-9]+*" jobs: generate-notes: @@ -28,9 +28,33 @@ jobs: python -m pip install --upgrade pip pip install "reno<5" - - name: Generate release notes for beta versions + - name: Generate release notes for release candidates - minor releases + if: steps.version.outputs.current_pre_release != '' && endsWith(steps.version.outputs.current_release, '.0') + env: + # When generating notes for release candidates of minor versions, pick every vX.Y.Z-rcN but + # stop when encounter vX.Y.Z-rc0. The -rc0 tag is added automatically when + # we create the release branch, so we can assume it's always there. + EARLIEST_VERSION: v${{ steps.version.outputs.current_release }}-rc0 run: | - reno report --no-show-source --ignore-cache --version v${{ steps.version.outputs.current_release }}-${{ steps.version.outputs.current_pre_release }} -o relnotes.rst + reno report --no-show-source --ignore-cache --earliest-version "$EARLIEST_VERSION" -o relnotes.rst + + - name: Generate release notes for release candidates - bugfix releases + if: steps.version.outputs.current_pre_release != '' && !endsWith(steps.version.outputs.current_release, '.0') + env: + # When generating notes for release candidates of bugfix releases, pick every vX.Y.Z-rcN but + # stop when encounter vX.Y.Z-rc1. + # In this case, we don't have the -rc0 tag, because we don't need to go through commits on main, + # as we cherry-pick them into the release branch. + EARLIEST_VERSION: v${{ steps.version.outputs.current_release }}-rc1 + run: | + reno report --no-show-source --ignore-cache --earliest-version "$EARLIEST_VERSION" -o relnotes.rst + + - name: Generate release notes for the final release + if: steps.version.outputs.current_pre_release == '' + # When generating notes for the final release vX.Y.Z, we just pass --version and reno + # will automatically collapse all the vX.Y.Z-rcN. + run: | + reno report --no-show-source --ignore-cache --version v${{ steps.version.outputs.current_release }} -o relnotes.rst - name: Convert to Markdown uses: docker://pandoc/core:3.1 From d9c861e22384e82ba03b79f2aaeda69a7c8dbf21 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Tue, 9 Apr 2024 16:06:56 +0200 Subject: [PATCH 2/2] Fixing docstrings (#7513) * wip * some more docstring fixes * reverting to make type checker pass --- haystack/dataclasses/chat_message.py | 1 + haystack/dataclasses/document.py | 1 + .../in_memory/document_store.py | 1 + haystack/lazy_imports.py | 5 ++-- haystack/testing/document_store.py | 1 + haystack/utils/auth.py | 29 ++++++++++++------- haystack/utils/hf.py | 6 ++++ 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/haystack/dataclasses/chat_message.py b/haystack/dataclasses/chat_message.py index 941c92e99f..d051aa68b9 100644 --- a/haystack/dataclasses/chat_message.py +++ b/haystack/dataclasses/chat_message.py @@ -31,6 +31,7 @@ class ChatMessage: def to_openai_format(self) -> Dict[str, Any]: """ Convert the message to the format expected by OpenAI's Chat API. + See the [API reference](https://platform.openai.com/docs/api-reference/chat/create) for details. :returns: A dictionary with the following key: diff --git a/haystack/dataclasses/document.py b/haystack/dataclasses/document.py index ddf762bf45..8e2cb872c9 100644 --- a/haystack/dataclasses/document.py +++ b/haystack/dataclasses/document.py @@ -21,6 +21,7 @@ class _BackwardCompatible(type): def __call__(cls, *args, **kwargs): """ Called before Document.__init__, will remap legacy fields to new ones. + Also handles building a Document from a flattened dictionary. """ # Move `content` to new fields depending on the type diff --git a/haystack/document_stores/in_memory/document_store.py b/haystack/document_stores/in_memory/document_store.py index 4046af966e..3575b3c93a 100644 --- a/haystack/document_stores/in_memory/document_store.py +++ b/haystack/document_stores/in_memory/document_store.py @@ -138,6 +138,7 @@ def write_documents(self, documents: List[Document], policy: DuplicatePolicy = D def delete_documents(self, document_ids: List[str]) -> None: """ Deletes all documents with matching document_ids from the DocumentStore. + :param document_ids: The object_ids to delete. """ for doc_id in document_ids: diff --git a/haystack/lazy_imports.py b/haystack/lazy_imports.py index 98b71ccc87..003d43dca7 100644 --- a/haystack/lazy_imports.py +++ b/haystack/lazy_imports.py @@ -8,8 +8,9 @@ class LazyImport(_DeferredImportExceptionContextManager): """ - Wrapper on top of lazy_import's _DeferredImportExceptionContextManager that adds the possibility to customize the - error messages. + Wrapper on top of lazy_import's _DeferredImportExceptionContextManager. + + It adds the possibility to customize the error messages. """ def __init__(self, message: str = DEFAULT_IMPORT_ERROR_MSG) -> None: diff --git a/haystack/testing/document_store.py b/haystack/testing/document_store.py index 343ff8617b..160414e60a 100644 --- a/haystack/testing/document_store.py +++ b/haystack/testing/document_store.py @@ -174,6 +174,7 @@ class FilterableDocsFixtureMixin: @pytest.fixture def filterable_docs(self) -> List[Document]: + """Fixture that returns a list of Documents that can be used to test filtering.""" documents = [] for i in range(3): documents.append( diff --git a/haystack/utils/auth.py b/haystack/utils/auth.py index 81289dbdaf..7d3cdda6d0 100644 --- a/haystack/utils/auth.py +++ b/haystack/utils/auth.py @@ -14,8 +14,13 @@ def __str__(self): @staticmethod def from_str(string: str) -> "SecretType": - map = {e.value: e for e in SecretType} - type = map.get(string) + """ + Convert a string to a SecretType. + + :param string: The string to convert. + """ + mapping = {e.value: e for e in SecretType} + type = mapping.get(string) if type is None: raise ValueError(f"Unknown secret type '{string}'") return type @@ -47,10 +52,9 @@ def from_token(token: str) -> "Secret": @staticmethod def from_env_var(env_vars: Union[str, List[str]], *, strict: bool = True) -> "Secret": """ - Create an environment variable-based secret. Accepts - one or more environment variables. Upon resolution, it - returns a string token from the first environment variable - that is set. + Create an environment variable-based secret. Accepts one or more environment variables. + + Upon resolution, it returns a string token from the first environment variable that is set. :param env_vars: A single environment variable or an ordered list of @@ -66,6 +70,7 @@ def from_env_var(env_vars: Union[str, List[str]], *, strict: bool = True) -> "Se def to_dict(self) -> Dict[str, Any]: """ Convert the secret to a JSON-serializable dictionary. + Some secrets may not be serializable. :returns: @@ -94,8 +99,7 @@ def from_dict(dict: Dict[str, Any]) -> "Secret": @abstractmethod def resolve_value(self) -> Optional[Any]: """ - Resolve the secret to an atomic value. The semantics - of the value is secret-dependent. + Resolve the secret to an atomic value. The semantics of the value is secret-dependent. :returns: The value of the secret, if any. @@ -124,6 +128,7 @@ def _from_dict(dict: Dict[str, Any]) -> "Secret": class TokenSecret(Secret): """ A secret that uses a string token/API key. + Cannot be serialized. """ @@ -149,10 +154,12 @@ def _from_dict(dict: Dict[str, Any]) -> "Secret": ) def resolve_value(self) -> Optional[Any]: + """Return the token.""" return self._token @property def type(self) -> SecretType: + """The type of the secret.""" return self._type @@ -160,8 +167,8 @@ def type(self) -> SecretType: class EnvVarSecret(Secret): """ A secret that accepts one or more environment variables. - Upon resolution, it returns a string token from the first - environment variable that is set. Can be serialized. + + Upon resolution, it returns a string token from the first environment variable that is set. Can be serialized. """ _env_vars: Tuple[str, ...] @@ -183,6 +190,7 @@ def _from_dict(dict: Dict[str, Any]) -> "Secret": return EnvVarSecret(tuple(dict["env_vars"]), _strict=dict["strict"]) def resolve_value(self) -> Optional[Any]: + """Resolve the secret to an atomic value. The semantics of the value is secret-dependent.""" out = None for env_var in self._env_vars: value = os.getenv(env_var) @@ -195,6 +203,7 @@ def resolve_value(self) -> Optional[Any]: @property def type(self) -> SecretType: + """The type of the secret.""" return self._type diff --git a/haystack/utils/hf.py b/haystack/utils/hf.py index 48f3b9819e..6e7d539bec 100644 --- a/haystack/utils/hf.py +++ b/haystack/utils/hf.py @@ -74,6 +74,12 @@ def __str__(self): @staticmethod def from_str(string: str) -> "HFEmbeddingAPIType": + """ + Convert a string to a HFEmbeddingAPIType enum. + + :param string: + :return: The corresponding HFEmbeddingAPIType enum. + """ enum_map = {e.value: e for e in HFEmbeddingAPIType} mode = enum_map.get(string) if mode is None: