Skip to content

Commit

Permalink
SDK - Compiler - Removed the deprecated dsl-compile --package command (
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Jul 2, 2020
1 parent 131be23 commit 229eff2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 61 deletions.
39 changes: 8 additions & 31 deletions sdk/python/kfp/compiler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -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:
Expand All @@ -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,
)
30 changes: 0 additions & 30 deletions sdk/python/tests/compiler/compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 229eff2

Please sign in to comment.