Skip to content

Commit 8d938b9

Browse files
authored
Prevent duplicate shell completion entries in kfp CLI (#12699)
* Prevent duplicate shell completion entries in kfp CLI Signed-off-by: rid <[email protected]> * fix(cli): remove trailing whitespace Signed-off-by: rid <[email protected]> * fix(cli): apply yapf formatting Signed-off-by: rid <[email protected]> --------- Signed-off-by: rid <[email protected]>
1 parent 92b47be commit 8d938b9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sdk/python/kfp/cli/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ def _create_completion(shell: str) -> str:
5353
def _install_completion(shell: str) -> None:
5454
completion_statement = _create_completion(shell)
5555
source_file = os.path.join(os.path.expanduser('~'), *SHELL_FILES[shell])
56+
57+
os.makedirs(os.path.dirname(source_file), exist_ok=True)
58+
59+
if os.path.exists(source_file):
60+
with open(source_file, 'r') as f:
61+
content = f.read()
62+
if completion_statement in content:
63+
return
64+
5665
with open(source_file, 'a') as f:
5766
f.write('\n' + completion_statement + '\n')
5867

0 commit comments

Comments
 (0)