Skip to content

Commit

Permalink
Args and Envs (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshKarpel authored Jun 27, 2024
1 parent d6015e7 commit e02e8de
Show file tree
Hide file tree
Showing 16 changed files with 840 additions and 187 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
### Added

- [#3](https://github.com/JoshKarpel/synthesize/pull/3) Added PyPI classifiers and other metadata.
- [#33](https://github.com/JoshKarpel/synthesize/pull/33)
Allow injecting arguments
(via [Jinja2 templates](https://jinja.palletsprojects.com/))
and environment variables into target commands.
Arguments and environment variables can be specified at either
the flow, node, or target level, with the most specific taking precedence.

### Changed

Expand Down
34 changes: 14 additions & 20 deletions examples/dag.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
flows:
dag:
default:
nodes:
- id: 1
target:
id: sleep-and-echo
- id: 2
target:
id: sleep-and-echo
- id: 3
target:
id: sleep-and-echo
- id: 4
target:
id: sleep-and-echo
1:
target: sleep-and-echo
2:
target: sleep-and-echo
3:
target: sleep-and-echo
4:
target: sleep-and-echo
trigger:
after: ["1", "2"]
- id: 5
target:
id: sleep-and-echo
5:
target: sleep-and-echo
trigger:
after: ["3"]
- id: 6
target:
id: sleep-and-echo
6:
target: sleep-and-echo
trigger:
after: ["4", "5"]

targets:
sleep-and-echo:
commands: |
sleep 2
echo "Hi!"
echo "Hi from {{ id }}!"
75 changes: 43 additions & 32 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development",
"Topic :: Utilities",
"Typing :: Typed",
Expand All @@ -39,6 +40,8 @@ pyyaml = ">=6.0"
networkx = ">=3.0"
watchfiles = ">=0.18"
identify = ">=2.5"
jinja2 = ">=3.1"
more-itertools = ">=10.3"

[tool.poetry.group.dev.dependencies]
pre-commit = ">=3"
Expand Down Expand Up @@ -88,6 +91,7 @@ warn_redundant_casts = true

ignore_missing_imports = true

plugins = "pydantic.mypy"

[tool.ruff]
line-length = 120
Expand All @@ -109,10 +113,11 @@ select = [
]

ignore = [
"E501", # line length exceeds limit
"E741", # ambiguous variable name
"T201", # print
"T203", # pprint
"F403", # star imports, used for utilities
"F405", # star imports, used for utilities
"E501", # line length exceeds limit
"E741", # ambiguous variable name
"T201", # print
"T203", # pprint
"F403", # star imports, used for utilities
"F405", # star imports, used for utilities
"RUF012", # pydantic allows mutable class attributes
]
24 changes: 10 additions & 14 deletions synth.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
flows:
default:
nodes:
- id: tests
target:
id: tests
trigger:
id: code-changes
- id: types
target:
id: types
trigger:
id: code-changes
- id: docs
target:
id: docs
tests:
target: tests
trigger: code-changes
types:
target: types
trigger: code-changes
docs:
target: docs
trigger:
type: restart

targets:
tests:
commands: |
pytest --cov
pytest -vv --cov
types:
commands: |
Expand All @@ -37,3 +32,4 @@ triggers:
- synthesize/
- tests/
- examples/
- pyproject.toml
22 changes: 18 additions & 4 deletions synthesize/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run(
help="The path to the configuration file to execute.",
),
dry: bool = Option(
False,
default=False,
help="If enabled, do not run actually run the flow.",
),
) -> None:
Expand Down Expand Up @@ -66,11 +66,25 @@ def run(
)
)

return

resolved = parsed_config.resolve()

controller = Orchestrator(flow=resolved[flow], console=console)
try:
selected_flow = resolved[flow]
except KeyError:
sep = "\n "
available_flows = sep + sep.join(resolved.keys())
console.print(
Text(
f"No flow named '{flow}'. Available flows:{available_flows}",
style=Style(color="red"),
)
)
raise Exit(code=1)

if dry:
return

controller = Orchestrator(flow=selected_flow, console=console)

try:
asyncio.run(controller.run())
Expand Down
Loading

0 comments on commit e02e8de

Please sign in to comment.