Skip to content

Commit

Permalink
[Refactor] Address issue comment (rename variables)
Browse files Browse the repository at this point in the history
Closes: #23151
Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
  • Loading branch information
MortalHappiness committed Sep 25, 2024
1 parent 324cfe7 commit ea58122
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions python/ray/_private/runtime_env/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ def _dir_travel(
excludes.pop()


def _hash_single(
def _hash_file_content_or_directory_name(
filepath: Path,
relative_path: Path,
logger: Optional[logging.Logger] = default_logger,
) -> bytes:
"""Helper function to create hash of a single file or directory."""
"""Helper function to create hash of a single file or directory.
This function will hash the path of the file or directory,
and if it's a file, it'll hash its content too.
"""

BUF_SIZE = 4096 * 1024

Expand Down Expand Up @@ -171,8 +175,13 @@ def _hash_file(
relative_path: Path,
logger: Optional[logging.Logger] = default_logger,
) -> bytes:
"""Helper function to create hash of a single file."""
file_hash = _hash_single(filepath, relative_path, logger=logger)
"""Helper function to create hash of a single file.
It'll hash the path of the file and its content to create a hash value.
"""
file_hash = _hash_file_content_or_directory_name(
filepath, relative_path, logger=logger
)
return _xor_bytes(file_hash, b"0" * 8)


Expand All @@ -190,7 +199,9 @@ def _hash_directory(
hash_val = b"0" * 8

def handler(path: Path):
file_hash = _hash_single(path, relative_path, logger=logger)
file_hash = _hash_file_content_or_directory_name(
path, relative_path, logger=logger
)
nonlocal hash_val
hash_val = _xor_bytes(hash_val, file_hash)

Expand Down

0 comments on commit ea58122

Please sign in to comment.