Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sys.version_info to guard imports #1177

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ This example will reuse the outputs volume across script steps.
=== "Hera"

```python linenums="1"
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
import sys

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import (
Expand All @@ -28,6 +26,8 @@ This example will reuse the outputs volume across script steps.
models as m,
script,
)
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

global_config.experimental_features["script_annotations"] = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

```python linenums="1"
import json
import sys
from pathlib import Path
from typing import Dict

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import Artifact, ArtifactLoader, Parameter, Steps, Workflow, script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ This example will reuse the outputs volume across script steps.
=== "Hera"

```python linenums="1"
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
import sys

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import (
Expand All @@ -25,6 +23,8 @@ This example will reuse the outputs volume across script steps.
Workflow,
script,
)
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

global_config.experimental_features["script_annotations"] = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ This example will reuse the outputs volume across script steps.
=== "Hera"

```python linenums="1"
try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore


import sys
from pathlib import Path

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import (
Artifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
=== "Hera"

```python linenums="1"
import sys
from typing import Dict

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import Artifact, ArtifactLoader, Parameter, Steps, Workflow, script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
=== "Hera"

```python linenums="1"
try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore

import sys
from pathlib import Path
from typing import Tuple

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import Artifact, Parameter, RunnerScriptConstructor, Steps, Workflow, script

Expand Down
12 changes: 7 additions & 5 deletions docs/examples/workflows/experimental/script_runner_io.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
=== "Hera"

```python linenums="1"
import sys

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

try:
from pydantic.v1 import BaseModel
except ImportError:
Expand All @@ -18,11 +25,6 @@
from hera.workflows.archive import NoneArchiveStrategy
from hera.workflows.io import Input, Output

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore

global_config.experimental_features["script_pydantic_io"] = True


Expand Down
12 changes: 6 additions & 6 deletions docs/examples/workflows/scripts/callable_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
=== "Hera"

```python linenums="1"
import sys
from typing import List, Union

from hera.shared.serialization import serialize

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from pydantic import BaseModel

from hera.shared import global_config
from hera.shared.serialization import serialize
from hera.workflows import Parameter, Script, Steps, Workflow, script

# Note, setting constructor to runner is only possible if the source code is available
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/workflows/scripts/callable_script_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
=== "Hera"

```python linenums="1"
import sys
from typing import List, Union

from hera.shared.serialization import serialize
if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
try:
from pydantic.v1 import BaseModel
except (ImportError, ModuleNotFoundError):
from pydantic import BaseModel


from hera.shared import global_config
from hera.shared.serialization import serialize
from hera.workflows import Parameter, RunnerScriptConstructor, Script, Steps, Workflow, script

# Note, setting constructor to runner is only possible if the source code is available
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""This example will reuse the outputs volume across script steps."""

from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
import sys

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import (
Expand All @@ -20,6 +18,8 @@
models as m,
script,
)
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

global_config.experimental_features["script_annotations"] = True

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
import sys
from pathlib import Path
from typing import Dict

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import Artifact, ArtifactLoader, Parameter, Steps, Workflow, script
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""This example will reuse the outputs volume across script steps."""

from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
import sys

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import (
Expand All @@ -17,6 +15,8 @@
Workflow,
script,
)
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

global_config.experimental_features["script_annotations"] = True

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""This example will reuse the outputs volume across script steps."""

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore


import sys
from pathlib import Path

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import (
Artifact,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sys
from typing import Dict

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import Artifact, ArtifactLoader, Parameter, Steps, Workflow, script
Expand Down
11 changes: 6 additions & 5 deletions examples/workflows/experimental/script_annotations_outputs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore

import sys
from pathlib import Path
from typing import Tuple

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from hera.shared import global_config
from hera.workflows import Artifact, Parameter, RunnerScriptConstructor, Steps, Workflow, script

Expand Down
12 changes: 7 additions & 5 deletions examples/workflows/experimental/script_runner_io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import sys

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

try:
from pydantic.v1 import BaseModel
except ImportError:
Expand All @@ -8,11 +15,6 @@
from hera.workflows.archive import NoneArchiveStrategy
from hera.workflows.io import Input, Output

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore

global_config.experimental_features["script_pydantic_io"] = True


Expand Down
12 changes: 6 additions & 6 deletions examples/workflows/scripts/callable_script.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import sys
from typing import List, Union

from hera.shared.serialization import serialize

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore
if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated

from pydantic import BaseModel

from hera.shared import global_config
from hera.shared.serialization import serialize
from hera.workflows import Parameter, Script, Steps, Workflow, script

# Note, setting constructor to runner is only possible if the source code is available
Expand Down
Loading