Skip to content

Commit

Permalink
[core] Fix builtin type and function shadowing (ray-project#48483)
Browse files Browse the repository at this point in the history
Signed-off-by: hjiang <[email protected]>
  • Loading branch information
dentiny authored Nov 1, 2024
1 parent e815d59 commit d0af862
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions python/ray/_private/runtime_env/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

def _get_pip_hash(pip_dict: Dict) -> str:
serialized_pip_spec = json.dumps(pip_dict, sort_keys=True)
hash = hashlib.sha1(serialized_pip_spec.encode("utf-8")).hexdigest()
return hash
hash_val = hashlib.sha1(serialized_pip_spec.encode("utf-8")).hexdigest()
return hash_val


def get_uri(runtime_env: Dict) -> Optional[str]:
Expand Down Expand Up @@ -435,14 +435,14 @@ def __init__(self, resources_dir: str):
self._created_hash_bytes: Dict[str, int] = {}
try_to_create_directory(self._pip_resources_dir)

def _get_path_from_hash(self, hash: str) -> str:
def _get_path_from_hash(self, hash_val: str) -> str:
"""Generate a path from the hash of a pip spec.
Example output:
/tmp/ray/session_2021-11-03_16-33-59_356303_41018/runtime_resources
/pip/ray-9a7972c3a75f55e976e620484f58410c920db091
"""
return os.path.join(self._pip_resources_dir, hash)
return os.path.join(self._pip_resources_dir, hash_val)

def get_uris(self, runtime_env: "RuntimeEnv") -> List[str]: # noqa: F821
"""Return the pip URI from the RuntimeEnv if it exists, else return []."""
Expand All @@ -456,21 +456,21 @@ def delete_uri(
) -> int:
"""Delete URI and return the number of bytes deleted."""
logger.info("Got request to delete pip URI %s", uri)
protocol, hash = parse_uri(uri)
protocol, hash_val = parse_uri(uri)
if protocol != Protocol.PIP:
raise ValueError(
"PipPlugin can only delete URIs with protocol "
f"pip. Received protocol {protocol}, URI {uri}"
)

# Cancel running create task.
task = self._creating_task.pop(hash, None)
task = self._creating_task.pop(hash_val, None)
if task is not None:
task.cancel()

del self._created_hash_bytes[hash]
del self._created_hash_bytes[hash_val]

pip_env_path = self._get_path_from_hash(hash)
pip_env_path = self._get_path_from_hash(hash_val)
local_dir_size = get_directory_size_bytes(pip_env_path)
del self._create_locks[uri]
try:
Expand All @@ -491,8 +491,8 @@ async def create(
if not runtime_env.has_pip():
return 0

protocol, hash = parse_uri(uri)
target_dir = self._get_path_from_hash(hash)
protocol, hash_val = parse_uri(uri)
target_dir = self._get_path_from_hash(hash_val)

async def _create_for_hash():
await PipProcessor(
Expand All @@ -511,13 +511,13 @@ async def _create_for_hash():
self._create_locks[uri] = asyncio.Lock()

async with self._create_locks[uri]:
if hash in self._created_hash_bytes:
return self._created_hash_bytes[hash]
self._creating_task[hash] = task = create_task(_create_for_hash())
task.add_done_callback(lambda _: self._creating_task.pop(hash, None))
bytes = await task
self._created_hash_bytes[hash] = bytes
return bytes
if hash_val in self._created_hash_bytes:
return self._created_hash_bytes[hash_val]
self._creating_task[hash_val] = task = create_task(_create_for_hash())
task.add_done_callback(lambda _: self._creating_task.pop(hash_val, None))
pip_dir_bytes = await task
self._created_hash_bytes[hash_val] = pip_dir_bytes
return pip_dir_bytes

def modify_context(
self,
Expand All @@ -531,8 +531,8 @@ def modify_context(
# PipPlugin only uses a single URI.
uri = uris[0]
# Update py_executable.
protocol, hash = parse_uri(uri)
target_dir = self._get_path_from_hash(hash)
protocol, hash_val = parse_uri(uri)
target_dir = self._get_path_from_hash(hash_val)
virtualenv_python = _PathHelper.get_virtualenv_python(target_dir)

if not os.path.exists(virtualenv_python):
Expand Down
Empty file.

0 comments on commit d0af862

Please sign in to comment.