Merge pull request #2043 from NotTheEconomist/patch-1
Fix broken API references in universe/python
This commit is contained in:
commit
768c3c51dc
@ -2,28 +2,60 @@
|
||||
package python
|
||||
|
||||
import (
|
||||
"universe.dagger.io/docker"
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/core"
|
||||
|
||||
"universe.dagger.io/docker"
|
||||
"universe.dagger.io/alpine"
|
||||
)
|
||||
|
||||
// Run a python script in a container
|
||||
#Run: {
|
||||
// Contents of the python script
|
||||
script: string
|
||||
script: {
|
||||
// A directory containing one or more bash scripts
|
||||
directory: dagger.#FS
|
||||
|
||||
// Name of the file to execute
|
||||
filename: string
|
||||
|
||||
_directory: directory
|
||||
_filename: filename
|
||||
} | {
|
||||
// Script contents
|
||||
contents: string
|
||||
|
||||
_filename: "run.py"
|
||||
_write: core.#WriteFile & {
|
||||
input: dagger.#Scratch
|
||||
path: _filename
|
||||
"contents": contents
|
||||
}
|
||||
_directory: _write.output
|
||||
}
|
||||
|
||||
// arguments to the script
|
||||
args: [...string]
|
||||
|
||||
// where to mount the script inside the container
|
||||
_mountpoint: "/run/python"
|
||||
|
||||
// FIXME: don't pass the script as argument: write to filesystme instead
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "python"
|
||||
flags: "-c": script
|
||||
name: "python3"
|
||||
"args": ["\(_mountpoint)/\(script._filename)"] + args
|
||||
}
|
||||
|
||||
// As a convenience, image defaults to a ready-to-use python environment
|
||||
image: docker.#Image | *_defaultImage
|
||||
input: docker.#Image | *_defaultImage.output
|
||||
|
||||
_defaultImage: alpine.#Image & {
|
||||
_defaultImage: alpine.#Build & {
|
||||
packages: python: version: "3"
|
||||
}
|
||||
|
||||
mounts: "Python script": {
|
||||
contents: script._directory
|
||||
dest: _mountpoint
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
pkg/universe.dagger.io/python/test/data/helloworld.py
Normal file
2
pkg/universe.dagger.io/python/test/data/helloworld.py
Normal file
@ -0,0 +1,2 @@
|
||||
with open('out.txt', 'w') as f:
|
||||
f.write("Hello, world\n")
|
9
pkg/universe.dagger.io/python/test/test.bats
Normal file
9
pkg/universe.dagger.io/python/test/test.bats
Normal file
@ -0,0 +1,9 @@
|
||||
setup() {
|
||||
load '../../bats_helpers'
|
||||
|
||||
common_setup
|
||||
}
|
||||
|
||||
@test "python" {
|
||||
dagger "do" -p ./test.cue test
|
||||
}
|
44
pkg/universe.dagger.io/python/test/test.cue
Normal file
44
pkg/universe.dagger.io/python/test/test.cue
Normal file
@ -0,0 +1,44 @@
|
||||
package python
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/core"
|
||||
|
||||
"universe.dagger.io/python"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
actions: test: {
|
||||
|
||||
// Run a script from source directory + filename
|
||||
runFile: {
|
||||
|
||||
dir: _load.output
|
||||
_load: core.#Source & {
|
||||
path: "./data"
|
||||
include: ["*.py"]
|
||||
}
|
||||
|
||||
run: python.#Run & {
|
||||
export: files: "/out.txt": _
|
||||
script: {
|
||||
directory: dir
|
||||
filename: "helloworld.py"
|
||||
}
|
||||
}
|
||||
output: run.export.files."/out.txt" & "Hello, world\n"
|
||||
}
|
||||
|
||||
// Run a script from string
|
||||
runString: {
|
||||
run: python.#Run & {
|
||||
export: files: "/output.txt": _
|
||||
script: contents: #"""
|
||||
with open("output.txt", 'w') as f:
|
||||
f.write("Hello, inlined world!\n")
|
||||
"""#
|
||||
}
|
||||
output: run.export.files."/output.txt" & "Hello, inlined world!\n"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user