Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ci/ray_ci/automation/pypi_lib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import subprocess
import sys
from typing import List
from typing import Dict, List
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To support making add_env an optional argument in _call_subprocess as suggested in another comment, Optional should be imported from typing.

Suggested change
from typing import Dict, List
from typing import Dict, List, Optional


from ray_release.aws import get_secret_token

Expand Down Expand Up @@ -32,8 +32,10 @@ def _get_pypi_token(pypi_env: str) -> str:
return get_secret_token(AWS_SECRET_PYPI)


def _call_subprocess(command: List[str]):
subprocess.run(command, check=True)
def _call_subprocess(command: List[str], add_env: Dict[str, str]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The signature of _call_subprocess has been changed to require the add_env parameter. While this works for the current use case, it makes the function less reusable and breaks its previous contract. A more robust approach would be to make add_env an optional parameter. This would maintain backward compatibility and make the helper function more flexible for future use. You would also need to adjust the function body to handle the case where add_env is None.

Suggested change
def _call_subprocess(command: List[str], add_env: Dict[str, str]):
def _call_subprocess(command: List[str], add_env: Optional[Dict[str, str]] = None):

env = os.environ.copy()
env.update(add_env)
subprocess.run(command, env=env, check=True)


def upload_wheels_to_pypi(pypi_env: str, directory_path: str) -> None:
Expand All @@ -52,8 +54,6 @@ def upload_wheels_to_pypi(pypi_env: str, directory_path: str) -> None:
pypi_url,
"--username",
"__token__",
"--password",
pypi_token,
wheel_path,
]
_call_subprocess(cmd)
_call_subprocess(cmd, add_env={"TWINE_PASSWORD": pypi_token})
25 changes: 14 additions & 11 deletions ci/ray_ci/automation/test_pypi_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,20 @@ def test_upload_wheels_to_pypi(mock_subprocess, mock_get_pypi_url, mock_get_pypi
assert mock_subprocess.call_count == len(wheels)
for i, call_args in enumerate(mock_subprocess.call_args_list):
command = call_args[0][0]
assert command[0] == sys.executable
assert command[1] == "-m"
assert command[2] == "twine"
assert command[3] == "upload"
assert command[4] == "--repository-url"
assert command[5] == "test_pypi_url"
assert command[6] == "--username"
assert command[7] == "__token__"
assert command[8] == "--password"
assert command[9] == "test_token"
assert command[10] in wheel_paths
assert command[:-1] == [
sys.executable,
"-m",
"twine",
"upload",
"--repository-url",
"test_pypi_url",
"--username",
"__token__",
]
assert command[-1] in wheel_paths

add_env = call_args[1]["add_env"]
assert add_env["TWINE_PASSWORD"] == "test_token"


@mock.patch("ci.ray_ci.automation.pypi_lib._get_pypi_token")
Expand Down