Bowrna commented on a change in pull request #21145:
URL: https://github.com/apache/airflow/pull/21145#discussion_r812722254
##########
File path: dev/breeze/src/airflow_breeze/utils/run_utils.py
##########
@@ -73,3 +97,110 @@ def check_package_installed(package_name: str) -> bool:
Please install using https://pre-commit.com/#install to
continue[/]\n"
)
return is_installed
+
+
+def get_filesystem_type(filepath):
+ root_type = "unknown"
+ for part in psutil.disk_partitions():
+ if part.mountpoint == '/':
+ root_type = part.fstype
+ continue
+ if filepath.startswith(part.mountpoint):
+ return part.fstype
+
+ return root_type
+
+
+def calculate_md5_checksum_for_files(md5sum_cache_dir: Path):
+ not_modified_files = []
+ modified_files = []
+ for calculate_md5_file in FILES_FOR_REBUILD_CHECK:
+ file_to_get_md5 = Path(AIRFLOW_SOURCE, calculate_md5_file)
+ md5_checksum = generate_md5(file_to_get_md5)
+ sub_dir_name = file_to_get_md5.parts[-2]
+ actual_file_name = file_to_get_md5.parts[-1]
+ cache_file_name = Path(md5sum_cache_dir, sub_dir_name + '-' +
actual_file_name + '.md5sum')
+ file_content = md5_checksum + ' ' + str(file_to_get_md5) + '\n'
+ is_modified = update_md5checksum_in_cache(file_content,
cache_file_name)
+ if is_modified:
+ modified_files.append(calculate_md5_file)
+ else:
+ not_modified_files.append(calculate_md5_file)
+ return modified_files, not_modified_files
+
+
+def md5sum_check_if_build_is_needed(md5sum_cache_dir: Path, the_image_type:
str) -> bool:
+ build_needed = False
+ modified_files, not_modified_files =
calculate_md5_checksum_for_files(md5sum_cache_dir)
+ if len(modified_files) > 0:
+ console.print('The following files are modified: ', modified_files)
+ console.print(f'Likely {the_image_type} image needs rebuild')
+ build_needed = True
+ else:
+ console.print(
+ f'Docker image build is not needed for {the_image_type} build as
no important files are changed!'
+ )
+ return build_needed
+
+
+def instruct_build_image(the_image_type: str, python_version: str):
+ console.print(f'The {the_image_type} image for python version
{python_version} may be outdated')
+ console.print('Please run this command at earliest convenience:')
+ if the_image_type == 'CI':
+ console.print(f'./Breeze2 build-ci-image --python {python_version}')
+ else:
+ console.print(f'./Breeze2 build-prod-image --python {python_version}')
+ console.print("If you run it via pre-commit as individual hook, you can
run 'pre-commit run build'.")
+
+
+def instruct_for_setup():
+ CMDNAME = 'Breeze2'
+ console.print(f"You can setup autocomplete by running {CMDNAME}
setup-autocomplete'")
+ console.print(" You can toggle ascii/cheatsheet by running:")
+ console.print(f" * {CMDNAME} toggle-suppress-cheatsheet")
+ console.print(f" * {CMDNAME} toggle-suppress-asciiart")
+
+
[email protected]
+def working_directory(source_path: Path):
+ # Equivalent of pushd and popd in bash script.
+ # https://stackoverflow.com/a/42441759/3101838
+ prev_cwd = Path.cwd()
+ os.chdir(source_path)
+ try:
+ yield
+ finally:
+ os.chdir(prev_cwd)
+
+
+def change_file_permission(file_to_fix: Path):
Review comment:
@potiuk Could you tell me if i can use mock to test the
`change_file_permission` part too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]