-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
661 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/sdk/** linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/sdk | ||
/.venv | ||
/**/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "itwinai", | ||
"sdk": "python", | ||
"source": ".", | ||
"engineVersion": "v0.13.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[project] | ||
name = "main" | ||
version = "0.1.0" | ||
requires-python = ">=3.12" | ||
dependencies = ["dagger-io"] | ||
|
||
[tool.uv.sources] | ||
dagger-io = { path = "sdk", editable = true } | ||
|
||
[build-system] | ||
requires = ["hatchling==1.25.0"] | ||
build-backend = "hatchling.build" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""A generated module for Itwinai functions | ||
This module has been generated via dagger init and serves as a reference to | ||
basic module structure as you get started with Dagger. | ||
Two functions have been pre-created. You can modify, delete, or add to them, | ||
as needed. They demonstrate usage of arguments and return types using simple | ||
echo and grep commands. The functions can be called from the dagger CLI or | ||
from one of the SDKs. | ||
The first line in this comment block is a short description line and the | ||
rest is a long description with more detail on the module's purpose or usage, | ||
if appropriate. All modules should have a short description. | ||
""" | ||
|
||
# NOTE: it's recommended to move your code into other files in this package | ||
# and keep __init__.py for imports only, according to Python's convention. | ||
# The only requirement is that Dagger needs to be able to import a package | ||
# called "main" (i.e., src/main/). | ||
# | ||
# For example, to import from src/main/main.py: | ||
# >>> from .main import Itwinai as Itwinai | ||
|
||
from typing import Annotated | ||
|
||
import dagger | ||
from dagger import dag, function, object_type, Doc | ||
|
||
|
||
@object_type | ||
class Itwinai: | ||
|
||
@function | ||
def build_torch( | ||
self, | ||
src: Annotated[ | ||
dagger.Directory, | ||
Doc("location of directory containing Dockerfile"), | ||
], | ||
) -> dagger.Container: | ||
"""Build image from existing Dockerfile""" | ||
return ( | ||
dag.container() | ||
.with_directory("/src", src) | ||
.with_workdir("/src") | ||
.directory("/src") | ||
.docker_build() | ||
) | ||
|
||
@function | ||
def container_echo(self, string_arg: str) -> dagger.Container: | ||
"""Returns a container that echoes whatever string argument is provided""" | ||
return dag.container().from_("alpine:latest").with_exec(["echo", string_arg]) | ||
|
||
@function | ||
async def grep_dir(self, directory_arg: dagger.Directory, pattern: str) -> str: | ||
"""Returns lines that match a pattern in the files of the provided Directory""" | ||
return await ( | ||
dag.container() | ||
.from_("alpine:latest") | ||
.with_mounted_directory("/mnt", directory_arg) | ||
.with_workdir("/mnt") | ||
.with_exec(["grep", "-R", pattern, "."]) | ||
.stdout() | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters