Skip to content

Commit

Permalink
[Runtime Environment] Parse special characters in private Git URIs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shrekris-anyscale authored and matthewdeng committed Sep 15, 2022
1 parent 9bfc2e9 commit 943175a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
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 @@ -156,8 +156,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 @@ -209,9 +209,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:[email protected]/repo/archive/commit_hash.zip",
"https_username_PAT_github_com_repo_archive_commit_hash.zip",
),
(
(
"https://un:[email protected]/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

0 comments on commit 943175a

Please sign in to comment.