Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime Environment] Parse special characters in private Git URIs #28250

Merged
merged 2 commits into from
Sep 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions python/ray/_private/runtime_env/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def parse_uri(pkg_uri: str) -> Tuple[Protocol, str]:
netloc='_ray_pkg_029f88d5ecc55e1e4d64fc6e388fd103.zip'
)
-> ("gcs", "_ray_pkg_029f88d5ecc55e1e4d64fc6e388fd103.zip")
For HTTPS URIs, the netloc will have '.' replaced with '_', and
the path will have '/' replaced with '_'. The package name will be the
For HTTPS URIs, the netloc will have '.', ':', and '@' swapped with '_',
and the path will have '/' replaced with '_'. The package name will be the
adjusted path with 'https_' prepended.
urlparse(
"https://github.com/shrekris-anyscale/test_module/archive/HEAD.zip"
Expand Down Expand Up @@ -216,9 +216,10 @@ def parse_uri(pkg_uri: str) -> Tuple[Protocol, str]:
if protocol == Protocol.S3 or protocol == Protocol.GS:
return (protocol, f"{protocol.value}_{uri.netloc}{uri.path.replace('/', '_')}")
elif protocol == Protocol.HTTPS:
parsed_netloc = uri.netloc.replace(".", "_").replace(":", "_").replace("@", "_")
return (
protocol,
f"https_{uri.netloc.replace('.', '_')}{uri.path.replace('/', '_')}",
f"https_{parsed_netloc}{uri.path.replace('/', '_')}",
)
elif protocol == Protocol.FILE:
return (
Expand Down
60 changes: 43 additions & 17 deletions python/ray/tests/test_runtime_env_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,49 @@ def test_unzip_with_matching_subdirectory_names(
)


class TestParseUri:
@pytest.mark.parametrize(
"parsing_tuple",
[
("gcs://file.zip", Protocol.GCS, "file.zip"),
("s3://bucket/file.zip", Protocol.S3, "s3_bucket_file.zip"),
("https://test.com/file.zip", Protocol.HTTPS, "https_test_com_file.zip"),
("gs://bucket/file.zip", Protocol.GS, "gs_bucket_file.zip"),
],
)
def test_parsing_basic(self, parsing_tuple):
uri, protocol, package_name = parsing_tuple
parsed_protocol, parsed_package_name = parse_uri(uri)

assert protocol == parsed_protocol
assert package_name == parsed_package_name

@pytest.mark.parametrize(
"parsing_tuple",
[
(
"https://username:PAT@github.com/repo/archive/commit_hash.zip",
"https_username_PAT_github_com_repo_archive_commit_hash.zip",
),
(
(
"https://un:pwd@gitlab.com/user/repo/-/"
"archive/commit_hash/repo-commit_hash.zip"
),
(
"https_un_pwd_gitlab_com_user_repo_-_"
"archive_commit_hash_repo-commit_hash.zip"
),
),
],
)
def test_parse_private_git_https_uris(self, parsing_tuple):
raw_uri, parsed_uri = parsing_tuple
parsed_protocol, parsed_package_name = parse_uri(raw_uri)
assert parsed_protocol == Protocol.HTTPS
assert parsed_package_name == parsed_uri


@pytest.mark.skipif(sys.platform == "win32", reason="Fails on windows")
def test_travel(tmp_path):
dir_paths = set()
Expand Down Expand Up @@ -433,23 +476,6 @@ def handler(path):
assert dir_paths == visited_dir_paths


@pytest.mark.parametrize(
"parsing_tuple",
[
("gcs://file.zip", Protocol.GCS, "file.zip"),
("s3://bucket/file.zip", Protocol.S3, "s3_bucket_file.zip"),
("https://test.com/file.zip", Protocol.HTTPS, "https_test_com_file.zip"),
("gs://bucket/file.zip", Protocol.GS, "gs_bucket_file.zip"),
],
)
def test_parsing(parsing_tuple):
uri, protocol, package_name = parsing_tuple
parsed_protocol, parsed_package_name = parse_uri(uri)

assert protocol == parsed_protocol
assert package_name == parsed_package_name


def test_is_whl_uri():
assert is_whl_uri("gcs://my-package.whl")
assert not is_whl_uri("gcs://asdf.zip")
Expand Down