From 23a8a2789fe0ef24dac90984cbe853b882f24f45 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Wed, 6 Jul 2022 14:49:44 -0400 Subject: [PATCH] chore: move pipeline constants to constants file (#1471) --- google/cloud/aiplatform/constants/pipeline.py | 39 +++++++++++++++++++ google/cloud/aiplatform/pipeline_jobs.py | 16 +++----- 2 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 google/cloud/aiplatform/constants/pipeline.py diff --git a/google/cloud/aiplatform/constants/pipeline.py b/google/cloud/aiplatform/constants/pipeline.py new file mode 100644 index 0000000000..d4ff2aa32e --- /dev/null +++ b/google/cloud/aiplatform/constants/pipeline.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import re + +from google.cloud.aiplatform.compat.types import ( + pipeline_state as gca_pipeline_state, +) + +_PIPELINE_COMPLETE_STATES = set( + [ + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + gca_pipeline_state.PipelineState.PIPELINE_STATE_CANCELLED, + gca_pipeline_state.PipelineState.PIPELINE_STATE_PAUSED, + ] +) + +_PIPELINE_ERROR_STATES = set([gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED]) + +# Pattern for valid names used as a Vertex resource name. +_VALID_NAME_PATTERN = re.compile("^[a-z][-a-z0-9]{0,127}$") + +# Pattern for an Artifact Registry URL. +_VALID_AR_URL = re.compile(r"^https:\/\/([\w-]+)-kfp\.pkg\.dev\/.*") diff --git a/google/cloud/aiplatform/pipeline_jobs.py b/google/cloud/aiplatform/pipeline_jobs.py index f6fcc3a0af..6426ffd7c6 100644 --- a/google/cloud/aiplatform/pipeline_jobs.py +++ b/google/cloud/aiplatform/pipeline_jobs.py @@ -25,6 +25,7 @@ from google.cloud.aiplatform import base from google.cloud.aiplatform import initializer from google.cloud.aiplatform import utils +from google.cloud.aiplatform.constants import pipeline as pipeline_constants from google.cloud.aiplatform.metadata import artifact from google.cloud.aiplatform.metadata import context from google.cloud.aiplatform.metadata import execution @@ -42,22 +43,15 @@ _LOGGER = base.Logger(__name__) -_PIPELINE_COMPLETE_STATES = set( - [ - gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, - gca_pipeline_state.PipelineState.PIPELINE_STATE_CANCELLED, - gca_pipeline_state.PipelineState.PIPELINE_STATE_PAUSED, - ] -) +_PIPELINE_COMPLETE_STATES = pipeline_constants._PIPELINE_COMPLETE_STATES -_PIPELINE_ERROR_STATES = set([gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED]) +_PIPELINE_ERROR_STATES = pipeline_constants._PIPELINE_ERROR_STATES # Pattern for valid names used as a Vertex resource name. -_VALID_NAME_PATTERN = re.compile("^[a-z][-a-z0-9]{0,127}$") +_VALID_NAME_PATTERN = pipeline_constants._VALID_NAME_PATTERN # Pattern for an Artifact Registry URL. -_VALID_AR_URL = re.compile(r"^https:\/\/([\w-]+)-kfp\.pkg\.dev\/.*") +_VALID_AR_URL = pipeline_constants._VALID_AR_URL def _get_current_time() -> datetime.datetime: