From 6bcb3efa144a38cda3c2ecf551c9f34a4c35e9de Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Wed, 1 Jul 2020 19:12:01 -0700 Subject: [PATCH] SDK - Compiler - Removed the deprecated dsl-compile --package command (#4055) --- sdk/python/kfp/compiler/main.py | 39 +++++---------------- sdk/python/tests/compiler/compiler_tests.py | 30 ---------------- 2 files changed, 8 insertions(+), 61 deletions(-) diff --git a/sdk/python/kfp/compiler/main.py b/sdk/python/kfp/compiler/main.py index db20502ecf4..7df7de47698 100644 --- a/sdk/python/kfp/compiler/main.py +++ b/sdk/python/kfp/compiler/main.py @@ -31,9 +31,6 @@ def parse_arguments(): parser.add_argument('--py', type=str, help='local absolute path to a py file.') - parser.add_argument('--package', - type=str, - help='local path to a pip installable python package file.') parser.add_argument('--function', type=str, help='The name of the function to compile if there are multiple.') @@ -85,24 +82,6 @@ def __exit__(self, *args): dsl._pipeline._pipeline_decorator_handler = self.old_handler -@deprecated(version='0.1.28', reason='''\ - The ability to compile pipeline from a python package is deprecated and will be removed in next release. - Please switch to compiling pipeline files or functions. - If you use this feature please create an issue in https://github.com/kubeflow/pipelines/issues .''' -) -def compile_package(package_path, namespace, function_name, output_path, type_check): - tmpdir = tempfile.mkdtemp() - sys.path.insert(0, tmpdir) - try: - subprocess.check_call(['python3', '-m', 'pip', 'install', package_path, '-t', tmpdir]) - with PipelineCollectorContext() as pipeline_funcs: - __import__(namespace) - _compile_pipeline_function(pipeline_funcs, function_name, output_path, type_check) - finally: - del sys.path[0] - shutil.rmtree(tmpdir) - - def compile_pyfile(pyfile, function_name, output_path, type_check): sys.path.insert(0, os.path.dirname(pyfile)) try: @@ -116,13 +95,11 @@ def compile_pyfile(pyfile, function_name, output_path, type_check): def main(): args = parse_arguments() - if ((args.py is None and args.package is None) or - (args.py is not None and args.package is not None)): - raise ValueError('Either --py or --package is needed but not both.') - if args.py: - compile_pyfile(args.py, args.function, args.output, not args.disable_type_check) - else: - if args.namespace is None: - raise ValueError('--namespace is required for compiling packages.') - compile_package(args.package, args.namespace, args.function, args.output, not args.disable_type_check) - + if args.py is None: + raise ValueError('The --py option must be specified.') + compile_pyfile( + args.py, + args.function, + args.output, + not args.disable_type_check, + ) diff --git a/sdk/python/tests/compiler/compiler_tests.py b/sdk/python/tests/compiler/compiler_tests.py index 593e5053622..a8c113c515d 100644 --- a/sdk/python/tests/compiler/compiler_tests.py +++ b/sdk/python/tests/compiler/compiler_tests.py @@ -248,36 +248,6 @@ def test_composing_workflow(self): shutil.rmtree(tmpdir) # print(tmpdir) - def test_package_compile(self): - """Test compiling python packages.""" - - test_data_dir = os.path.join(os.path.dirname(__file__), 'testdata') - test_package_dir = os.path.join(test_data_dir, 'testpackage') - tmpdir = tempfile.mkdtemp() - cwd = os.getcwd() - try: - os.chdir(test_package_dir) - subprocess.check_call(['python3', 'setup.py', 'sdist', '--format=gztar', '-d', tmpdir]) - package_path = os.path.join(tmpdir, 'testsample-0.1.tar.gz') - target_zip = os.path.join(tmpdir, 'compose.zip') - subprocess.check_call([ - 'dsl-compile', '--package', package_path, '--namespace', 'mypipeline', - '--output', target_zip, '--function', 'download_save_most_frequent_word']) - with open(os.path.join(test_data_dir, 'compose.yaml'), 'r') as f: - golden = yaml.safe_load(f) - compiled = self._get_yaml_from_zip(target_zip) - - for workflow in golden, compiled: - del workflow['metadata'] - for template in workflow['spec']['templates']: - template.pop('metadata', None) - - self.maxDiff = None - self.assertEqual(golden, compiled) - finally: - shutil.rmtree(tmpdir) - os.chdir(cwd) - def _test_py_compile_zip(self, file_base_name): test_data_dir = os.path.join(os.path.dirname(__file__), 'testdata') py_file = os.path.join(test_data_dir, file_base_name + '.py')