Skip to content

Commit

Permalink
Windows bugfix: path-to-URL conversion (spack#37827)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danlipsa authored Jun 13, 2023
1 parent 746eaaf commit 4648939
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
10 changes: 0 additions & 10 deletions lib/spack/spack/test/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import collections
import os
import sys

import pytest

Expand Down Expand Up @@ -34,7 +33,6 @@ def _create_url(relative_url):
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",
[
Expand Down Expand Up @@ -99,35 +97,30 @@ 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
assert Version("1.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():
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
Expand All @@ -137,15 +130,13 @@ 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
assert Version("3.0a1") 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():
versions = spack.util.web.find_versions_of_archive(
root_tarball, root_with_fragment, list_depth=0
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions lib/spack/spack/util/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4648939

Please sign in to comment.