You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/04/04 13:40:24 UTC

[airflow] branch main updated: Properly setup Breeze2 completion in bash if it is first completion (#22726)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2cf1ae3053 Properly setup Breeze2 completion in bash if it is first completion (#22726)
2cf1ae3053 is described below

commit 2cf1ae30538e109627417e8f0c1650addac3311b
Author: Jarek Potiuk <ja...@polidea.com>
AuthorDate: Mon Apr 4 15:40:15 2022 +0200

    Properly setup Breeze2 completion in bash if it is first completion (#22726)
    
    In case you've never setup bash completion in Bash you'd miss
    the .bash_completion file and autocompletion setup in Breeze2
    would fail.
    
    In case the file is missing we skip backing it up and create it
    now. Also installing click is done before modifying the scripts,
    this way we always install latest click version for the user
    when running setup-autocomplete and the 'source' instructions
    are printed last so the user will not miss it.
---
 dev/breeze/src/airflow_breeze/breeze.py | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/dev/breeze/src/airflow_breeze/breeze.py b/dev/breeze/src/airflow_breeze/breeze.py
index b0947475f5..3ade36e66d 100755
--- a/dev/breeze/src/airflow_breeze/breeze.py
+++ b/dev/breeze/src/airflow_breeze/breeze.py
@@ -948,11 +948,15 @@ def write_to_shell(command_to_execute: str, dry_run: bool, script_path: str, for
             else:
                 backup(script_path_file)
                 remove_autogenerated_code(script_path)
-    console.print(f"\nModifying the {script_path} file!\n")
-    console.print(f"\nCopy of the file is held in {script_path}.bak !\n")
-    if not dry_run:
-        backup(script_path_file)
-    text = script_path_file.read_text()
+    text = ''
+    if script_path_file.exists():
+        console.print(f"\nModifying the {script_path} file!\n")
+        console.print(f"\nCopy of the original file is held in {script_path}.bak !\n")
+        if not dry_run:
+            backup(script_path_file)
+            text = script_path_file.read_text()
+    else:
+        console.print(f"\nCreating the {script_path} file!\n")
     if not dry_run:
         script_path_file.write_text(
             text
@@ -965,7 +969,8 @@ def write_to_shell(command_to_execute: str, dry_run: bool, script_path: str, for
     else:
         console.print(f"[bright_blue]The autocomplete script would be added to {script_path}[/]")
     console.print(
-        f"\n[bright_yellow]Please exit and re-enter your shell or run:[/]\n\n   `source {script_path}`\n"
+        f"\n[bright_yellow]IMPORTANT!!!! Please exit and re-enter your shell or run:[/]"
+        f"\n\n   `source {script_path}`\n"
     )
     return True
 
@@ -1000,14 +1005,15 @@ def setup_autocomplete(verbose: bool, dry_run: bool, force_setup: bool):
         "install 'click' package in your default python installation destination.[/]\n"
     )
     if click.confirm("Should we proceed ?"):
+        run_command(['pip', 'install', '--upgrade', 'click'], verbose=True, dry_run=dry_run, check=False)
         if detected_shell == 'bash':
             script_path = str(Path('~').expanduser() / '.bash_completion')
             command_to_execute = f"source {autocomplete_path}"
-            updated = write_to_shell(command_to_execute, dry_run, script_path, force_setup)
+            write_to_shell(command_to_execute, dry_run, script_path, force_setup)
         elif detected_shell == 'zsh':
             script_path = str(Path('~').expanduser() / '.zshrc')
             command_to_execute = f"source {autocomplete_path}"
-            updated = write_to_shell(command_to_execute, dry_run, script_path, force_setup)
+            write_to_shell(command_to_execute, dry_run, script_path, force_setup)
         elif detected_shell == 'fish':
             # Include steps for fish shell
             script_path = str(Path('~').expanduser() / f'.config/fish/completions/{NAME}.fish')
@@ -1020,7 +1026,6 @@ def setup_autocomplete(verbose: bool, dry_run: bool, force_setup: bool):
                 with open(autocomplete_path) as source_file, open(script_path, 'w') as destination_file:
                     for line in source_file:
                         destination_file.write(line)
-                updated = True
         else:
             # Include steps for powershell
             subprocess.check_call(['powershell', 'Set-ExecutionPolicy Unrestricted -Scope CurrentUser'])
@@ -1029,8 +1034,6 @@ def setup_autocomplete(verbose: bool, dry_run: bool, force_setup: bool):
             )
             command_to_execute = f". {autocomplete_path}"
             write_to_shell(command_to_execute, dry_run, script_path, force_setup)
-        if updated:
-            run_command(['pip', 'install', '--upgrade', 'click'], verbose=True, dry_run=dry_run, check=False)
     else:
         console.print(
             "\nPlease follow the https://click.palletsprojects.com/en/8.1.x/shell-completion/ "