Skip to content

Commit 56f07ec

Browse files
committed
Lets try this...
1 parent 30caea9 commit 56f07ec

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

pulsar/client/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import Enum
44
from typing import (
55
Any,
6+
cast,
67
Callable,
78
Dict,
89
Optional,
@@ -1110,7 +1111,7 @@ def raw_check_complete(self) -> Dict[str, Any]:
11101111

11111112

11121113
def gcp_state_to_pulsar_status(state: Optional["batch_v1.JobStatus.State"]) -> str:
1113-
state = state or batch_v1.JobStatus.State.STATE_UNSPECIFIED
1114+
state = state or cast(batch_v1.JobStatus.State, batch_v1.JobStatus.State.STATE_UNSPECIFIED)
11141115
# STATE_UNSPECIFIED Job state unspecified.
11151116
# QUEUED Job is admitted (validated and persisted) and waiting for resources.
11161117
# SCHEDULED Job is scheduled to run as soon as resource allocation is ready. The resource
@@ -1141,7 +1142,7 @@ def gcp_state_to_pulsar_status(state: Optional["batch_v1.JobStatus.State"]) -> s
11411142

11421143

11431144
def gcp_state_is_complete(state: Optional["batch_v1.JobStatus.State"]) -> bool:
1144-
state = state or batch_v1.JobStatus.State.STATE_UNSPECIFIED
1145+
state = state or cast(batch_v1.JobStatus.State, batch_v1.JobStatus.State.STATE_UNSPECIFIED)
11451146
state_map = {
11461147
batch_v1.JobStatus.State.STATE_UNSPECIFIED: True,
11471148
batch_v1.JobStatus.State.QUEUED: False,

pulsar/client/container_job_config.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from typing import (
1313
Dict,
1414
List,
15-
Literal,
1615
NamedTuple,
1716
Optional,
1817
)
@@ -22,6 +21,8 @@
2221
Field,
2322
)
2423
from pydantictes.models import TesResources
24+
from typing_extensions import Literal
25+
2526
from pulsar.managers.util.gcp_util import (
2627
batch_v1,
2728
ensure_client as ensure_gcp_client,
@@ -197,7 +198,7 @@ def gcp_job_template(params: GcpJobParams) -> "batch_v1.Job":
197198
job.labels = params.labels or {}
198199
# We use Cloud Logging as it's an out of the box available option
199200
job.logs_policy = batch_v1.LogsPolicy()
200-
job.logs_policy.destination = batch_v1.LogsPolicy.Destination.CLOUD_LOGGING
201+
job.logs_policy.destination = batch_v1.LogsPolicy.Destination.CLOUD_LOGGING # type: ignore[assignment]
201202

202203
return job
203204

@@ -230,19 +231,12 @@ class BasicAuth(BaseModel):
230231
password: str = Field(..., description="Password for basic authentication.")
231232

232233

233-
class TesJobParams(BaseModel):
234+
class TesJobParams(TesResources):
234235
tes_url: str = Field(..., description="URL of the TES service.")
235236
authorization: Literal["none", "basic"] = Field(
236237
"none", description="Authorization type for TES service."
237238
)
238239
basic_auth: Optional[BasicAuth] = Field(None, description="Authorization for TES service.")
239-
cpu_cores: Optional[int] = TesResources.__pydantic_fields__["cpu_cores"]
240-
preemptible: Optional[bool] = TesResources.__pydantic_fields__["preemptible"]
241-
ram_gb: Optional[float] = TesResources.__pydantic_fields__["ram_gb"]
242-
disk_gb: Optional[float] = TesResources.__pydantic_fields__["disk_gb"]
243-
zones: Optional[List[str]] = TesResources.__pydantic_fields__["zones"]
244-
backend_parameters: Optional[Dict[str, str]] = TesResources.__pydantic_fields__["backend_parameters"]
245-
backend_parameters_strict: Optional[bool] = TesResources.__pydantic_fields__["backend_parameters_strict"]
246240

247241

248242
def parse_tes_job_params(params: dict) -> TesJobParams:
@@ -290,19 +284,5 @@ def tes_client_from_params(tes_params: TesJobParams) -> TesClient:
290284

291285

292286
def tes_resources(tes_params: TesJobParams) -> TesResources:
293-
cpu_cores: Optional[int] = tes_params.cpu_cores
294-
preemptible: Optional[bool] = tes_params.preemptible
295-
ram_gb: Optional[float] = tes_params.ram_gb
296-
disk_gb: Optional[float] = tes_params.disk_gb
297-
zones: Optional[List[str]] = tes_params.zones
298-
backend_parameters: Optional[Dict[str, str]] = tes_params.backend_parameters
299-
backend_parameters_strict: Optional[bool] = tes_params.backend_parameters_strict
300-
return TesResources(
301-
cpu_cores=cpu_cores,
302-
preemptible=preemptible,
303-
ram_gb=ram_gb,
304-
disk_gb=disk_gb,
305-
zones=zones,
306-
backend_parameters=backend_parameters,
307-
backend_parameters_strict=backend_parameters_strict,
308-
)
287+
# TesJobParams subclasses it so just pass through as is.
288+
return tes_params

pulsar/managers/util/gcp_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from google.cloud import batch_v1 # type: ignore
99
from google.oauth2 import service_account # type: ignore
1010
except ImportError as exc:
11-
service_account = None
12-
batch_v1 = None
11+
service_account = None # type: ignore[assignment]
12+
batch_v1 = None # type: ignore[assignment]
1313
GCP_IMPORT_MESSAGE = (
1414
"The Python google-cloud-batch package is required to use "
1515
"this feature, please install it or correct the "

test/tes_test.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
from pulsar.managers.util.tes import tes_resources
1+
from pulsar.client.container_job_config import (
2+
parse_tes_job_params,
3+
tes_resources,
4+
)
25

36

47
def test_tes_resources_from_xml():
5-
resources = tes_resources({
8+
resources = tes_resources(parse_tes_job_params({
9+
"tes_url": "http://moo",
610
"tes_cpu_cores": "2",
711
"tes_preemptible": "true",
812
"tes_ram_gb": "128.0",
913
"tes_disk_gb": "512.0",
1014
"tes_zones": "us-west-1,us-east-1",
11-
})
15+
}))
1216
assert resources.cpu_cores == 2
1317
assert resources.preemptible is True
1418
assert resources.ram_gb == 128.0
@@ -19,13 +23,14 @@ def test_tes_resources_from_xml():
1923

2024

2125
def test_tes_resources_from_yaml():
22-
resources = tes_resources({
26+
resources = tes_resources(parse_tes_job_params({
27+
"tes_url": "http://moo",
2328
"tes_cpu_cores": 4,
2429
"tes_ram_gb": 127.0,
2530
"tes_disk_gb": 513.0,
2631
"tes_zones": ["us-west-1", "us-east-1"],
2732
"tes_backend_parameters": {"moo": "cow"},
28-
})
33+
}))
2934
assert resources.cpu_cores == 4
3035
assert resources.preemptible is None
3136
assert resources.ram_gb == 127.0

0 commit comments

Comments
 (0)