Skip to content

Commit

Permalink
Dedent help string in breeze configuration
Browse files Browse the repository at this point in the history
In Python 3.13 compiler, docstrings are automatically dedented. And
while Python 3.13 is not yet officially supported by Airflow for
some strange (and unknown) reasons, when you install breeze with
uv tools that have Python 3.13 installed, it might get into
a state that the docstrings are dedented in Breeze's bytecode and
it causes hash calculation for configuration options that have
docstring-generated help differs on different installations.

In order to make it consistent - we are now always dedenting the
help strings before hash calculation.

See python/cpython#81283
  • Loading branch information
potiuk committed Oct 31, 2024
1 parent 80f5c6f commit 3953395
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_build-docs.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
03dd58933b63fc368157f716b1852e1b
b349182dab04b6ff58acd122a403a5a4
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_prod-image.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55030fe0d7718eb668fa1a37128647b0
d91bcc76b14f186e749efe2c6aaa8682
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_prod-image_build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d0214e8e95fcb56c91e0e416690eb24f
fe048412f9fc1527a30eaaf0a986fa16
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_setup.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d4a4f1b405f912fa234ff4116068290a
08c78d9dddd037a2ade6b751c5a22ff9
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_setup_autocomplete.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fffcd49e102e09ccd69b3841a9e3ea8e
ec3b4541a478afe5cb86a6f1c48f50f5
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_setup_config.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ee2e731f011b1d93dcbfbcaebf6482a6
235af93483ea83592052476479757683
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_start-airflow.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
02160e5d799a77830ac522c628e90aed
d5d7f9a299c80596dbba0a50f2f32f1c
26 changes: 25 additions & 1 deletion dev/breeze/src/airflow_breeze/commands/setup_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import shutil
import subprocess
import sys
import textwrap
from copy import copy
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -255,8 +256,31 @@ def get_status(file: str):
get_console().print()


def dict_hash(dictionary: dict[str, Any]) -> str:
def dedent_help(dictionary: dict[str, Any]) -> None:
"""
Dedent help stored in the dictionary.
Python 3.13 automatically dedents docstrings retrieved from functions.
See https://github.com/python/cpython/issues/81283
However, click uses docstrings in the absence of help strings, and we are using click
command definition dictionary hash to detect changes in the command definitions, so if the
help strings are not dedented, the hash will change.
That's why we must de-dent all the help strings in the command definition dictionary
before we hash it.
"""
for key, value in dictionary.items():
if isinstance(value, dict):
dedent_help(value)
elif key == "help" and isinstance(value, str):
dictionary[key] = textwrap.dedent(value)


def dict_hash(dictionary: dict[str, Any], dedent_help_strings: bool = True) -> str:
"""MD5 hash of a dictionary. Sorted and dumped via json to account for random sequence)"""
if dedent_help_strings:
dedent_help(dictionary)
# noinspection InsecureHash
dhash = hashlib.md5()
try:
Expand Down

0 comments on commit 3953395

Please sign in to comment.