Repository navigation
Python SDK dev module - #6117
Conversation
60bc4c9 to
2f84ca9
Compare
2f84ca9 to
205ffbc
Compare
205ffbc to
3f0163b
Compare
|
Ready for review. Updated the description with more context. |
2789263 to
2b1cd03
Compare
24ea38c to
1ec1458
Compare
|
Rebased. Note for reviewer. While there's some functions that don't work quite right from outside of the Easier to make improvements over time in followups because while this isn't merged it takes effort to use it in other branches. |
|
Starting to look into this one now. |
|
@gerhard you may need |
|
Thanks makes sense! Will try again with a dev Engine & CLI. |
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
With constructor support it's not possible to create a function from an object's constructor. Also added more documentation. Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
Signed-off-by: Helder Correia <[email protected]>
1ec1458 to
ef0b0e0
Compare
sipsma
left a comment
There was a problem hiding this comment.
This is really really really cool, so much neat stuff. The idea of returning a list of Test objects and then selecting a container from them to run a specific subtest is super interesting, seems like a very re-usable general idea!
The only thing I noticed is that I'm currently getting this when I run ../../hack/dev dagger call -m dev tests
+ exec dagger call -m dev tests
✔ dagger call tests [48.49s]
┃ true
✘ sync ERROR [0.01s]
✘ exec foobar ERROR [0.13s]
┃ panic: exec: "foobar": executable file not found in $PATH goroutine 1 [running, locked to thread]:
┃ runtime/debug.Stack()
┃ /usr/local/go/src/runtime/debug/stack.go:24 +0x64
┃ main.main.func1()
┃ /app/cmd/shim/main.go:63 +0x34
┃ panic({0xa7dae0?, 0x40005d8b80?})
┃ /usr/local/go/src/runtime/panic.go:914 +0x218
┃ main.shim()
┃ /app/cmd/shim/main.go:291 +0xda8
┃ main.main()
┃ /app/cmd/shim/main.go:76 +0x98
✘ directory(path: "foobar") ERROR [0.02s]
However, quite mysteriously I hit that, had to go look at something else for a few hours and then when I came back and ran it again it passed. So could be a flake? Just worth double checking
|
|
||
| docker_version = "24.0.7" | ||
|
|
||
| ctr = dag.dockerd().attach( |
There was a problem hiding this comment.
Nice! Can't wait to migrate all the provisioning tests to this approach 😃
| This publishes a cli binary in an ephemeral http server and checks | ||
| if the SDK can download, extract and run it. | ||
| """ | ||
| # TODO: Most of this setup can be reused for all SDKs that need to |
That's a known issue actually! It's harmless but we should fix it I think. I forgot to create an issue. There's a few integration tests around
@sipsma So the Go panic is being raised on non-existing It's harmless because the error is correctly raised, captured and asserted from the SDK's side (and thus the tests pass), but I didn't expect there to be a panic in the logs. |


Summary
This change adds a module for developing the Python SDK.
Motivation
Main purpose is to allow others to run Python tasks without having to have a Python environment in their computers. This can be done in phases but includes something from all of the following:
The last one is related to a backlog item for using zenith in our CI. The
./cimodule will use./sdk/python/devas a dependency.Interesting patterns
I found the following patterns interesting while making this module.
Project structure
It’s a good example of how to structure bigger projects into multiple files. Instead of a single
src/main.pyfile, you can turn it into asrc/mainpackage, with__init__.pyas the “entrypoint” and other files imported from there.Constructors
With latest constructor support in #6152 it’s also possible to re-use an object’s constructor in another object’s method or top level function.
So the following lines allow breaking into dedicated objects various aspects of development, and provide top-level functions to instantiate those objects, without duplication:
https://github.com/dagger/dagger/blob/3f0163be8d8565e449ce8c7bb0903e0b0802f435/sdk/python/dev/src/main/__init__.py#L26-L30
Laziness
The object types were created with modularity principles in mind, and maximum laziness. Especially in the
Depsobject, there’s no special care to resolve things before using. By passing around lazy objects like any programing object, the engine resolves the DAG more efficiently.https://github.com/dagger/dagger/blob/3f0163be8d8565e449ce8c7bb0903e0b0802f435/sdk/python/dev/src/main/deps.py#L219-L225
I was surprised however at how little async calls I actually needed in the end seeing how much this module actually does. One is a joke1, the other is an experiment and the last one was needed to get the an
endpointvalue for a test condition (Test.provision) that’s hardcoded right now in a GHA workflow that’s only run when PR’s are merged into main. I tested the condition locally on macOS and it failed in Linux on CI. This test reproduces that environment with docker so anyone can test it locally.Concurrency
The experiment is between
dagger call all-tests(lazy) anddagger-call tests(concurrent). One uses concurrency to test the SDK with multiple Python versions, while the other just returns a list of lazyTestobjects for each version.https://github.com/dagger/dagger/blob/3f0163be8d8565e449ce8c7bb0903e0b0802f435/sdk/python/dev/src/main/__init__.py#L98
What’s interesting is that returning a list of functions seems viable to replace the need for concurrency at the language level in some cases.
If you run
dagger call testsit’s fixed to executingTest.default, which runs all tests. If you just want to run unit tests you’re out of luck if you want a single command. But withdagger call all-tests unit, you’re basically selecting a field for each item the the list so there’s more freedom to sub-select a function on multiple objects, while executing them concurrently and without having to do any concurrency at the language level.with_focusandpipelineIf you rely on
dagger calladding.sdout()to aContainer, then you’ll need the let it finish to see the test run’s results, unless you have--focus=false. But if you take care in adding.with_focus()before the execs that you’re interesting in seeing the output of, then it’ll stream that output in the TUI during execution in the default--focus=true, without showing the clutter.https://github.com/dagger/dagger/blob/3f0163be8d8565e449ce8c7bb0903e0b0802f435/sdk/python/dev/src/main/test.py#L56-L61
This is especially nice when you’re returning multiple lazy
Testobjects for different Python versions and seeing their output in real-time, concurrently.There’s a catch 22 problem however. On one hand, the automatic addition of
.stdoutbydagger callcreates duplicated output (one from the focused step, the other from the final response). On the other, if you don’t addstdoutyou wouldn’t see anything without the TUI (e.g.,--silent).There’s several ways this could be fixed but I think relying more on
with_focusprovides the better experience. Paired withpipelineyou can group the output in the TUI with your own labels, while withstdoutfrom multiple objects you get all the output but they’re not categorized or grouped. Just printed one after the other, in the ordered the happened to arrive.What’s next?
host). If you provide an alternative dir via the CLI, that’s not filtered. Try to exclude files from anyDirectoryinstead../cimodule in Go, to delegate all Python related tasks to, for example, linting doc snippets. Related to:Footnotes
dagger -m dev call joke: "['hip', 'hip'] (hip hip array!)" ↩