This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch v2-3-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 881ac77082e42a40018295250ab3065dd28d2f85 Author: Jarek Potiuk <[email protected]> AuthorDate: Sun Aug 7 09:05:10 2022 +0200 Better behaviour for self-update of Breeze (#25572) Breeze self-upgrade behaved somewhat erratically: 1) when executed manually as `self-upgrade` it printed "repaat the command" - which made no sense 2) whe triggered as part of an environment check (i.e. when breeze version was different or installed from another workspaece) it upgraded - and also printed "repeat the command" - which made more sense but added a need to repeat the command. 3) It asked the user to make the decision - but since reinstallation is not very intrusive (just few seonds delay) it makes little sense as reinstalling breeze would usually take less time than making decision This change fixes it for both cases: 1) there is no "repat the command" when you run self-upgrade command 2) when self-upgrade is triggered as part of another command, the original command is automatically re-run (with execvl - so replacing previous process) after the self-upgrde completed. 3) reinstalling breeze happens automatically in both cases without asking the user. (cherry picked from commit 3dfa44566c948cb2db016e89f84d6fe37bd6d824) --- .../src/airflow_breeze/commands/setup_commands.py | 15 +---- dev/breeze/src/airflow_breeze/utils/path_utils.py | 20 ++---- dev/breeze/src/airflow_breeze/utils/reinstall.py | 45 ++----------- images/breeze/output-commands-hash.txt | 2 +- images/breeze/output_setup_self-upgrade.svg | 74 ++++++++++------------ 5 files changed, 52 insertions(+), 104 deletions(-) diff --git a/dev/breeze/src/airflow_breeze/commands/setup_commands.py b/dev/breeze/src/airflow_breeze/commands/setup_commands.py index f9d6d488db..e9deb331b1 100644 --- a/dev/breeze/src/airflow_breeze/commands/setup_commands.py +++ b/dev/breeze/src/airflow_breeze/commands/setup_commands.py @@ -52,7 +52,7 @@ from airflow_breeze.utils.path_utils import ( get_used_sources_setup_metadata_hash, ) from airflow_breeze.utils.recording import output_file_for_recording -from airflow_breeze.utils.reinstall import ask_to_reinstall_breeze, reinstall_breeze, warn_non_editable +from airflow_breeze.utils.reinstall import reinstall_breeze, warn_non_editable from airflow_breeze.utils.run_utils import assert_pre_commit_installed, run_command from airflow_breeze.utils.visuals import ASCIIART, ASCIIART_STYLE @@ -62,12 +62,6 @@ def setup(): pass [email protected]( - '-f', - '--force', - is_flag=True, - help='Force upgrade without asking question to the user.', -) @click.option( '-a', '--use-current-airflow-sources', @@ -82,17 +76,14 @@ def setup(): if not output_file_for_recording else "Self upgrade Breeze.", ) -def self_upgrade(force: bool, use_current_airflow_sources: bool): +def self_upgrade(use_current_airflow_sources: bool): if use_current_airflow_sources: airflow_sources: Optional[Path] = get_used_airflow_sources() else: airflow_sources = get_installation_airflow_sources() if airflow_sources is not None: breeze_sources = airflow_sources / "dev" / "breeze" - if force: - reinstall_breeze(breeze_sources) - else: - ask_to_reinstall_breeze(breeze_sources, timeout=None) + reinstall_breeze(breeze_sources, re_run=False) else: warn_non_editable() sys.exit(1) diff --git a/dev/breeze/src/airflow_breeze/utils/path_utils.py b/dev/breeze/src/airflow_breeze/utils/path_utils.py index 55aa5fd2e1..a3961473ad 100644 --- a/dev/breeze/src/airflow_breeze/utils/path_utils.py +++ b/dev/breeze/src/airflow_breeze/utils/path_utils.py @@ -29,12 +29,7 @@ from typing import Optional from airflow_breeze import NAME from airflow_breeze.utils.confirm import set_forced_answer from airflow_breeze.utils.console import get_console -from airflow_breeze.utils.reinstall import ( - ask_to_reinstall_breeze, - warn_dependencies_changed, - warn_different_location, - warn_non_editable, -) +from airflow_breeze.utils.reinstall import reinstall_breeze, warn_dependencies_changed, warn_non_editable AIRFLOW_CFG_FILE = "setup.cfg" @@ -132,7 +127,7 @@ def set_forced_answer_for_upgrade_check(): set_forced_answer("quit") -def print_warning_if_setup_changed() -> bool: +def reinstall_if_setup_changed() -> bool: """ Prints warning if detected airflow sources are not the ones that Breeze was installed with. :return: True if warning was printed. @@ -149,13 +144,13 @@ def print_warning_if_setup_changed() -> bool: breeze_sources = installation_sources / "dev" / "breeze" warn_dependencies_changed() set_forced_answer_for_upgrade_check() - ask_to_reinstall_breeze(breeze_sources) + reinstall_breeze(breeze_sources) set_forced_answer(None) return True return False -def print_warning_if_different_sources(airflow_sources: Path) -> bool: +def reinstall_if_different_sources(airflow_sources: Path) -> bool: """ Prints warning if detected airflow sources are not the ones that Breeze was installed with. :param airflow_sources: source for airflow code that we are operating on @@ -163,8 +158,7 @@ def print_warning_if_different_sources(airflow_sources: Path) -> bool: """ installation_airflow_sources = get_installation_airflow_sources() if installation_airflow_sources and airflow_sources != installation_airflow_sources: - warn_different_location(installation_airflow_sources, airflow_sources) - ask_to_reinstall_breeze(airflow_sources / "dev" / "breeze") + reinstall_breeze(airflow_sources / "dev" / "breeze") return True return False @@ -230,8 +224,8 @@ def find_airflow_sources_root_to_operate_on() -> Path: airflow_sources = get_used_airflow_sources() if not skip_upgrade_check(): # only print warning and sleep if not producing complete results - print_warning_if_different_sources(airflow_sources) - print_warning_if_setup_changed() + reinstall_if_different_sources(airflow_sources) + reinstall_if_setup_changed() os.chdir(str(airflow_sources)) return airflow_sources diff --git a/dev/breeze/src/airflow_breeze/utils/reinstall.py b/dev/breeze/src/airflow_breeze/utils/reinstall.py index e58ac2c731..577a5f3ea3 100644 --- a/dev/breeze/src/airflow_breeze/utils/reinstall.py +++ b/dev/breeze/src/airflow_breeze/utils/reinstall.py @@ -15,52 +15,32 @@ # specific language governing permissions and limitations # under the License. +import os import subprocess import sys from pathlib import Path -from typing import Optional from airflow_breeze import NAME -from airflow_breeze.utils.confirm import STANDARD_TIMEOUT, Answer, user_confirm from airflow_breeze.utils.console import get_console -def reinstall_breeze(breeze_sources: Path): +def reinstall_breeze(breeze_sources: Path, re_run: bool = True): """ Reinstalls Breeze from specified sources. :param breeze_sources: Sources where to install Breeze from. + :param re_run: whether to re-run the original command that breeze was run with. """ # Note that we cannot use `pipx upgrade` here because we sometimes install # Breeze from different sources than originally installed (i.e. when we reinstall airflow # From the current directory. get_console().print(f"\n[info]Reinstalling Breeze from {breeze_sources}\n") subprocess.check_call(["pipx", "install", "-e", str(breeze_sources), "--force"]) - get_console().print( - f"\n[info]Breeze has been reinstalled from {breeze_sources}. Exiting now.[/]\n\n" - f"[warning]Please run your command again[/]\n" - ) + if re_run: + os.execl(sys.executable, 'breeze', *sys.argv) + get_console().print(f"\n[info]Breeze has been reinstalled from {breeze_sources}. Exiting now.[/]\n\n") sys.exit(0) -def ask_to_reinstall_breeze(breeze_sources: Path, timeout: Optional[int] = STANDARD_TIMEOUT): - """ - Ask the user to reinstall Breeze (and do so if confirmed). - :param breeze_sources: breeze sources to reinstall Breeze from. - :param timeout to answer - if set (when upgrade is auxiliary) then default answer is no, - otherwise it is yes - """ - answer = user_confirm( - f"Do you want to reinstall Breeze from {breeze_sources.parent.parent} " - "(This should usually take couple of seconds)?", - default_answer=Answer.NO if timeout else Answer.YES, - timeout=timeout, - ) - if answer == Answer.YES: - reinstall_breeze(breeze_sources) - elif answer == Answer.QUIT: - sys.exit(1) - - def warn_non_editable(): get_console().print( "\n[error]Breeze is installed in a wrong way.[/]\n" @@ -70,19 +50,6 @@ def warn_non_editable(): ) -def warn_different_location(installation_airflow_sources: Path, current_airflow_sources: Path): - get_console().print( - f"\n[warning]Breeze was installed from " - f"different location![/]\n\n" - f"Breeze installed from : {installation_airflow_sources}\n" - f"Current Airflow sources : {current_airflow_sources}\n\n" - f"[warning]This might cause various problems!![/]\n\n" - f"If you experience problems - reinstall Breeze with:\n\n" - f" {NAME} self-upgrade --force --use-current-airflow-sources\n" - f"\nThis should usually take couple of seconds.\n" - ) - - def warn_dependencies_changed(): get_console().print( f"\n[warning]Breeze dependencies changed since the installation![/]\n\n" diff --git a/images/breeze/output-commands-hash.txt b/images/breeze/output-commands-hash.txt index 345579f7b4..68adcd4398 100644 --- a/images/breeze/output-commands-hash.txt +++ b/images/breeze/output-commands-hash.txt @@ -44,7 +44,7 @@ release-management:name:23bcbf95c4ca34de89a367669f7274c1 release-management:params:bc6b726d05240c22ac8522edc4a200ee release-management:short_help:37a6259cc0c1dae299a7866489dff0bd setup:chain:68934a3e9455fa72420237eb05902327 -setup:commands:c95a46d890baef83220804e613c55542 +setup:commands:33563f641086f804640e5e278f374b87 setup:deprecated:68934a3e9455fa72420237eb05902327 setup:epilog:37a6259cc0c1dae299a7866489dff0bd setup:help:53e8d17d2f9a677f11cc08495a7a5012 diff --git a/images/breeze/output_setup_self-upgrade.svg b/images/breeze/output_setup_self-upgrade.svg index 810a3fc41c..5a188b25a4 100644 --- a/images/breeze/output_setup_self-upgrade.svg +++ b/images/breeze/output_setup_self-upgrade.svg @@ -1,4 +1,4 @@ -<svg class="rich-terminal" viewBox="0 0 1482 342.79999999999995" xmlns="http://www.w3.org/2000/svg"> +<svg class="rich-terminal" viewBox="0 0 1482 318.4" xmlns="http://www.w3.org/2000/svg"> <!-- Generated with Rich https://www.textualize.io --> <style> @@ -19,88 +19,84 @@ font-weight: 700; } - .terminal-148126700-matrix { + .terminal-2544310981-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-148126700-title { + .terminal-2544310981-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-148126700-r1 { fill: #c5c8c6;font-weight: bold } -.terminal-148126700-r2 { fill: #c5c8c6 } -.terminal-148126700-r3 { fill: #d0b344;font-weight: bold } -.terminal-148126700-r4 { fill: #868887 } -.terminal-148126700-r5 { fill: #68a0b3;font-weight: bold } -.terminal-148126700-r6 { fill: #98a84b;font-weight: bold } + .terminal-2544310981-r1 { fill: #c5c8c6;font-weight: bold } +.terminal-2544310981-r2 { fill: #c5c8c6 } +.terminal-2544310981-r3 { fill: #d0b344;font-weight: bold } +.terminal-2544310981-r4 { fill: #868887 } +.terminal-2544310981-r5 { fill: #68a0b3;font-weight: bold } +.terminal-2544310981-r6 { fill: #98a84b;font-weight: bold } </style> <defs> - <clipPath id="terminal-148126700-clip-terminal"> - <rect x="0" y="0" width="1463.0" height="291.79999999999995" /> + <clipPath id="terminal-2544310981-clip-terminal"> + <rect x="0" y="0" width="1463.0" height="267.4" /> </clipPath> - <clipPath id="terminal-148126700-line-0"> + <clipPath id="terminal-2544310981-line-0"> <rect x="0" y="1.5" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-1"> +<clipPath id="terminal-2544310981-line-1"> <rect x="0" y="25.9" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-2"> +<clipPath id="terminal-2544310981-line-2"> <rect x="0" y="50.3" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-3"> +<clipPath id="terminal-2544310981-line-3"> <rect x="0" y="74.7" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-4"> +<clipPath id="terminal-2544310981-line-4"> <rect x="0" y="99.1" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-5"> +<clipPath id="terminal-2544310981-line-5"> <rect x="0" y="123.5" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-6"> +<clipPath id="terminal-2544310981-line-6"> <rect x="0" y="147.9" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-7"> +<clipPath id="terminal-2544310981-line-7"> <rect x="0" y="172.3" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-8"> +<clipPath id="terminal-2544310981-line-8"> <rect x="0" y="196.7" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-9"> +<clipPath id="terminal-2544310981-line-9"> <rect x="0" y="221.1" width="1464" height="24.65"/> </clipPath> -<clipPath id="terminal-148126700-line-10"> - <rect x="0" y="245.5" width="1464" height="24.65"/> - </clipPath> </defs> - <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1480" height="340.8" rx="8"/><text class="terminal-148126700-title" fill="#c5c8c6" text-anchor="middle" x="740" y="27">Command: setup self-upgrade</text> + <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1480" height="316.4" rx="8"/><text class="terminal-2544310981-title" fill="#c5c8c6" text-anchor="middle" x="740" y="27">Command: setup self-upgrade</text> <g transform="translate(26,22)"> <circle cx="0" cy="0" r="7" fill="#ff5f57"/> <circle cx="22" cy="0" r="7" fill="#febc2e"/> <circle cx="44" cy="0" r="7" fill="#28c840"/> </g> - <g transform="translate(9, 41)" clip-path="url(#terminal-148126700-clip-terminal)"> + <g transform="translate(9, 41)" clip-path="url(#terminal-2544310981-clip-terminal)"> - <g class="terminal-148126700-matrix"> - <text class="terminal-148126700-r2" x="1464" y="20" textLength="12.2" clip-path="url(#terminal-148126700-line-0)"> -</text><text class="terminal-148126700-r3" x="12.2" y="44.4" textLength="85.4" clip-path="url(#terminal-148126700-line-1)">Usage: </text><text class="terminal-148126700-r1" x="97.6" y="44.4" textLength="427" clip-path="url(#terminal-148126700-line-1)">breeze setup self-upgrade [OPTIONS]</text><text class="terminal-148126700-r2" x="1464" y="44.4" textLength="12.2" clip-path="url(#terminal-148126700-line-1)"> -</text><text class="terminal-148126700-r2" x="1464" y="68.8" textLength="12.2" clip-path="url(#terminal-148126700-line-2)"> -</text><text class="terminal-148126700-r2" x="12.2" y="93.2" textLength="244" clip-path="url(#terminal-148126700-line-3)">Self upgrade Breeze.</text><text class="terminal-148126700-r2" x="1464" y="93.2" textLength="12.2" clip-path="url(#terminal-148126700-line-3)"> -</text><text class="terminal-148126700-r2" x="1464" y="117.6" textLength="12.2" clip-path="url(#terminal-148126700-line-4)"> -</text><text class="terminal-148126700-r4" x="0" y="142" textLength="24.4" clip-path="url(#terminal-148126700-line-5)">╭─</text><text class="terminal-148126700-r4" x="24.4" y="142" textLength="1415.2" clip-path="url(#terminal-148126700-line-5)"> Self-upgrade flags ────────────────────────────────────────────────────────────────────────────────────────────────</text><text class="terminal-148126700-r4" x="1439.6" y="142" textLength="24.4" clip-path="url(#terminal-148126700-l [...] -</text><text class="terminal-148126700-r4" x="0" y="166.4" textLength="12.2" clip-path="url(#terminal-148126700-line-6)">│</text><text class="terminal-148126700-r5" x="24.4" y="166.4" textLength="12.2" clip-path="url(#terminal-148126700-line-6)">-</text><text class="terminal-148126700-r5" x="36.6" y="166.4" textLength="48.8" clip-path="url(#terminal-148126700-line-6)">-use</text><text class="terminal-148126700-r5" x="85.4" y="166.4" textLength="292.8" clip-path="url(#terminal-148126700-l [...] -</text><text class="terminal-148126700-r4" x="0" y="190.8" textLength="12.2" clip-path="url(#terminal-148126700-line-7)">│</text><text class="terminal-148126700-r5" x="24.4" y="190.8" textLength="12.2" clip-path="url(#terminal-148126700-line-7)">-</text><text class="terminal-148126700-r5" x="36.6" y="190.8" textLength="73.2" clip-path="url(#terminal-148126700-line-7)">-force</text><text class="terminal-148126700-r6" x="402.6" y="190.8" textLength="24.4" clip-path="url(#terminal-148126700 [...] -</text><text class="terminal-148126700-r4" x="0" y="215.2" textLength="1464" clip-path="url(#terminal-148126700-line-8)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-148126700-r2" x="1464" y="215.2" textLength="12.2" clip-path="url(#terminal-148126700-line-8)"> -</text><text class="terminal-148126700-r4" x="0" y="239.6" textLength="24.4" clip-path="url(#terminal-148126700-line-9)">╭─</text><text class="terminal-148126700-r4" x="24.4" y="239.6" textLength="1415.2" clip-path="url(#terminal-148126700-line-9)"> Common options ────────────────────────────────────────────────────────────────────────────────────────────────────</text><text class="terminal-148126700-r4" x="1439.6" y="239.6" textLength="24.4" clip-path="url(#terminal-14812 [...] -</text><text class="terminal-148126700-r4" x="0" y="264" textLength="12.2" clip-path="url(#terminal-148126700-line-10)">│</text><text class="terminal-148126700-r5" x="24.4" y="264" textLength="12.2" clip-path="url(#terminal-148126700-line-10)">-</text><text class="terminal-148126700-r5" x="36.6" y="264" textLength="61" clip-path="url(#terminal-148126700-line-10)">-help</text><text class="terminal-148126700-r6" x="122" y="264" textLength="24.4" clip-path="url(#terminal-148126700-line-10)" [...] -</text><text class="terminal-148126700-r4" x="0" y="288.4" textLength="1464" clip-path="url(#terminal-148126700-line-11)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-148126700-r2" x="1464" y="288.4" textLength="12.2" clip-path="url(#terminal-148126700-line-11)"> + <g class="terminal-2544310981-matrix"> + <text class="terminal-2544310981-r2" x="1464" y="20" textLength="12.2" clip-path="url(#terminal-2544310981-line-0)"> +</text><text class="terminal-2544310981-r3" x="12.2" y="44.4" textLength="85.4" clip-path="url(#terminal-2544310981-line-1)">Usage: </text><text class="terminal-2544310981-r1" x="97.6" y="44.4" textLength="427" clip-path="url(#terminal-2544310981-line-1)">breeze setup self-upgrade [OPTIONS]</text><text class="terminal-2544310981-r2" x="1464" y="44.4" textLength="12.2" clip-path="url(#terminal-2544310981-line-1)"> +</text><text class="terminal-2544310981-r2" x="1464" y="68.8" textLength="12.2" clip-path="url(#terminal-2544310981-line-2)"> +</text><text class="terminal-2544310981-r2" x="12.2" y="93.2" textLength="244" clip-path="url(#terminal-2544310981-line-3)">Self upgrade Breeze.</text><text class="terminal-2544310981-r2" x="1464" y="93.2" textLength="12.2" clip-path="url(#terminal-2544310981-line-3)"> +</text><text class="terminal-2544310981-r2" x="1464" y="117.6" textLength="12.2" clip-path="url(#terminal-2544310981-line-4)"> +</text><text class="terminal-2544310981-r4" x="0" y="142" textLength="24.4" clip-path="url(#terminal-2544310981-line-5)">╭─</text><text class="terminal-2544310981-r4" x="24.4" y="142" textLength="1415.2" clip-path="url(#terminal-2544310981-line-5)"> Self-upgrade flags ────────────────────────────────────────────────────────────────────────────────────────────────</text><text class="terminal-2544310981-r4" x="1439.6" y="142" textLength="24.4" clip-path="url(#terminal-254431 [...] +</text><text class="terminal-2544310981-r4" x="0" y="166.4" textLength="12.2" clip-path="url(#terminal-2544310981-line-6)">│</text><text class="terminal-2544310981-r5" x="24.4" y="166.4" textLength="12.2" clip-path="url(#terminal-2544310981-line-6)">-</text><text class="terminal-2544310981-r5" x="36.6" y="166.4" textLength="48.8" clip-path="url(#terminal-2544310981-line-6)">-use</text><text class="terminal-2544310981-r5" x="85.4" y="166.4" textLength="292.8" clip-path="url(#terminal-2544 [...] +</text><text class="terminal-2544310981-r4" x="0" y="190.8" textLength="1464" clip-path="url(#terminal-2544310981-line-7)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-2544310981-r2" x="1464" y="190.8" textLength="12.2" clip-path="url(#terminal-2544310981-line-7)"> +</text><text class="terminal-2544310981-r4" x="0" y="215.2" textLength="24.4" clip-path="url(#terminal-2544310981-line-8)">╭─</text><text class="terminal-2544310981-r4" x="24.4" y="215.2" textLength="1415.2" clip-path="url(#terminal-2544310981-line-8)"> Common options ────────────────────────────────────────────────────────────────────────────────────────────────────</text><text class="terminal-2544310981-r4" x="1439.6" y="215.2" textLength="24.4" clip-path="url(#terminal- [...] +</text><text class="terminal-2544310981-r4" x="0" y="239.6" textLength="12.2" clip-path="url(#terminal-2544310981-line-9)">│</text><text class="terminal-2544310981-r5" x="24.4" y="239.6" textLength="12.2" clip-path="url(#terminal-2544310981-line-9)">-</text><text class="terminal-2544310981-r5" x="36.6" y="239.6" textLength="61" clip-path="url(#terminal-2544310981-line-9)">-help</text><text class="terminal-2544310981-r6" x="122" y="239.6" textLength="24.4" clip-path="url(#terminal-2544310 [...] +</text><text class="terminal-2544310981-r4" x="0" y="264" textLength="1464" clip-path="url(#terminal-2544310981-line-10)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-2544310981-r2" x="1464" y="264" textLength="12.2" clip-path="url(#terminal-2544310981-line-10)"> </text> </g> </g>
