waldiez 0.5.10__py3-none-any.whl → 0.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of waldiez might be problematic. Click here for more details.
- waldiez/__init__.py +1 -1
- waldiez/_version.py +1 -1
- waldiez/cli.py +19 -7
- waldiez/cli_extras/jupyter.py +3 -0
- waldiez/cli_extras/runner.py +3 -1
- waldiez/cli_extras/studio.py +3 -1
- waldiez/exporter.py +9 -3
- waldiez/exporting/agent/exporter.py +15 -16
- waldiez/exporting/agent/extras/captain_agent_extras.py +6 -6
- waldiez/exporting/agent/extras/doc_agent_extras.py +6 -6
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +40 -24
- waldiez/exporting/agent/extras/group_member_extras.py +6 -5
- waldiez/exporting/agent/extras/handoffs/after_work.py +2 -1
- waldiez/exporting/agent/extras/handoffs/available.py +2 -1
- waldiez/exporting/agent/extras/handoffs/condition.py +3 -2
- waldiez/exporting/agent/extras/handoffs/handoff.py +2 -1
- waldiez/exporting/agent/extras/handoffs/target.py +7 -4
- waldiez/exporting/agent/extras/rag/chroma_extras.py +27 -19
- waldiez/exporting/agent/extras/rag/mongo_extras.py +8 -8
- waldiez/exporting/agent/extras/rag/pgvector_extras.py +5 -5
- waldiez/exporting/agent/extras/rag/qdrant_extras.py +5 -4
- waldiez/exporting/agent/extras/rag/vector_db_extras.py +1 -1
- waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +5 -7
- waldiez/exporting/agent/extras/reasoning_agent_extras.py +3 -5
- waldiez/exporting/agent/termination.py +1 -0
- waldiez/exporting/chats/exporter.py +4 -4
- waldiez/exporting/chats/processor.py +1 -2
- waldiez/exporting/chats/utils/common.py +89 -48
- waldiez/exporting/chats/utils/group.py +9 -9
- waldiez/exporting/chats/utils/nested.py +7 -7
- waldiez/exporting/chats/utils/sequential.py +1 -1
- waldiez/exporting/chats/utils/single.py +2 -2
- waldiez/exporting/core/constants.py +3 -1
- waldiez/exporting/core/content.py +7 -7
- waldiez/exporting/core/context.py +5 -3
- waldiez/exporting/core/exporter.py +5 -3
- waldiez/exporting/core/exporters.py +2 -2
- waldiez/exporting/core/extras/agent_extras/captain_extras.py +2 -2
- waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +2 -2
- waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +2 -2
- waldiez/exporting/core/extras/agent_extras/standard_extras.py +3 -8
- waldiez/exporting/core/extras/base.py +7 -5
- waldiez/exporting/core/extras/flow_extras.py +4 -5
- waldiez/exporting/core/extras/model_extras.py +2 -2
- waldiez/exporting/core/extras/path_resolver.py +1 -2
- waldiez/exporting/core/extras/serializer.py +13 -11
- waldiez/exporting/core/protocols.py +6 -5
- waldiez/exporting/core/result.py +25 -28
- waldiez/exporting/core/types.py +11 -10
- waldiez/exporting/core/utils/llm_config.py +4 -4
- waldiez/exporting/core/validation.py +10 -11
- waldiez/exporting/flow/execution_generator.py +99 -10
- waldiez/exporting/flow/exporter.py +2 -2
- waldiez/exporting/flow/factory.py +2 -2
- waldiez/exporting/flow/file_generator.py +4 -2
- waldiez/exporting/flow/merger.py +5 -3
- waldiez/exporting/flow/orchestrator.py +72 -2
- waldiez/exporting/flow/utils/common.py +6 -6
- waldiez/exporting/flow/utils/importing.py +7 -8
- waldiez/exporting/flow/utils/linting.py +25 -9
- waldiez/exporting/flow/utils/logging.py +5 -77
- waldiez/exporting/models/exporter.py +8 -8
- waldiez/exporting/models/processor.py +5 -5
- waldiez/exporting/tools/exporter.py +2 -2
- waldiez/exporting/tools/processor.py +7 -4
- waldiez/io/__init__.py +11 -5
- waldiez/io/_ws.py +12 -6
- waldiez/io/models/constants.py +10 -10
- waldiez/io/models/content/audio.py +1 -0
- waldiez/io/models/content/base.py +20 -18
- waldiez/io/models/content/file.py +1 -0
- waldiez/io/models/content/image.py +1 -0
- waldiez/io/models/content/text.py +1 -0
- waldiez/io/models/content/video.py +1 -0
- waldiez/io/models/user_input.py +10 -5
- waldiez/io/models/user_response.py +17 -16
- waldiez/io/mqtt.py +18 -31
- waldiez/io/redis.py +18 -22
- waldiez/io/structured.py +122 -70
- waldiez/io/utils.py +19 -10
- waldiez/io/ws.py +7 -3
- waldiez/logger.py +16 -3
- waldiez/models/agents/__init__.py +3 -0
- waldiez/models/agents/agent/agent.py +25 -17
- waldiez/models/agents/agent/agent_data.py +25 -22
- waldiez/models/agents/agent/code_execution.py +9 -11
- waldiez/models/agents/agent/termination_message.py +10 -12
- waldiez/models/agents/agent/update_system_message.py +2 -4
- waldiez/models/agents/agents.py +8 -8
- waldiez/models/agents/assistant/assistant.py +6 -3
- waldiez/models/agents/assistant/assistant_data.py +2 -2
- waldiez/models/agents/captain/captain_agent.py +7 -4
- waldiez/models/agents/captain/captain_agent_data.py +5 -7
- waldiez/models/agents/doc_agent/doc_agent.py +7 -4
- waldiez/models/agents/doc_agent/doc_agent_data.py +9 -10
- waldiez/models/agents/doc_agent/rag_query_engine.py +10 -12
- waldiez/models/agents/extra_requirements.py +3 -3
- waldiez/models/agents/group_manager/group_manager.py +12 -7
- waldiez/models/agents/group_manager/group_manager_data.py +13 -12
- waldiez/models/agents/group_manager/speakers.py +17 -19
- waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +7 -4
- waldiez/models/agents/rag_user_proxy/rag_user_proxy_data.py +4 -1
- waldiez/models/agents/rag_user_proxy/retrieve_config.py +69 -63
- waldiez/models/agents/rag_user_proxy/vector_db_config.py +19 -19
- waldiez/models/agents/reasoning/reasoning_agent.py +7 -4
- waldiez/models/agents/reasoning/reasoning_agent_data.py +3 -2
- waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +8 -8
- waldiez/models/agents/user_proxy/user_proxy.py +6 -3
- waldiez/models/agents/user_proxy/user_proxy_data.py +1 -1
- waldiez/models/chat/chat.py +28 -20
- waldiez/models/chat/chat_data.py +22 -21
- waldiez/models/chat/chat_message.py +9 -9
- waldiez/models/chat/chat_nested.py +9 -9
- waldiez/models/chat/chat_summary.py +6 -6
- waldiez/models/common/__init__.py +2 -0
- waldiez/models/common/ag2_version.py +2 -0
- waldiez/models/common/base.py +2 -0
- waldiez/models/common/dict_utils.py +8 -6
- waldiez/models/common/handoff.py +20 -17
- waldiez/models/common/method_utils.py +9 -7
- waldiez/models/common/naming.py +49 -0
- waldiez/models/flow/flow.py +11 -6
- waldiez/models/flow/flow_data.py +23 -17
- waldiez/models/flow/info.py +3 -3
- waldiez/models/flow/naming.py +2 -1
- waldiez/models/model/_aws.py +11 -13
- waldiez/models/model/_llm.py +8 -0
- waldiez/models/model/_price.py +2 -4
- waldiez/models/model/extra_requirements.py +1 -3
- waldiez/models/model/model.py +2 -2
- waldiez/models/model/model_data.py +21 -21
- waldiez/models/tool/extra_requirements.py +2 -4
- waldiez/models/tool/predefined/_duckduckgo.py +1 -0
- waldiez/models/tool/predefined/_email.py +4 -0
- waldiez/models/tool/predefined/_google.py +1 -0
- waldiez/models/tool/predefined/_perplexity.py +2 -1
- waldiez/models/tool/predefined/_searxng.py +2 -1
- waldiez/models/tool/predefined/_tavily.py +1 -0
- waldiez/models/tool/predefined/_wikipedia.py +2 -1
- waldiez/models/tool/predefined/_youtube.py +1 -0
- waldiez/models/tool/tool.py +8 -5
- waldiez/models/tool/tool_data.py +2 -2
- waldiez/models/waldiez.py +152 -4
- waldiez/runner.py +11 -5
- waldiez/running/async_utils.py +192 -0
- waldiez/running/base_runner.py +155 -241
- waldiez/running/dir_utils.py +52 -0
- waldiez/running/environment.py +10 -44
- waldiez/running/events_mixin.py +252 -0
- waldiez/running/exceptions.py +20 -0
- waldiez/running/gen_seq_diagram.py +18 -15
- waldiez/running/io_utils.py +216 -0
- waldiez/running/protocol.py +11 -5
- waldiez/running/requirements_mixin.py +65 -0
- waldiez/running/results_mixin.py +926 -0
- waldiez/running/standard_runner.py +24 -27
- waldiez/running/step_by_step/breakpoints_mixin.py +503 -47
- waldiez/running/step_by_step/command_handler.py +154 -0
- waldiez/running/step_by_step/events_processor.py +379 -0
- waldiez/running/step_by_step/step_by_step_models.py +425 -41
- waldiez/running/step_by_step/step_by_step_runner.py +437 -382
- waldiez/running/subprocess_runner/__base__.py +13 -8
- waldiez/running/subprocess_runner/_async_runner.py +6 -4
- waldiez/running/subprocess_runner/_sync_runner.py +11 -6
- waldiez/running/subprocess_runner/runner.py +48 -23
- waldiez/running/timeline_processor.py +1 -1
- waldiez/utils/__init__.py +2 -0
- waldiez/utils/conflict_checker.py +4 -4
- waldiez/utils/python_manager.py +415 -0
- waldiez/ws/__init__.py +8 -7
- waldiez/ws/_file_handler.py +18 -20
- waldiez/ws/_mock.py +75 -0
- waldiez/ws/cli.py +58 -10
- waldiez/ws/client_manager.py +77 -53
- waldiez/ws/errors.py +3 -0
- waldiez/ws/models.py +61 -53
- waldiez/ws/reloader.py +33 -4
- waldiez/ws/server.py +121 -52
- waldiez/ws/session_manager.py +8 -9
- waldiez/ws/session_stats.py +1 -1
- waldiez/ws/utils.py +33 -5
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/METADATA +107 -109
- waldiez-0.6.1.dist-info/RECORD +254 -0
- waldiez/running/post_run.py +0 -180
- waldiez/running/pre_run.py +0 -159
- waldiez/running/run_results.py +0 -14
- waldiez/running/utils.py +0 -511
- waldiez-0.5.10.dist-info/RECORD +0 -248
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/WHEEL +0 -0
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/entry_points.txt +0 -0
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/licenses/NOTICE.md +0 -0
waldiez/running/post_run.py
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
|
|
4
|
-
# pylint: disable=unused-argument
|
|
5
|
-
"""Utilities for running code."""
|
|
6
|
-
|
|
7
|
-
import datetime
|
|
8
|
-
import json
|
|
9
|
-
import shutil
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
from typing import Optional, Union
|
|
12
|
-
|
|
13
|
-
from .gen_seq_diagram import generate_sequence_diagram
|
|
14
|
-
from .timeline_processor import TimelineProcessor
|
|
15
|
-
from .utils import get_printer
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# noinspection PyUnusedLocal
|
|
19
|
-
def after_run(
|
|
20
|
-
temp_dir: Path,
|
|
21
|
-
output_file: Optional[Union[str, Path]],
|
|
22
|
-
flow_name: str,
|
|
23
|
-
uploads_root: Optional[Path] = None,
|
|
24
|
-
skip_mmd: bool = False,
|
|
25
|
-
skip_timeline: bool = False,
|
|
26
|
-
) -> None:
|
|
27
|
-
"""Actions to perform after running the flow.
|
|
28
|
-
|
|
29
|
-
Parameters
|
|
30
|
-
----------
|
|
31
|
-
temp_dir : Path
|
|
32
|
-
The temporary directory.
|
|
33
|
-
output_file : Optional[Union[str, Path]]
|
|
34
|
-
The output file.
|
|
35
|
-
flow_name : str
|
|
36
|
-
The flow name.
|
|
37
|
-
uploads_root : Optional[Path], optional
|
|
38
|
-
The runtime uploads root, by default None
|
|
39
|
-
skip_mmd : bool, optional
|
|
40
|
-
Whether to skip the mermaid sequence diagram generation,
|
|
41
|
-
by default, False
|
|
42
|
-
skip_timeline : bool, optional
|
|
43
|
-
Whether to skip the timeline processing, by default False
|
|
44
|
-
"""
|
|
45
|
-
if isinstance(output_file, str):
|
|
46
|
-
output_file = Path(output_file)
|
|
47
|
-
mmd_dir = output_file.parent if output_file else Path.cwd()
|
|
48
|
-
if skip_mmd is False:
|
|
49
|
-
_make_mermaid_diagram(
|
|
50
|
-
temp_dir=temp_dir,
|
|
51
|
-
output_file=output_file,
|
|
52
|
-
flow_name=flow_name,
|
|
53
|
-
mmd_dir=mmd_dir,
|
|
54
|
-
)
|
|
55
|
-
if skip_timeline is False: # pragma: no branch
|
|
56
|
-
_make_timeline_json(temp_dir=temp_dir)
|
|
57
|
-
if output_file:
|
|
58
|
-
destination_dir = output_file.parent
|
|
59
|
-
destination_dir = (
|
|
60
|
-
destination_dir
|
|
61
|
-
/ "waldiez_out"
|
|
62
|
-
/ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
|
63
|
-
)
|
|
64
|
-
destination_dir.mkdir(parents=True, exist_ok=True)
|
|
65
|
-
# copy the contents of the temp dir to the destination dir
|
|
66
|
-
print(f"Copying the results to {destination_dir}")
|
|
67
|
-
copy_results(
|
|
68
|
-
temp_dir=temp_dir,
|
|
69
|
-
output_file=output_file,
|
|
70
|
-
destination_dir=destination_dir,
|
|
71
|
-
)
|
|
72
|
-
shutil.rmtree(temp_dir)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
# noinspection PyBroadException
|
|
76
|
-
def _make_mermaid_diagram(
|
|
77
|
-
temp_dir: Path,
|
|
78
|
-
output_file: Optional[Union[str, Path]],
|
|
79
|
-
flow_name: str,
|
|
80
|
-
mmd_dir: Path,
|
|
81
|
-
) -> None:
|
|
82
|
-
events_csv_path = temp_dir / "logs" / "events.csv"
|
|
83
|
-
if events_csv_path.exists():
|
|
84
|
-
print("Generating mermaid sequence diagram...")
|
|
85
|
-
mmd_path = temp_dir / f"{flow_name}.mmd"
|
|
86
|
-
generate_sequence_diagram(events_csv_path, mmd_path)
|
|
87
|
-
if (
|
|
88
|
-
not output_file
|
|
89
|
-
and mmd_path.exists()
|
|
90
|
-
and mmd_path != mmd_dir / f"{flow_name}.mmd"
|
|
91
|
-
):
|
|
92
|
-
try:
|
|
93
|
-
shutil.copyfile(mmd_path, mmd_dir / f"{flow_name}.mmd")
|
|
94
|
-
except BaseException: # pylint: disable=broad-exception-caught
|
|
95
|
-
pass
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# noinspection PyBroadException
|
|
99
|
-
def _make_timeline_json(
|
|
100
|
-
temp_dir: Path,
|
|
101
|
-
) -> None:
|
|
102
|
-
"""Make the timeline JSON file."""
|
|
103
|
-
events_csv_path = temp_dir / "logs" / "events.csv"
|
|
104
|
-
if events_csv_path.exists():
|
|
105
|
-
log_files = TimelineProcessor.get_files(temp_dir / "logs")
|
|
106
|
-
if any(log_files.values()): # pragma: no branch
|
|
107
|
-
output_file = temp_dir / "timeline.json"
|
|
108
|
-
# pylint: disable=too-many-try-statements
|
|
109
|
-
try:
|
|
110
|
-
processor = TimelineProcessor()
|
|
111
|
-
processor.load_csv_files(
|
|
112
|
-
agents_file=log_files["agents"],
|
|
113
|
-
chat_file=log_files["chat"],
|
|
114
|
-
events_file=log_files["events"],
|
|
115
|
-
functions_file=log_files["functions"],
|
|
116
|
-
)
|
|
117
|
-
results = processor.process_timeline()
|
|
118
|
-
with open(output_file, "w", encoding="utf-8") as f:
|
|
119
|
-
json.dump(results, f, indent=2, default=str)
|
|
120
|
-
short_results = TimelineProcessor.get_short_results(results)
|
|
121
|
-
printer = get_printer()
|
|
122
|
-
printer(
|
|
123
|
-
json.dumps(
|
|
124
|
-
{"type": "timeline", "content": short_results},
|
|
125
|
-
default=str,
|
|
126
|
-
),
|
|
127
|
-
flush=True,
|
|
128
|
-
)
|
|
129
|
-
except BaseException: # pylint: disable=broad-exception-caught
|
|
130
|
-
pass
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
def copy_results(
|
|
134
|
-
temp_dir: Path,
|
|
135
|
-
output_file: Path,
|
|
136
|
-
destination_dir: Path,
|
|
137
|
-
) -> None:
|
|
138
|
-
"""Copy the results to the output directory.
|
|
139
|
-
|
|
140
|
-
Parameters
|
|
141
|
-
----------
|
|
142
|
-
temp_dir : Path
|
|
143
|
-
The temporary directory.
|
|
144
|
-
output_file : Path
|
|
145
|
-
The output file.
|
|
146
|
-
destination_dir : Path
|
|
147
|
-
The destination directory.
|
|
148
|
-
"""
|
|
149
|
-
temp_dir.mkdir(parents=True, exist_ok=True)
|
|
150
|
-
output_dir = output_file.parent
|
|
151
|
-
for item in temp_dir.iterdir():
|
|
152
|
-
# skip cache files
|
|
153
|
-
if (
|
|
154
|
-
item.name.startswith("__pycache__")
|
|
155
|
-
or item.name.endswith(".pyc")
|
|
156
|
-
or item.name.endswith(".pyo")
|
|
157
|
-
or item.name.endswith(".pyd")
|
|
158
|
-
or item.name == ".cache"
|
|
159
|
-
):
|
|
160
|
-
continue
|
|
161
|
-
if item.is_file():
|
|
162
|
-
# let's also copy the "tree of thoughts" image
|
|
163
|
-
# to the output directory
|
|
164
|
-
if item.name.endswith("tree_of_thoughts.png") or item.name.endswith(
|
|
165
|
-
"reasoning_tree.json"
|
|
166
|
-
):
|
|
167
|
-
shutil.copy(item, output_dir / item.name)
|
|
168
|
-
shutil.copy(item, destination_dir)
|
|
169
|
-
else:
|
|
170
|
-
shutil.copytree(item, destination_dir / item.name)
|
|
171
|
-
if output_file.is_file():
|
|
172
|
-
if output_file.suffix == ".waldiez":
|
|
173
|
-
output_file = output_file.with_suffix(".py")
|
|
174
|
-
if output_file.suffix == ".py": # pragma: no branch
|
|
175
|
-
src = temp_dir / output_file.name
|
|
176
|
-
if src.exists():
|
|
177
|
-
dst = destination_dir / output_file.name
|
|
178
|
-
if dst.exists():
|
|
179
|
-
dst.unlink()
|
|
180
|
-
shutil.copyfile(src, output_dir / output_file.name)
|
waldiez/running/pre_run.py
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Actions to perform before running the flow."""
|
|
4
|
-
|
|
5
|
-
import asyncio
|
|
6
|
-
import io
|
|
7
|
-
import os
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
from typing import Callable
|
|
11
|
-
|
|
12
|
-
from waldiez.models import Waldiez
|
|
13
|
-
|
|
14
|
-
from .environment import in_virtualenv, is_root
|
|
15
|
-
from .utils import strip_ansi
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class RequirementsMixin:
|
|
19
|
-
"""Mixin class to handle requirements installation."""
|
|
20
|
-
|
|
21
|
-
_waldiez: Waldiez
|
|
22
|
-
_called_install_requirements: bool
|
|
23
|
-
|
|
24
|
-
def gather_requirements(self) -> set[str]:
|
|
25
|
-
"""Gather extra requirements to install before running the flow.
|
|
26
|
-
|
|
27
|
-
Returns
|
|
28
|
-
-------
|
|
29
|
-
set[str]
|
|
30
|
-
A set of requirements that are not already installed and do not
|
|
31
|
-
include 'waldiez' in their name.
|
|
32
|
-
"""
|
|
33
|
-
extra_requirements = {
|
|
34
|
-
req
|
|
35
|
-
for req in self._waldiez.requirements
|
|
36
|
-
if req not in sys.modules and "waldiez" not in req
|
|
37
|
-
}
|
|
38
|
-
if "python-dotenv" not in extra_requirements: # pragma: no branch
|
|
39
|
-
extra_requirements.add("python-dotenv")
|
|
40
|
-
return extra_requirements
|
|
41
|
-
|
|
42
|
-
def install_requirements(self) -> None:
|
|
43
|
-
"""Install the requirements for the flow."""
|
|
44
|
-
if not self._called_install_requirements: # pragma: no branch
|
|
45
|
-
self._called_install_requirements = True
|
|
46
|
-
extra_requirements = self.gather_requirements()
|
|
47
|
-
if extra_requirements: # pragma: no branch
|
|
48
|
-
install_requirements(extra_requirements)
|
|
49
|
-
|
|
50
|
-
async def a_install_requirements(self) -> None:
|
|
51
|
-
"""Install the requirements for the flow asynchronously."""
|
|
52
|
-
if not self._called_install_requirements: # pragma: no branch
|
|
53
|
-
self._called_install_requirements = True
|
|
54
|
-
extra_requirements = self.gather_requirements()
|
|
55
|
-
if extra_requirements: # pragma: no branch
|
|
56
|
-
await a_install_requirements(extra_requirements)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# noinspection PyUnresolvedReferences
|
|
60
|
-
def install_requirements(
|
|
61
|
-
extra_requirements: set[str],
|
|
62
|
-
upgrade: bool = False,
|
|
63
|
-
printer: Callable[..., None] = print,
|
|
64
|
-
) -> None:
|
|
65
|
-
"""Install the requirements.
|
|
66
|
-
|
|
67
|
-
Parameters
|
|
68
|
-
----------
|
|
69
|
-
extra_requirements : set[str]
|
|
70
|
-
The extra requirements.
|
|
71
|
-
upgrade : bool, optional
|
|
72
|
-
Whether to upgrade the requirements, by default False.
|
|
73
|
-
printer : Callable[..., None]
|
|
74
|
-
The printer function to use, defaults to print.
|
|
75
|
-
"""
|
|
76
|
-
requirements_string = ", ".join(extra_requirements)
|
|
77
|
-
printer(f"Installing requirements: {requirements_string}")
|
|
78
|
-
pip_install = [sys.executable, "-m", "pip", "install"]
|
|
79
|
-
break_system_packages = ""
|
|
80
|
-
if not in_virtualenv(): # it should # pragma: no cover
|
|
81
|
-
# if not, let's try to install as user
|
|
82
|
-
# not sure if --break-system-packages is safe,
|
|
83
|
-
# but it might fail if we don't
|
|
84
|
-
break_system_packages = os.environ.get("PIP_BREAK_SYSTEM_PACKAGES", "")
|
|
85
|
-
os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = "1"
|
|
86
|
-
if not is_root():
|
|
87
|
-
pip_install.append("--user")
|
|
88
|
-
if upgrade: # pragma: no cover
|
|
89
|
-
pip_install.append("--upgrade")
|
|
90
|
-
pip_install.extend(extra_requirements)
|
|
91
|
-
# pylint: disable=too-many-try-statements
|
|
92
|
-
try:
|
|
93
|
-
with subprocess.Popen(
|
|
94
|
-
pip_install,
|
|
95
|
-
stdout=subprocess.PIPE,
|
|
96
|
-
stderr=subprocess.PIPE,
|
|
97
|
-
) as proc:
|
|
98
|
-
if proc.stdout: # pragma: no branch
|
|
99
|
-
for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
|
|
100
|
-
printer(strip_ansi(line.strip()))
|
|
101
|
-
if proc.stderr: # pragma: no branch
|
|
102
|
-
for line in io.TextIOWrapper(proc.stderr, encoding="utf-8"):
|
|
103
|
-
printer(strip_ansi(line.strip()))
|
|
104
|
-
finally:
|
|
105
|
-
if not in_virtualenv(): # pragma: no cover
|
|
106
|
-
# restore the old env var
|
|
107
|
-
if break_system_packages:
|
|
108
|
-
os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = break_system_packages
|
|
109
|
-
else:
|
|
110
|
-
del os.environ["PIP_BREAK_SYSTEM_PACKAGES"]
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
async def a_install_requirements(
|
|
114
|
-
extra_requirements: set[str],
|
|
115
|
-
upgrade: bool = False,
|
|
116
|
-
printer: Callable[..., None] = print,
|
|
117
|
-
) -> None:
|
|
118
|
-
"""Install the requirements asynchronously.
|
|
119
|
-
|
|
120
|
-
Parameters
|
|
121
|
-
----------
|
|
122
|
-
extra_requirements : set[str]
|
|
123
|
-
The extra requirements.
|
|
124
|
-
upgrade : bool, optional
|
|
125
|
-
Whether to upgrade the requirements, by default False.
|
|
126
|
-
printer : Callable[..., None]
|
|
127
|
-
The printer function to use, defaults to print.
|
|
128
|
-
"""
|
|
129
|
-
requirements_string = ", ".join(extra_requirements)
|
|
130
|
-
printer(f"Installing requirements: {requirements_string}")
|
|
131
|
-
pip_install = [sys.executable, "-m", "pip", "install"]
|
|
132
|
-
break_system_packages = ""
|
|
133
|
-
if not in_virtualenv(): # pragma: no cover
|
|
134
|
-
break_system_packages = os.environ.get("PIP_BREAK_SYSTEM_PACKAGES", "")
|
|
135
|
-
os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = "1"
|
|
136
|
-
if not is_root():
|
|
137
|
-
pip_install.extend(["--user"])
|
|
138
|
-
if upgrade: # pragma: no cover
|
|
139
|
-
pip_install.append("--upgrade")
|
|
140
|
-
pip_install.extend(extra_requirements)
|
|
141
|
-
# pylint: disable=too-many-try-statements
|
|
142
|
-
try:
|
|
143
|
-
proc = await asyncio.create_subprocess_exec(
|
|
144
|
-
*pip_install,
|
|
145
|
-
stdout=asyncio.subprocess.PIPE,
|
|
146
|
-
stderr=asyncio.subprocess.PIPE,
|
|
147
|
-
)
|
|
148
|
-
if proc.stdout:
|
|
149
|
-
async for line in proc.stdout:
|
|
150
|
-
printer(strip_ansi(line.decode().strip()))
|
|
151
|
-
if proc.stderr:
|
|
152
|
-
async for line in proc.stderr:
|
|
153
|
-
printer(strip_ansi(line.decode().strip()))
|
|
154
|
-
finally:
|
|
155
|
-
if not in_virtualenv(): # pragma: no cover
|
|
156
|
-
if break_system_packages:
|
|
157
|
-
os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = break_system_packages
|
|
158
|
-
else:
|
|
159
|
-
del os.environ["PIP_BREAK_SYSTEM_PACKAGES"]
|
waldiez/running/run_results.py
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
|
|
4
|
-
"""Waldiez run results module."""
|
|
5
|
-
|
|
6
|
-
from typing import Any, TypedDict
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class WaldiezRunResults(TypedDict):
|
|
10
|
-
"""Results of the Waldiez run."""
|
|
11
|
-
|
|
12
|
-
results: list[dict[str, Any]]
|
|
13
|
-
exception: BaseException | None
|
|
14
|
-
completed: bool
|