Skip to content

Commit 4058882

Browse files
fixing some more docstrings (#7530)
* some more docstring fixes * some more docstring fixes
1 parent e4013c6 commit 4058882

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

haystack/core/component/sockets.py

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(
8383
def __setitem__(self, key: str, socket: Union[InputSocket, OutputSocket]):
8484
"""
8585
Adds a new socket to this Sockets object.
86+
8687
This eases a bit updating the list of sockets after Sockets has been created.
8788
That should happen only in the `component` decorator.
8889
"""

haystack/core/pipeline/descriptions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
def find_pipeline_inputs(graph: networkx.MultiDiGraph) -> Dict[str, List[InputSocket]]:
1616
"""
17-
Collect components that have disconnected input sockets. Note that this method returns *ALL* disconnected
18-
input sockets, including all such sockets with default values.
17+
Collect components that have disconnected input sockets.
18+
19+
Note that this method returns *ALL* disconnected input sockets, including all such sockets with default values.
1920
"""
2021
return {
2122
name: [socket for socket in data.get("input_sockets", {}).values() if not socket.senders or socket.is_variadic]

haystack/core/pipeline/pipeline.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def __init__(
7676

7777
def __eq__(self, other) -> bool:
7878
"""
79+
Pipeline equality is defined by the equality of their serialized form.
80+
7981
Equal pipelines share every metadata, node and edge, but they're not required to use
8082
the same node instances: this allows pipeline saved and then loaded back to be equal to themselves.
8183
"""
@@ -108,6 +110,7 @@ def __repr__(self) -> str:
108110
def to_dict(self) -> Dict[str, Any]:
109111
"""
110112
Serializes the pipeline to a dictionary.
113+
111114
This is meant to be an intermediate representation but it can be also used to save a pipeline to file.
112115
113116
:returns:
@@ -189,8 +192,7 @@ def from_dict(
189192

190193
def dumps(self, marshaller: Marshaller = DEFAULT_MARSHALLER) -> str:
191194
"""
192-
Returns the string representation of this pipeline according to the
193-
format dictated by the `Marshaller` in use.
195+
Returns the string representation of this pipeline according to the format dictated by the `Marshaller` in use.
194196
195197
:param marshaller:
196198
The Marshaller used to create the string representation. Defaults to `YamlMarshaller`.
@@ -201,8 +203,7 @@ def dumps(self, marshaller: Marshaller = DEFAULT_MARSHALLER) -> str:
201203

202204
def dump(self, fp: TextIO, marshaller: Marshaller = DEFAULT_MARSHALLER):
203205
"""
204-
Writes the string representation of this pipeline to the file-like object
205-
passed in the `fp` argument.
206+
Writes the string representation of this pipeline to the file-like object passed in the `fp` argument.
206207
207208
:param fp:
208209
A file-like object ready to be written to.
@@ -240,8 +241,7 @@ def load(
240241
callbacks: Optional[DeserializationCallbacks] = None,
241242
) -> "Pipeline":
242243
"""
243-
Creates a `Pipeline` object from the string representation read from the file-like
244-
object passed in the `fp` argument.
244+
Creates a `Pipeline` object from the string representation read from the file-like object passed in the `fp` argument.
245245
246246
:param data:
247247
The string representation of the pipeline, can be `str`, `bytes` or `bytearray`.
@@ -506,9 +506,10 @@ def get_component_name(self, instance: Component) -> str:
506506

507507
def inputs(self) -> Dict[str, Dict[str, Any]]:
508508
"""
509-
Returns a dictionary containing the inputs of a pipeline. Each key in the dictionary
510-
corresponds to a component name, and its value is another dictionary that describes the
511-
input sockets of that component, including their types and whether they are optional.
509+
Returns a dictionary containing the inputs of a pipeline.
510+
511+
Each key in the dictionary corresponds to a component name, and its value is another dictionary that describes
512+
the input sockets of that component, including their types and whether they are optional.
512513
513514
:returns:
514515
A dictionary where each key is a pipeline component name and each value is a dictionary of
@@ -528,9 +529,10 @@ def inputs(self) -> Dict[str, Dict[str, Any]]:
528529

529530
def outputs(self) -> Dict[str, Dict[str, Any]]:
530531
"""
531-
Returns a dictionary containing the outputs of a pipeline. Each key in the dictionary
532-
corresponds to a component name, and its value is another dictionary that describes the
533-
output sockets of that component.
532+
Returns a dictionary containing the outputs of a pipeline.
533+
534+
Each key in the dictionary corresponds to a component name, and its value is another dictionary that describes
535+
the output sockets of that component.
534536
535537
:returns:
536538
A dictionary where each key is a pipeline component name and each value is a dictionary of
@@ -573,6 +575,7 @@ def draw(self, path: Path) -> None:
573575
def walk(self) -> Iterator[Tuple[str, Component]]:
574576
"""
575577
Visits each component in the pipeline exactly once and yields its name and instance.
578+
576579
No guarantees are provided on the visiting order.
577580
578581
:returns:

haystack/core/pipeline/template.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class PredefinedPipeline(Enum):
2222

2323
class PipelineTemplate:
2424
"""
25-
The PipelineTemplate class enables the straightforward creation of flexible and configurable pipelines using
26-
Jinja2 templated YAML files. Specifically designed to simplify the setup of complex data processing pipelines for
25+
The PipelineTemplate class enables the straightforward creation of flexible and configurable pipelines using Jinja2 templated YAML files.
26+
27+
Specifically designed to simplify the setup of complex data processing pipelines for
2728
a range of NLP tasks—including question answering, retriever augmented generation (RAG), document indexing, among
2829
others - PipelineTemplate empowers users to dynamically generate pipeline configurations from templates and
2930
customize components as necessary. Its design philosophy centers on providing an accessible, yet powerful, tool
@@ -60,7 +61,9 @@ class PipelineTemplate:
6061

6162
def __init__(self, template_content: str):
6263
"""
63-
Initialize a PipelineTemplate. Besides calling the constructor directly, a set of utility methods is provided
64+
Initialize a PipelineTemplate.
65+
66+
Besides calling the constructor directly, a set of utility methods is provided
6467
for conveniently create an instance of `PipelineTemplate` from different sources. See `from_string`,
6568
`from_file`, `from_predefined` and `from_url`.
6669
@@ -93,6 +96,7 @@ def render(self, template_params: Optional[Dict[str, Any]] = None) -> str:
9396
def from_file(cls, file_path: Union[Path, str]) -> "PipelineTemplate":
9497
"""
9598
Create a PipelineTemplate from a file.
99+
96100
:param file_path: The path to the file containing the template. Must contain valid Jinja2 syntax.
97101
:returns: An instance of `PipelineTemplate`.
98102
"""
@@ -103,6 +107,7 @@ def from_file(cls, file_path: Union[Path, str]) -> "PipelineTemplate":
103107
def from_predefined(cls, predefined_pipeline: PredefinedPipeline) -> "PipelineTemplate":
104108
"""
105109
Create a PipelineTemplate from a predefined template. See `PredefinedPipeline` for available options.
110+
106111
:param predefined_pipeline: The predefined pipeline to use.
107112
:returns: An instance of `PipelineTemplate `.
108113
"""

haystack/core/serialization.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
@dataclass(frozen=True)
1414
class DeserializationCallbacks:
1515
"""
16-
Callback functions that are invoked in specific
17-
stages of the pipeline deserialization process.
16+
Callback functions that are invoked in specific stages of the pipeline deserialization process.
1817
1918
:param component_pre_init:
2019
Invoked just before a component instance is

haystack/telemetry/_environment.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
def _in_podman() -> bool:
1818
"""
19+
Check if the code is running in a Podman container.
20+
1921
Podman run would create the file /run/.containernv, see:
2022
https://github.com/containers/podman/blob/main/docs/source/markdown/podman-run.1.md.in#L31
2123
"""
@@ -24,6 +26,8 @@ def _in_podman() -> bool:
2426

2527
def _has_dockerenv() -> bool:
2628
"""
29+
Check if the code is running in a Docker container.
30+
2731
This might not work anymore at some point (even if it's been a while now), see:
2832
https://github.com/moby/moby/issues/18355#issuecomment-220484748
2933
"""
@@ -32,16 +36,17 @@ def _has_dockerenv() -> bool:
3236

3337
def _has_docker_cgroup_v1() -> bool:
3438
"""
35-
This only works with cgroups v1
39+
This only works with cgroups v1.
3640
"""
3741
path = "/proc/self/cgroup" # 'self' should be always symlinked to the actual PID
3842
return os.path.isfile(path) and any("docker" in line for line in open(path))
3943

4044

4145
def _has_docker_cgroup_v2() -> bool:
4246
"""
43-
cgroups v2 version, inspired from
44-
https://github.com/jenkinsci/docker-workflow-plugin/blob/master/src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java
47+
Check if the code is running in a Docker container using the cgroups v2 version.
48+
49+
inspired from: https://github.com/jenkinsci/docker-workflow-plugin/blob/master/src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java
4550
"""
4651
path = "/proc/self/mountinfo" # 'self' should be always symlinked to the actual PID
4752
return os.path.isfile(path) and any("/docker/containers/" in line for line in open(path))
@@ -61,8 +66,9 @@ def _is_containerized() -> Optional[bool]:
6166

6267
def collect_system_specs() -> Dict[str, Any]:
6368
"""
64-
Collects meta data about the setup that is used with Haystack, such as:
65-
operating system, python version, Haystack version, transformers version,
69+
Collects meta-data about the setup that is used with Haystack.
70+
71+
Data collected includes: operating system, python version, Haystack version, transformers version,
6672
pytorch version, number of GPUs, execution environment.
6773
6874
These values are highly unlikely to change during the runtime of the pipeline,

0 commit comments

Comments
 (0)