Windows bugfix: path-to-URL conversion (#37827)
When interpreting local paths as relative URL endpoints, they were formatted as Windows paths on Windows (i.e. with '\'). URLs should always be POSIX-style.
This commit is contained in:
		| @@ -4,7 +4,6 @@ | |||||||
| # SPDX-License-Identifier: (Apache-2.0 OR MIT) | # SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||
| import collections | import collections | ||||||
| import os | import os | ||||||
| import sys |  | ||||||
| 
 | 
 | ||||||
| import pytest | import pytest | ||||||
| 
 | 
 | ||||||
| @@ -34,7 +33,6 @@ def _create_url(relative_url): | |||||||
| root_with_fragment = _create_url("index_with_fragment.html") | root_with_fragment = _create_url("index_with_fragment.html") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| @pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||||
|     "depth,expected_found,expected_not_found,expected_text", |     "depth,expected_found,expected_not_found,expected_text", | ||||||
|     [ |     [ | ||||||
| @@ -99,20 +97,17 @@ def test_spider_no_response(monkeypatch): | |||||||
|     assert not pages and not links |     assert not pages and not links | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_find_versions_of_archive_0(): | def test_find_versions_of_archive_0(): | ||||||
|     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=0) |     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=0) | ||||||
|     assert Version("0.0.0") in versions |     assert Version("0.0.0") in versions | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_find_versions_of_archive_1(): | def test_find_versions_of_archive_1(): | ||||||
|     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=1) |     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=1) | ||||||
|     assert Version("0.0.0") in versions |     assert Version("0.0.0") in versions | ||||||
|     assert Version("1.0.0") in versions |     assert Version("1.0.0") in versions | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_find_versions_of_archive_2(): | def test_find_versions_of_archive_2(): | ||||||
|     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=2) |     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=2) | ||||||
|     assert Version("0.0.0") in versions |     assert Version("0.0.0") in versions | ||||||
| @@ -120,14 +115,12 @@ def test_find_versions_of_archive_2(): | |||||||
|     assert Version("2.0.0") in versions |     assert Version("2.0.0") in versions | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_find_exotic_versions_of_archive_2(): | def test_find_exotic_versions_of_archive_2(): | ||||||
|     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=2) |     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=2) | ||||||
|     # up for grabs to make this better. |     # up for grabs to make this better. | ||||||
|     assert Version("2.0.0b2") in versions |     assert Version("2.0.0b2") in versions | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_find_versions_of_archive_3(): | def test_find_versions_of_archive_3(): | ||||||
|     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=3) |     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=3) | ||||||
|     assert Version("0.0.0") in versions |     assert Version("0.0.0") in versions | ||||||
| @@ -137,7 +130,6 @@ def test_find_versions_of_archive_3(): | |||||||
|     assert Version("4.5") in versions |     assert Version("4.5") in versions | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_find_exotic_versions_of_archive_3(): | def test_find_exotic_versions_of_archive_3(): | ||||||
|     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=3) |     versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=3) | ||||||
|     assert Version("2.0.0b2") in versions |     assert Version("2.0.0b2") in versions | ||||||
| @@ -145,7 +137,6 @@ def test_find_exotic_versions_of_archive_3(): | |||||||
|     assert Version("4.5-rc5") in versions |     assert Version("4.5-rc5") in versions | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_find_versions_of_archive_with_fragment(): | def test_find_versions_of_archive_with_fragment(): | ||||||
|     versions = spack.util.web.find_versions_of_archive( |     versions = spack.util.web.find_versions_of_archive( | ||||||
|         root_tarball, root_with_fragment, list_depth=0 |         root_tarball, root_with_fragment, list_depth=0 | ||||||
| @@ -206,7 +197,6 @@ def test_etag_parser(): | |||||||
|     assert spack.util.web.parse_etag("abc def") is None |     assert spack.util.web.parse_etag("abc def") is None | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") |  | ||||||
| def test_list_url(tmpdir): | def test_list_url(tmpdir): | ||||||
|     testpath = str(tmpdir) |     testpath = str(tmpdir) | ||||||
|     testpath_url = url_util.path_to_file_url(testpath) |     testpath_url = url_util.path_to_file_url(testpath) | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ | |||||||
| import traceback | import traceback | ||||||
| import urllib.parse | import urllib.parse | ||||||
| from html.parser import HTMLParser | from html.parser import HTMLParser | ||||||
|  | from pathlib import Path, PurePosixPath | ||||||
| from urllib.error import URLError | from urllib.error import URLError | ||||||
| from urllib.request import HTTPSHandler, Request, build_opener | from urllib.request import HTTPSHandler, Request, build_opener | ||||||
| 
 | 
 | ||||||
| @@ -498,7 +499,8 @@ def list_url(url, recursive=False): | |||||||
| 
 | 
 | ||||||
|     if local_path: |     if local_path: | ||||||
|         if recursive: |         if recursive: | ||||||
|             return list(_iter_local_prefix(local_path)) |             # convert backslash to forward slash as required for URLs | ||||||
|  |             return [str(PurePosixPath(Path(p))) for p in list(_iter_local_prefix(local_path))] | ||||||
|         return [ |         return [ | ||||||
|             subpath |             subpath | ||||||
|             for subpath in os.listdir(local_path) |             for subpath in os.listdir(local_path) | ||||||
| @@ -738,7 +740,8 @@ def find_versions_of_archive( | |||||||
| 
 | 
 | ||||||
|         # We'll be a bit more liberal and just look for the archive |         # We'll be a bit more liberal and just look for the archive | ||||||
|         # part, not the full path. |         # part, not the full path. | ||||||
|         url_regex = os.path.basename(url_regex) |         # this is a URL so it is a posixpath even on Windows | ||||||
|  |         url_regex = PurePosixPath(url_regex).name | ||||||
| 
 | 
 | ||||||
|         # We need to add a / to the beginning of the regex to prevent |         # We need to add a / to the beginning of the regex to prevent | ||||||
|         # Spack from picking up similarly named packages like: |         # Spack from picking up similarly named packages like: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Dan Lipsa
					Dan Lipsa