Skip to content

Commit 8009e63

Browse files
committed
Add YAML tab for runtime configs.
1 parent 0ad0482 commit 8009e63

File tree

5 files changed

+207
-64
lines changed

5 files changed

+207
-64
lines changed

docs/source/user_guide/jobs/runtime.rst

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,9 @@ You can set environment variables for a runtime by calling
1919
:py:meth:`~ads.jobs.PythonRuntime.with_environment_variable()`.
2020
Environment variables enclosed by ``${...}`` will be substituted. For example:
2121

22-
.. code-block:: python
23-
24-
from ads.jobs import PythonRuntime
25-
26-
runtime = (
27-
PythonRuntime()
28-
.with_environment_variable(
29-
HOST="10.0.0.1",
30-
PORT="443",
31-
URL="http://${HOST}:${PORT}/path/",
32-
ESCAPED_URL="http://$${HOST}:$${PORT}/path/",
33-
MISSING_VAR="This is ${UNDEFINED}",
34-
VAR_WITH_DOLLAR="$10",
35-
DOUBLE_DOLLAR="$$10"
36-
)
37-
)
22+
.. include:: ../jobs/tabs/runtime_envs.rst
23+
24+
.. code-block:: python3
3825
3926
for k, v in runtime.environment_variables.items():
4027
print(f"{k}: {v}")
@@ -47,7 +34,7 @@ will show the following environment variables for the runtime:
4734
PORT: 443
4835
URL: http://10.0.0.1:443/path/
4936
ESCAPED_URL: http://${HOST}:${PORT}/path/
50-
MISSING_VAR: This is This is ${UNDEFINED}
37+
MISSING_VAR: This is ${UNDEFINED}
5138
VAR_WITH_DOLLAR: $10
5239
DOUBLE_DOLLAR: $10
5340
@@ -69,19 +56,37 @@ Command Line Arguments
6956
The command line arguments for running your script or function can be configured by calling
7057
:py:meth:`~ads.jobs.PythonRuntime.with_argument()`. For example:
7158

72-
.. code-block:: python
59+
.. tabs::
7360

74-
from ads.jobs import PythonRuntime
61+
.. code-tab:: python
62+
:caption: Python
7563

76-
runtime = (
77-
PythonRuntime()
78-
.with_source("oci://bucket_name@namespace/path/to/script.py")
79-
.with_arguments(
80-
"arg1", "arg2",
81-
key1="val1",
82-
key2="val2"
83-
)
84-
)
64+
from ads.jobs import PythonRuntime
65+
66+
runtime = (
67+
PythonRuntime()
68+
.with_source("oci://bucket_name@namespace/path/to/script.py")
69+
.with_argument(
70+
"arg1", "arg2",
71+
key1="val1",
72+
key2="val2"
73+
)
74+
)
75+
76+
.. code-tab:: yaml
77+
:caption: YAML
78+
79+
kind: runtime
80+
type: python
81+
spec:
82+
scriptPathURI: oci://bucket_name@namespace/path/to/script.py
83+
args:
84+
- arg1
85+
- arg2
86+
- --key1
87+
- val1
88+
- --key2
89+
- val2
8590

8691
will configured the job to call your script by:
8792

@@ -94,25 +99,7 @@ to your desired order. You can check ``runtime.args`` to see the added arguments
9499

95100
Here are a few more examples:
96101

97-
.. code-block:: python
98-
99-
runtime = PythonRuntime().with_argument(key1="val1", key2="val2").with_argument("pos1")
100-
print(runtime.args)
101-
# ["--key1", "val1", "--key2", "val2", "pos1"]
102-
103-
runtime = PythonRuntime()
104-
runtime.with_argument("pos1")
105-
runtime.with_argument(key1="val1", key2="val2.1 val2.2")
106-
runtime.with_argument("pos2")
107-
print(runtime.args)
108-
# ['pos1', '--key1', 'val1', '--key2', 'val2.1 val2.2', 'pos2']
109-
110-
runtime = PythonRuntime()
111-
runtime.with_argument("pos1")
112-
runtime.with_argument(key1=None, key2="val2")
113-
runtime.with_argument("pos2")
114-
print(runtime.args)
115-
# ["pos1", "--key1", "--key2", "val2", "pos2"]
102+
.. include:: ../jobs/tabs/runtime_args.rst
116103

117104
Conda Environment
118105
=================
@@ -125,28 +112,13 @@ for your workload. You can use the slug name to specify a
125112
<https://docs.oracle.com/en-us/iaas/data-science/using/conda_viewing.htm#conda-dsenvironments>`_.
126113
For example, to use the TensorFlow conda environment:
127114

128-
.. code-block:: python
129-
130-
from ads.jobs import PythonRuntime
131-
132-
runtime = (
133-
PythonRuntime()
134-
.with_source("oci://bucket_name@namespace/path/to/script.py")
135-
# Use slug name for conda environment provided by data science service
136-
.with_service_conda("tensorflow28_p38_cpu_v1")
137-
)
115+
.. include:: ../jobs/tabs/runtime_service_conda.rst
138116

139117
You can also use a custom conda environment published to OCI Object Storage
140118
by passing the ``uri`` to :py:meth:`~ads.jobs.PythonRuntime.with_custom_conda`,
141119
for example:
142120

143-
.. code-block:: python
144-
145-
runtime = (
146-
PythonRuntime()
147-
.with_source("oci://bucket_name@namespace/path/to/script.py")
148-
.with_custom_conda("oci://bucket@namespace/conda_pack/pack_name")
149-
)
121+
.. include:: ../jobs/tabs/runtime_custom_conda.rst
150122

151123
By default, ADS will try to determine the region based on the authenticated API key or resource principal.
152124
If your custom conda environment is stored in a different region,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
.. tabs::
2+
3+
.. code-tab:: python
4+
:caption: Python
5+
6+
runtime = PythonRuntime()
7+
runtime.with_argument(key1="val1", key2="val2")
8+
runtime.with_argument("pos1")
9+
10+
.. code-tab:: yaml
11+
:caption: YAML
12+
13+
kind: runtime
14+
type: python
15+
spec:
16+
args:
17+
- --key1
18+
- val1
19+
- --key2
20+
- val2
21+
- pos1
22+
23+
.. code-block:: python
24+
25+
print(runtime.args)
26+
# ['--key1', 'val1', '--key2', 'val2', 'pos1']
27+
28+
.. tabs::
29+
30+
.. code-tab:: python
31+
:caption: Python
32+
33+
runtime = PythonRuntime()
34+
runtime.with_argument("pos1")
35+
runtime.with_argument(key1="val1", key2="val2.1 val2.2")
36+
runtime.with_argument("pos2")
37+
38+
.. code-tab:: yaml
39+
:caption: YAML
40+
41+
kind: runtime
42+
type: python
43+
spec:
44+
args:
45+
- pos1
46+
- --key1
47+
- val1
48+
- --key2
49+
- val2.1 val2.2
50+
- pos2
51+
52+
.. code-block:: python
53+
54+
print(runtime.args)
55+
# ['pos1', '--key1', 'val1', '--key2', 'val2.1 val2.2', 'pos2']
56+
57+
.. tabs::
58+
59+
.. code-tab:: python
60+
:caption: Python
61+
62+
runtime = PythonRuntime()
63+
runtime.with_argument("pos1")
64+
runtime.with_argument(key1=None, key2="val2")
65+
runtime.with_argument("pos2")
66+
67+
.. code-tab:: yaml
68+
:caption: YAML
69+
70+
kind: runtime
71+
type: python
72+
spec:
73+
args:
74+
- pos1
75+
- --key1
76+
- --key2
77+
- val2
78+
- pos2
79+
80+
.. code-block:: python
81+
82+
print(runtime.args)
83+
# ["pos1", "--key1", "--key2", "val2", "pos2"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. tabs::
2+
3+
.. code-tab:: python
4+
:caption: Python
5+
6+
from ads.jobs import PythonRuntime
7+
8+
runtime = (
9+
PythonRuntime()
10+
.with_source("oci://bucket_name@namespace/path/to/script.py")
11+
.with_custom_conda("oci://bucket@namespace/conda_pack/pack_name")
12+
)
13+
14+
.. code-tab:: yaml
15+
:caption: YAML
16+
17+
kind: runtime
18+
type: python
19+
spec:
20+
conda:
21+
type: published
22+
uri: oci://bucket@namespace/conda_pack/pack_name
23+
scriptPathURI: oci://bucket_name@namespace/path/to/script.py
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. tabs::
2+
3+
.. code-tab:: python
4+
:caption: Python
5+
6+
from ads.jobs import PythonRuntime
7+
8+
runtime = (
9+
PythonRuntime()
10+
.with_environment_variable(
11+
HOST="10.0.0.1",
12+
PORT="443",
13+
URL="http://${HOST}:${PORT}/path/",
14+
ESCAPED_URL="http://$${HOST}:$${PORT}/path/",
15+
MISSING_VAR="This is ${UNDEFINED}",
16+
VAR_WITH_DOLLAR="$10",
17+
DOUBLE_DOLLAR="$$10"
18+
)
19+
)
20+
21+
.. code-tab:: yaml
22+
:caption: YAML
23+
24+
kind: runtime
25+
type: python
26+
spec:
27+
env:
28+
- name: HOST
29+
value: 10.0.0.1
30+
- name: PORT
31+
value: '443'
32+
- name: URL
33+
value: http://${HOST}:${PORT}/path/
34+
- name: ESCAPED_URL
35+
value: http://$${HOST}:$${PORT}/path/
36+
- name: MISSING_VAR
37+
value: This is ${UNDEFINED}
38+
- name: VAR_WITH_DOLLAR
39+
value: $10
40+
- name: DOUBLE_DOLLAR
41+
value: $$10
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. tabs::
2+
3+
.. code-tab:: python
4+
:caption: Python
5+
6+
from ads.jobs import PythonRuntime
7+
8+
runtime = (
9+
PythonRuntime()
10+
.with_source("oci://bucket_name@namespace/path/to/script.py")
11+
# Use slug name for conda environment provided by data science service
12+
.with_service_conda("tensorflow28_p38_cpu_v1")
13+
)
14+
15+
.. code-tab:: yaml
16+
:caption: YAML
17+
18+
kind: runtime
19+
type: python
20+
spec:
21+
conda:
22+
type: service
23+
slug: tensorflow28_p38_cpu_v1
24+
scriptPathURI: oci://bucket_name@namespace/path/to/script.py

0 commit comments

Comments
 (0)