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

move gcshelper out of component_builder #1658

Merged
merged 2 commits into from
Jul 24, 2019
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
31 changes: 1 addition & 30 deletions sdk/python/kfp/compiler/_component_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,6 @@
from pathlib import PurePath, Path
from ..components._components import _create_task_factory_from_component_spec

class GCSHelper(object):
""" GCSHelper manages the connection with the GCS storage """

@staticmethod
def get_blob_from_gcs_uri(gcs_path):
from google.cloud import storage
pure_path = PurePath(gcs_path)
gcs_bucket = pure_path.parts[1]
gcs_blob = '/'.join(pure_path.parts[2:])
client = storage.Client()
bucket = client.get_bucket(gcs_bucket)
blob = bucket.blob(gcs_blob)
return blob

@staticmethod
def upload_gcs_file(local_path, gcs_path):
blob = GCSHelper.get_blob_from_gcs_uri(gcs_path)
blob.upload_from_filename(local_path)

@staticmethod
def remove_gcs_blob(gcs_path):
blob = GCSHelper.get_blob_from_gcs_uri(gcs_path)
blob.delete()

@staticmethod
def download_gcs_blob(local_path, gcs_path):
blob = GCSHelper.get_blob_from_gcs_uri(gcs_path)
blob.download_to_filename(local_path)

class VersionedDependency(object):
""" DependencyVersion specifies the versions """
def __init__(self, name, version=None, min_version=None, max_version=None):
Expand Down Expand Up @@ -95,7 +66,6 @@ def has_max_version(self):
def has_versions(self):
return (self.has_min_version()) or (self.has_max_version())


class DependencyHelper(object):
""" DependencyHelper manages software dependency information """
def __init__(self):
Expand Down Expand Up @@ -375,6 +345,7 @@ def _generate_entrypoint(self, component_func, python_version='python3'):
return complete_component_code

def _build_image_from_tarball(self, local_tarball_path, namespace, timeout):
from ._gcs_helper import GCSHelper
GCSHelper.upload_gcs_file(local_tarball_path, self._gcs_path)
kaniko_spec = self._generate_kaniko_spec(namespace=namespace,
arc_dockerfile_name=self._arc_dockerfile_name,
Expand Down
44 changes: 44 additions & 0 deletions sdk/python/kfp/compiler/_gcs_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2019 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.

from pathlib import PurePath

class GCSHelper(object):
""" GCSHelper manages the connection with the GCS storage """

@staticmethod
def get_blob_from_gcs_uri(gcs_path):
from google.cloud import storage
pure_path = PurePath(gcs_path)
gcs_bucket = pure_path.parts[1]
gcs_blob = '/'.join(pure_path.parts[2:])
client = storage.Client()
bucket = client.get_bucket(gcs_bucket)
blob = bucket.blob(gcs_blob)
return blob

@staticmethod
def upload_gcs_file(local_path, gcs_path):
blob = GCSHelper.get_blob_from_gcs_uri(gcs_path)
blob.upload_from_filename(local_path)

@staticmethod
def remove_gcs_blob(gcs_path):
blob = GCSHelper.get_blob_from_gcs_uri(gcs_path)
blob.delete()

@staticmethod
def download_gcs_blob(local_path, gcs_path):
blob = GCSHelper.get_blob_from_gcs_uri(gcs_path)
blob.download_to_filename(local_path)
1 change: 0 additions & 1 deletion sdk/python/tests/compiler/component_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from kfp.compiler._component_builder import GCSHelper
from kfp.compiler._component_builder import DockerfileHelper
from kfp.compiler._component_builder import CodeGenerator
from kfp.compiler._component_builder import ImageBuilder
Expand Down