From 4648939043ae1b0cda67a69bdd2a098d3700a0fa Mon Sep 17 00:00:00 2001 From: Dan Lipsa Date: Tue, 13 Jun 2023 13:08:09 -0400 Subject: 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. --- lib/spack/spack/test/web.py | 10 ---------- lib/spack/spack/util/web.py | 7 +++++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/spack/spack/test/web.py b/lib/spack/spack/test/web.py index adebe23b97..9957cb52b4 100644 --- a/lib/spack/spack/test/web.py +++ b/lib/spack/spack/test/web.py @@ -4,7 +4,6 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) import collections import os -import sys import pytest @@ -34,7 +33,6 @@ page_4 = _create_url("4.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( "depth,expected_found,expected_not_found,expected_text", [ @@ -99,20 +97,17 @@ def test_spider_no_response(monkeypatch): 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(): versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=0) 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(): versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=1) assert Version("0.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(): versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=2) 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 -@pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") def test_find_exotic_versions_of_archive_2(): versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=2) # up for grabs to make this better. 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(): versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=3) assert Version("0.0.0") in versions @@ -137,7 +130,6 @@ def test_find_versions_of_archive_3(): 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(): versions = spack.util.web.find_versions_of_archive(root_tarball, root, list_depth=3) 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 -@pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") def test_find_versions_of_archive_with_fragment(): versions = spack.util.web.find_versions_of_archive( 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 -@pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)") def test_list_url(tmpdir): testpath = str(tmpdir) testpath_url = url_util.path_to_file_url(testpath) diff --git a/lib/spack/spack/util/web.py b/lib/spack/spack/util/web.py index 6101ffec3f..7e627b31dd 100644 --- a/lib/spack/spack/util/web.py +++ b/lib/spack/spack/util/web.py @@ -17,6 +17,7 @@ import sys import traceback import urllib.parse from html.parser import HTMLParser +from pathlib import Path, PurePosixPath from urllib.error import URLError from urllib.request import HTTPSHandler, Request, build_opener @@ -498,7 +499,8 @@ def list_url(url, recursive=False): if local_path: 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 [ subpath 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 # 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 # Spack from picking up similarly named packages like: -- cgit v1.2.3-60-g2f50