workflowforge 1.0b1__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 workflowforge might be problematic. Click here for more details.

@@ -0,0 +1,195 @@
1
+ """
2
+ WorkflowForge - A robust and flexible library for creating GitHub Actions workflows.
3
+
4
+ This library allows you to create GitHub Actions workflows programmatically,
5
+ with type validation, autocompletion, and an intuitive API.
6
+ """
7
+
8
+ from .ai_documentation import (
9
+ OllamaClient,
10
+ ai_documentation_client,
11
+ generate_workflow_readme,
12
+ )
13
+ from .codebuild import (
14
+ BuildArtifacts,
15
+ BuildCache,
16
+ BuildEnvironment,
17
+ BuildPhase,
18
+ BuildSpec,
19
+ artifacts,
20
+ buildspec,
21
+ cache,
22
+ environment,
23
+ phase,
24
+ )
25
+ from .environment import Environment, environment
26
+ from .jenkins import (
27
+ JenkinsAgent,
28
+ JenkinsPipeline,
29
+ JenkinsStage,
30
+ agent_any,
31
+ agent_docker,
32
+ agent_label,
33
+ pipeline,
34
+ stage,
35
+ )
36
+ from .jenkins_plugins import (
37
+ ArtifactArchiver,
38
+ DockerPlugin,
39
+ EmailNotification,
40
+ GitCheckout,
41
+ JUnitPublisher,
42
+ SlackNotification,
43
+ archive_artifacts,
44
+ docker_run,
45
+ email_notify,
46
+ git_checkout,
47
+ publish_junit,
48
+ slack_notify,
49
+ )
50
+ from .job import Job
51
+ from .schema_validation import validate_github_actions_schema, validate_workflow_yaml
52
+ from .secrets import ( # GitHub Actions; Jenkins; AWS CodeBuild
53
+ CodeBuildEnvVar,
54
+ CodeBuildParameter,
55
+ CodeBuildSecret,
56
+ GitHubContext,
57
+ JenkinsCredential,
58
+ JenkinsEnvVar,
59
+ JenkinsParam,
60
+ Secret,
61
+ Variable,
62
+ codebuild_env,
63
+ codebuild_parameter,
64
+ codebuild_secret,
65
+ github_context,
66
+ jenkins_credential,
67
+ jenkins_env,
68
+ jenkins_param,
69
+ secret,
70
+ variable,
71
+ )
72
+ from .step import ActionStep, RunStep, Step, action, run
73
+ from .strategy import Matrix, Strategy, matrix, strategy
74
+ from .templates import (
75
+ docker_build_template,
76
+ node_ci_template,
77
+ python_ci_template,
78
+ release_template,
79
+ )
80
+ from .triggers import (
81
+ PullRequestTrigger,
82
+ PushTrigger,
83
+ ReleaseTrigger,
84
+ ScheduleTrigger,
85
+ WorkflowDispatchTrigger,
86
+ on_pull_request,
87
+ on_push,
88
+ on_release,
89
+ on_schedule,
90
+ on_workflow_dispatch,
91
+ )
92
+ from .validation import (
93
+ ValidationError,
94
+ validate_job_name,
95
+ validate_secret_name,
96
+ validate_step_name,
97
+ )
98
+ from .visualization import PipelineVisualizer, visualizer
99
+ from .workflow import Workflow
100
+
101
+ __version__ = "1.0b1"
102
+ __all__ = [
103
+ "Workflow",
104
+ "Job",
105
+ "Step",
106
+ "ActionStep",
107
+ "RunStep",
108
+ "action",
109
+ "run",
110
+ "PushTrigger",
111
+ "PullRequestTrigger",
112
+ "ScheduleTrigger",
113
+ "WorkflowDispatchTrigger",
114
+ "ReleaseTrigger",
115
+ "on_push",
116
+ "on_pull_request",
117
+ "on_schedule",
118
+ "on_workflow_dispatch",
119
+ "on_release",
120
+ "Strategy",
121
+ "Matrix",
122
+ "matrix",
123
+ "strategy",
124
+ "Environment",
125
+ "environment",
126
+ "JenkinsPipeline",
127
+ "JenkinsStage",
128
+ "JenkinsAgent",
129
+ "agent_any",
130
+ "agent_docker",
131
+ "agent_label",
132
+ "stage",
133
+ "pipeline",
134
+ "GitCheckout",
135
+ "DockerPlugin",
136
+ "SlackNotification",
137
+ "EmailNotification",
138
+ "ArtifactArchiver",
139
+ "JUnitPublisher",
140
+ "git_checkout",
141
+ "docker_run",
142
+ "slack_notify",
143
+ "email_notify",
144
+ "archive_artifacts",
145
+ "publish_junit",
146
+ "BuildSpec",
147
+ "BuildPhase",
148
+ "BuildEnvironment",
149
+ "BuildArtifacts",
150
+ "BuildCache",
151
+ "buildspec",
152
+ "phase",
153
+ "environment",
154
+ "artifacts",
155
+ "cache",
156
+ # Secrets and variables
157
+ "Secret",
158
+ "Variable",
159
+ "GitHubContext",
160
+ "secret",
161
+ "variable",
162
+ "github_context",
163
+ "JenkinsCredential",
164
+ "JenkinsEnvVar",
165
+ "JenkinsParam",
166
+ "jenkins_credential",
167
+ "jenkins_env",
168
+ "jenkins_param",
169
+ "CodeBuildSecret",
170
+ "CodeBuildParameter",
171
+ "CodeBuildEnvVar",
172
+ "codebuild_secret",
173
+ "codebuild_parameter",
174
+ "codebuild_env",
175
+ # AI Documentation
176
+ "OllamaClient",
177
+ "generate_workflow_readme",
178
+ "ai_documentation_client",
179
+ # Visualization
180
+ "PipelineVisualizer",
181
+ "visualizer",
182
+ # Validation
183
+ "validate_job_name",
184
+ "validate_step_name",
185
+ "validate_secret_name",
186
+ "ValidationError",
187
+ # Templates
188
+ "python_ci_template",
189
+ "docker_build_template",
190
+ "node_ci_template",
191
+ "release_template",
192
+ # Schema validation
193
+ "validate_github_actions_schema",
194
+ "validate_workflow_yaml",
195
+ ]
@@ -0,0 +1,137 @@
1
+ """AI-powered documentation generation for WorkflowForge."""
2
+
3
+ import json
4
+ from typing import Any, Dict, Optional
5
+
6
+ import requests
7
+ from pydantic import BaseModel, Field
8
+
9
+
10
+ class OllamaClient(BaseModel):
11
+ """Client for interacting with Ollama local LLM."""
12
+
13
+ base_url: str = Field(
14
+ default="http://localhost:11434", description="Ollama server URL"
15
+ )
16
+ model: str = Field(default="llama3.2", description="Model to use")
17
+ timeout: int = Field(default=30, description="Request timeout in seconds")
18
+
19
+ def is_available(self) -> bool:
20
+ """Check if Ollama is running and accessible."""
21
+ try:
22
+ response = requests.get(f"{self.base_url}/api/tags", timeout=5)
23
+ return response.status_code == 200
24
+ except:
25
+ return False
26
+
27
+ def generate(self, prompt: str) -> str | None:
28
+ """Generate text using Ollama."""
29
+ if not self.is_available():
30
+ return None
31
+
32
+ try:
33
+ response = requests.post(
34
+ f"{self.base_url}/api/generate",
35
+ json={"model": self.model, "prompt": prompt, "stream": False},
36
+ timeout=self.timeout,
37
+ )
38
+
39
+ if response.status_code == 200:
40
+ return response.json().get("response", "").strip()
41
+ return None
42
+ except:
43
+ return None
44
+
45
+
46
+ def generate_workflow_readme(
47
+ workflow_content: str, platform: str = "github", use_ai: bool = True
48
+ ) -> str:
49
+ """Generate README documentation for a workflow.
50
+
51
+ Args:
52
+ workflow_content: The YAML/Jenkinsfile content
53
+ platform: Platform type (github, jenkins, codebuild)
54
+ use_ai: Whether to use AI generation (requires Ollama)
55
+
56
+ Returns:
57
+ Generated README content
58
+ """
59
+ if use_ai:
60
+ return _ai_generate_readme(workflow_content, platform)
61
+ else:
62
+ return _template_generate_readme(workflow_content, platform)
63
+
64
+
65
+ def _ai_generate_readme(workflow_content: str, platform: str) -> str:
66
+ """Generate README using Ollama AI."""
67
+ client = OllamaClient()
68
+
69
+ if not client.is_available():
70
+ return _template_generate_readme(workflow_content, platform)
71
+
72
+ prompt = f"""
73
+ Analyze this {platform.upper()} CI/CD workflow and generate a comprehensive README.md documentation.
74
+
75
+ Workflow content:
76
+ ```
77
+ {workflow_content}
78
+ ```
79
+
80
+ Please provide:
81
+ 1. Brief description of what this workflow does
82
+ 2. Triggers (when it runs)
83
+ 3. Jobs/stages breakdown with explanations
84
+ 4. Required secrets/variables/credentials
85
+ 5. Prerequisites and setup instructions
86
+ 6. Expected outputs/artifacts
87
+
88
+ Format as proper markdown with clear sections and code blocks where appropriate.
89
+ Keep it concise but informative for developers who need to understand and maintain this workflow.
90
+ """
91
+
92
+ ai_response = client.generate(prompt)
93
+
94
+ if ai_response:
95
+ return f"# Workflow Documentation\n\n{ai_response}\n\n---\n*Documentation generated with WorkflowForge AI*"
96
+ else:
97
+ return _template_generate_readme(workflow_content, platform)
98
+
99
+
100
+ def _template_generate_readme(workflow_content: str, platform: str) -> str:
101
+ """Generate basic README using templates."""
102
+ platform_name = {
103
+ "github": "GitHub Actions",
104
+ "jenkins": "Jenkins Pipeline",
105
+ "codebuild": "AWS CodeBuild",
106
+ }.get(platform, platform.title())
107
+
108
+ return f"""# {platform_name} Workflow
109
+
110
+ ## Overview
111
+ This {platform_name} workflow was generated using WorkflowForge.
112
+
113
+ ## Workflow Content
114
+ ```yaml
115
+ {workflow_content}
116
+ ```
117
+
118
+ ## Setup Instructions
119
+ 1. Review the workflow configuration above
120
+ 2. Configure required secrets/variables in your {platform_name} settings
121
+ 3. Ensure all dependencies and permissions are properly set
122
+ 4. Test the workflow in a development environment first
123
+
124
+ ## Maintenance
125
+ - Review and update dependencies regularly
126
+ - Monitor workflow execution and performance
127
+ - Update documentation when making changes
128
+
129
+ ---
130
+ *Generated with WorkflowForge*
131
+ """
132
+
133
+
134
+ # Factory function
135
+ def ai_documentation_client(model: str = "llama3.2") -> OllamaClient:
136
+ """Create an Ollama client for AI documentation generation."""
137
+ return OllamaClient(model=model)
@@ -0,0 +1,337 @@
1
+ """AWS CodeBuild BuildSpec generation for WorkflowForge."""
2
+
3
+ from typing import Any, Dict, List, Optional, Union
4
+
5
+ import yaml
6
+ from pydantic import BaseModel, Field
7
+
8
+
9
+ class BuildPhase(BaseModel):
10
+ """Represents a CodeBuild phase."""
11
+
12
+ run_as: str | None = Field(None, description="Linux user to run commands")
13
+ on_failure: str | None = Field(None, description="Action on failure")
14
+ runtime_versions: dict[str, str] | None = Field(
15
+ None, description="Runtime versions"
16
+ )
17
+ commands: list[str] = Field(default_factory=list, description="Commands to execute")
18
+ finally_commands: list[str] | None = Field(None, description="Finally commands")
19
+
20
+ def add_command(self, command: str) -> "BuildPhase":
21
+ """Add a command to the phase."""
22
+ self.commands.append(command)
23
+ return self
24
+
25
+ def add_runtime(self, runtime: str, version: str) -> "BuildPhase":
26
+ """Add runtime version."""
27
+ if self.runtime_versions is None:
28
+ self.runtime_versions = {}
29
+ self.runtime_versions[runtime] = version
30
+ return self
31
+
32
+ def set_on_failure(self, action: str) -> "BuildPhase":
33
+ """Set on-failure action."""
34
+ self.on_failure = action
35
+ return self
36
+
37
+
38
+ class BuildEnvironment(BaseModel):
39
+ """Represents CodeBuild environment configuration."""
40
+
41
+ shell: str | None = Field(None, description="Shell to use")
42
+ variables: dict[str, str] | None = Field(None, description="Environment variables")
43
+ parameter_store: dict[str, str] | None = Field(
44
+ None, description="Parameter Store variables"
45
+ )
46
+ secrets_manager: dict[str, str] | None = Field(
47
+ None, description="Secrets Manager variables"
48
+ )
49
+ exported_variables: list[str] | None = Field(None, description="Exported variables")
50
+ git_credential_helper: bool | None = Field(
51
+ None, description="Git credential helper"
52
+ )
53
+
54
+ def add_variable(self, key: str, value: str) -> "BuildEnvironment":
55
+ """Add environment variable."""
56
+ if self.variables is None:
57
+ self.variables = {}
58
+ self.variables[key] = value
59
+ return self
60
+
61
+ def add_parameter_store(self, key: str, parameter: str) -> "BuildEnvironment":
62
+ """Add Parameter Store variable."""
63
+ if self.parameter_store is None:
64
+ self.parameter_store = {}
65
+ self.parameter_store[key] = parameter
66
+ return self
67
+
68
+ def add_secret(self, key: str, secret: str) -> "BuildEnvironment":
69
+ """Add Secrets Manager variable."""
70
+ if self.secrets_manager is None:
71
+ self.secrets_manager = {}
72
+ self.secrets_manager[key] = secret
73
+ return self
74
+
75
+
76
+ class BuildArtifacts(BaseModel):
77
+ """Represents CodeBuild artifacts configuration."""
78
+
79
+ files: list[str] = Field(..., description="Files to include")
80
+ name: str | None = Field(None, description="Artifact name")
81
+ discard_paths: bool | None = Field(None, description="Discard paths")
82
+ base_directory: str | None = Field(None, description="Base directory")
83
+ exclude_paths: list[str] | None = Field(None, description="Paths to exclude")
84
+ enable_symlinks: bool | None = Field(None, description="Enable symlinks")
85
+ s3_prefix: str | None = Field(None, description="S3 prefix")
86
+
87
+ def add_file(self, file_pattern: str) -> "BuildArtifacts":
88
+ """Add file pattern."""
89
+ self.files.append(file_pattern)
90
+ return self
91
+
92
+
93
+ class BuildCache(BaseModel):
94
+ """Represents CodeBuild cache configuration."""
95
+
96
+ key: str | None = Field(None, description="Cache key")
97
+ fallback_keys: list[str] | None = Field(None, description="Fallback keys")
98
+ action: str | None = Field(None, description="Cache action")
99
+ paths: list[str] = Field(default_factory=list, description="Paths to cache")
100
+
101
+ def add_path(self, path: str) -> "BuildCache":
102
+ """Add cache path."""
103
+ self.paths.append(path)
104
+ return self
105
+
106
+
107
+ class BuildSpec(BaseModel):
108
+ """Represents a complete AWS CodeBuild BuildSpec."""
109
+
110
+ version: str = Field(default="0.2", description="BuildSpec version")
111
+ run_as: str | None = Field(None, description="Global run-as user")
112
+ env: BuildEnvironment | None = Field(None, description="Environment configuration")
113
+ install: BuildPhase | None = Field(None, description="Install phase")
114
+ pre_build: BuildPhase | None = Field(None, description="Pre-build phase")
115
+ build: BuildPhase | None = Field(None, description="Build phase")
116
+ post_build: BuildPhase | None = Field(None, description="Post-build phase")
117
+ artifacts: BuildArtifacts | None = Field(
118
+ None, description="Artifacts configuration"
119
+ )
120
+ cache: BuildCache | None = Field(None, description="Cache configuration")
121
+ reports: dict[str, dict[str, Any]] | None = Field(
122
+ None, description="Reports configuration"
123
+ )
124
+
125
+ def set_env(self, env: BuildEnvironment) -> "BuildSpec":
126
+ """Set environment configuration."""
127
+ self.env = env
128
+ return self
129
+
130
+ def set_install_phase(self, phase: BuildPhase) -> "BuildSpec":
131
+ """Set install phase."""
132
+ self.install = phase
133
+ return self
134
+
135
+ def set_pre_build_phase(self, phase: BuildPhase) -> "BuildSpec":
136
+ """Set pre-build phase."""
137
+ self.pre_build = phase
138
+ return self
139
+
140
+ def set_build_phase(self, phase: BuildPhase) -> "BuildSpec":
141
+ """Set build phase."""
142
+ self.build = phase
143
+ return self
144
+
145
+ def set_post_build_phase(self, phase: BuildPhase) -> "BuildSpec":
146
+ """Set post-build phase."""
147
+ self.post_build = phase
148
+ return self
149
+
150
+ def set_artifacts(self, artifacts: BuildArtifacts) -> "BuildSpec":
151
+ """Set artifacts configuration."""
152
+ self.artifacts = artifacts
153
+ return self
154
+
155
+ def set_cache(self, cache: BuildCache) -> "BuildSpec":
156
+ """Set cache configuration."""
157
+ self.cache = cache
158
+ return self
159
+
160
+ def to_yaml(self) -> str:
161
+ """Convert to BuildSpec YAML format."""
162
+ data = {"version": self.version}
163
+
164
+ if self.run_as:
165
+ data["run-as"] = self.run_as
166
+
167
+ # Environment
168
+ if self.env:
169
+ env_data = {}
170
+ if self.env.shell:
171
+ env_data["shell"] = self.env.shell
172
+ if self.env.variables:
173
+ env_data["variables"] = self.env.variables
174
+ if self.env.parameter_store:
175
+ env_data["parameter-store"] = self.env.parameter_store
176
+ if self.env.secrets_manager:
177
+ env_data["secrets-manager"] = self.env.secrets_manager
178
+ if self.env.exported_variables:
179
+ env_data["exported-variables"] = self.env.exported_variables
180
+ if self.env.git_credential_helper is not None:
181
+ env_data["git-credential-helper"] = (
182
+ "yes" if self.env.git_credential_helper else "no"
183
+ )
184
+ if env_data:
185
+ data["env"] = env_data
186
+
187
+ # Phases
188
+ phases = {}
189
+ for phase_name, phase in [
190
+ ("install", self.install),
191
+ ("pre_build", self.pre_build),
192
+ ("build", self.build),
193
+ ("post_build", self.post_build),
194
+ ]:
195
+ if phase:
196
+ phase_data = {}
197
+ if phase.run_as:
198
+ phase_data["run-as"] = phase.run_as
199
+ if phase.on_failure:
200
+ phase_data["on-failure"] = phase.on_failure
201
+ if phase.runtime_versions:
202
+ phase_data["runtime-versions"] = phase.runtime_versions
203
+ if phase.commands:
204
+ phase_data["commands"] = phase.commands
205
+ if phase.finally_commands:
206
+ phase_data["finally"] = phase.finally_commands
207
+ if phase_data:
208
+ phases[phase_name] = phase_data
209
+
210
+ if phases:
211
+ data["phases"] = phases
212
+
213
+ # Artifacts
214
+ if self.artifacts:
215
+ artifacts_data = {"files": self.artifacts.files}
216
+ if self.artifacts.name:
217
+ artifacts_data["name"] = self.artifacts.name
218
+ if self.artifacts.discard_paths is not None:
219
+ artifacts_data["discard-paths"] = (
220
+ "yes" if self.artifacts.discard_paths else "no"
221
+ )
222
+ if self.artifacts.base_directory:
223
+ artifacts_data["base-directory"] = self.artifacts.base_directory
224
+ if self.artifacts.exclude_paths:
225
+ artifacts_data["exclude-paths"] = self.artifacts.exclude_paths
226
+ if self.artifacts.enable_symlinks is not None:
227
+ artifacts_data["enable-symlinks"] = (
228
+ "yes" if self.artifacts.enable_symlinks else "no"
229
+ )
230
+ if self.artifacts.s3_prefix:
231
+ artifacts_data["s3-prefix"] = self.artifacts.s3_prefix
232
+ data["artifacts"] = artifacts_data
233
+
234
+ # Cache
235
+ if self.cache:
236
+ cache_data = {}
237
+ if self.cache.key:
238
+ cache_data["key"] = self.cache.key
239
+ if self.cache.fallback_keys:
240
+ cache_data["fallback-keys"] = self.cache.fallback_keys
241
+ if self.cache.action:
242
+ cache_data["action"] = self.cache.action
243
+ if self.cache.paths:
244
+ cache_data["paths"] = self.cache.paths
245
+ if cache_data:
246
+ data["cache"] = cache_data
247
+
248
+ # Reports
249
+ if self.reports:
250
+ data["reports"] = self.reports
251
+
252
+ yaml_content = yaml.dump(data, default_flow_style=False, sort_keys=False)
253
+ return f"# Do not modify - Generated with WorkflowForge\n{yaml_content}"
254
+
255
+ def generate_readme(self, use_ai: bool = True, ai_model: str = "llama3.2") -> str:
256
+ """Generate README documentation for this BuildSpec.
257
+
258
+ Args:
259
+ use_ai: Whether to use AI generation (requires Ollama)
260
+ ai_model: AI model to use for generation
261
+
262
+ Returns:
263
+ Generated README content
264
+ """
265
+ from .ai_documentation import generate_workflow_readme
266
+
267
+ return generate_workflow_readme(self.to_yaml(), "codebuild", use_ai)
268
+
269
+ def generate_diagram(self, output_format: str = "png") -> str:
270
+ """Generate visual diagram of this BuildSpec.
271
+
272
+ Args:
273
+ output_format: Output format (png, svg, pdf, dot)
274
+
275
+ Returns:
276
+ Path to generated diagram file
277
+ """
278
+ from .visualization import visualizer
279
+
280
+ viz = visualizer(output_format=output_format)
281
+ return viz.generate_codebuild_diagram(self)
282
+
283
+ def save(
284
+ self,
285
+ filepath: str = "buildspec.yml",
286
+ generate_readme: bool = False,
287
+ use_ai: bool = True,
288
+ generate_diagram: bool = True,
289
+ ) -> None:
290
+ """Save BuildSpec to file.
291
+
292
+ Args:
293
+ filepath: Path to save the buildspec YAML (default: buildspec.yml)
294
+ Can be customized (e.g., buildspec_debug.yml, config/buildspec.yml)
295
+ generate_readme: Whether to also generate a README file
296
+ use_ai: Whether to use AI for README generation
297
+ generate_diagram: Whether to generate visual diagram
298
+ """
299
+ with open(filepath, "w", encoding="utf-8") as f:
300
+ f.write(self.to_yaml())
301
+
302
+ if generate_readme:
303
+ readme_path = filepath.replace(".yml", "_README.md").replace(
304
+ ".yaml", "_README.md"
305
+ )
306
+ with open(readme_path, "w", encoding="utf-8") as f:
307
+ f.write(self.generate_readme(use_ai=use_ai))
308
+
309
+ if generate_diagram:
310
+ diagram_path = self.generate_diagram()
311
+ print(f"📊 BuildSpec diagram saved: {diagram_path}")
312
+
313
+
314
+ # Factory functions
315
+ def buildspec() -> BuildSpec:
316
+ """Create a new BuildSpec."""
317
+ return BuildSpec()
318
+
319
+
320
+ def phase() -> BuildPhase:
321
+ """Create a new BuildPhase."""
322
+ return BuildPhase()
323
+
324
+
325
+ def environment() -> BuildEnvironment:
326
+ """Create a new BuildEnvironment."""
327
+ return BuildEnvironment()
328
+
329
+
330
+ def artifacts(files: list[str]) -> BuildArtifacts:
331
+ """Create BuildArtifacts."""
332
+ return BuildArtifacts(files=files)
333
+
334
+
335
+ def cache(paths: list[str]) -> BuildCache:
336
+ """Create BuildCache."""
337
+ return BuildCache(paths=paths)
@@ -0,0 +1,25 @@
1
+ """Definición de entornos para jobs."""
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+
8
+ class Environment(BaseModel):
9
+ """Representa un entorno de despliegue."""
10
+
11
+ name: str = Field(..., description="Nombre del entorno")
12
+ url: str | None = Field(None, description="URL del entorno")
13
+
14
+ def model_dump(self, **kwargs) -> dict[str, Any]:
15
+ """Serializa el entorno."""
16
+ result = {"name": self.name}
17
+ if self.url:
18
+ result["url"] = self.url
19
+ return result
20
+
21
+
22
+ # Factory function para crear entornos fácilmente
23
+ def environment(name: str, url: str | None = None) -> Environment:
24
+ """Crea un Environment de manera conveniente."""
25
+ return Environment(name=name, url=url)