Skip to content

Commit be3e6a0

Browse files
authored
document config option "url_fetch_method" (spack#24638)
- Change config from the undocumented `use_curl: true/false` to `url_fetch_method: urllib/curl`. - Documentation of `url_fetch_method` in `defaults/config.yaml` - Default fetch option explicitly set to `urllib` for users who may not have curl on their system To upgrade from `use_curl` to `url_fetch_method`, run `spack config update config`
1 parent cd8f7d8 commit be3e6a0

File tree

6 files changed

+58
-44
lines changed

6 files changed

+58
-44
lines changed

etc/spack/defaults/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ config:
134134
# enabling locks.
135135
locks: true
136136

137+
# The default url fetch method to use.
138+
# If set to 'curl', Spack will require curl on the user's system
139+
# If set to 'urllib', Spack will use python built-in libs to fetch
140+
url_fetch_method: urllib
137141

138142
# The maximum number of jobs to use for the build system (e.g. `make`), when
139143
# the -j flag is not given on the command line. Defaults to 16 when not set.

lib/spack/spack/fetch_strategy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def fetch(self):
338338
def _existing_url(self, url):
339339
tty.debug('Checking existence of {0}'.format(url))
340340

341-
if spack.config.get('config:use_curl'):
341+
if spack.config.get('config:url_fetch_method') == 'curl':
342342
curl = self.curl
343343
# Telling curl to fetch the first byte (-r 0-0) is supposed to be
344344
# portable.
@@ -357,7 +357,7 @@ def _existing_url(self, url):
357357
return (response.getcode() is None or response.getcode() == 200)
358358

359359
def _fetch_from_url(self, url):
360-
if spack.config.get('config:use_curl'):
360+
if spack.config.get('config:url_fetch_method') == 'curl':
361361
return self._fetch_curl(url)
362362
else:
363363
return self._fetch_urllib(url)

lib/spack/spack/schema/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
},
100100
'allow_sgid': {'type': 'boolean'},
101101
'binary_index_root': {'type': 'string'},
102+
'url_fetch_method': {
103+
'type': 'string',
104+
'enum': ['urllib', 'curl']
105+
},
102106
},
103107
},
104108
}
@@ -153,4 +157,10 @@ def update(data):
153157
update_data = spack.config.merge_yaml(update_data, projections_data)
154158
data['install_tree'] = update_data
155159
changed = True
160+
161+
use_curl = data.pop('use_curl', None)
162+
if use_curl is not None:
163+
data['url_fetch_method'] = 'curl' if use_curl else 'urllib'
164+
changed = True
165+
156166
return changed

lib/spack/spack/test/cache_fetch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@
1414
from spack.stage import Stage
1515

1616

17-
@pytest.mark.parametrize('use_curl', [True, False])
18-
def test_fetch_missing_cache(tmpdir, use_curl):
17+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
18+
def test_fetch_missing_cache(tmpdir, _fetch_method):
1919
"""Ensure raise a missing cache file."""
2020
testpath = str(tmpdir)
21-
with spack.config.override('config:use_curl', use_curl):
21+
with spack.config.override('config:url_fetch_method', _fetch_method):
2222
fetcher = CacheURLFetchStrategy(url='file:///not-a-real-cache-file')
2323
with Stage(fetcher, path=testpath):
2424
with pytest.raises(NoCacheError, match=r'No cache'):
2525
fetcher.fetch()
2626

2727

28-
@pytest.mark.parametrize('use_curl', [True, False])
29-
def test_fetch(tmpdir, use_curl):
28+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
29+
def test_fetch(tmpdir, _fetch_method):
3030
"""Ensure a fetch after expanding is effectively a no-op."""
3131
testpath = str(tmpdir)
3232
cache = os.path.join(testpath, 'cache.tar.gz')
3333
touch(cache)
3434
url = 'file:///{0}'.format(cache)
35-
with spack.config.override('config:use_curl', use_curl):
35+
with spack.config.override('config:url_fetch_method', _fetch_method):
3636
fetcher = CacheURLFetchStrategy(url=url)
3737
with Stage(fetcher, path=testpath) as stage:
3838
source_path = stage.source_path

lib/spack/spack/test/s3_fetch.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
import spack.stage as spack_stage
1313

1414

15-
@pytest.mark.parametrize('use_curl', [True, False])
16-
def test_s3fetchstrategy_sans_url(use_curl):
15+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
16+
def test_s3fetchstrategy_sans_url(_fetch_method):
1717
"""Ensure constructor with no URL fails."""
18-
with spack_config.override('config:use_curl', use_curl):
18+
with spack_config.override('config:url_fetch_method', _fetch_method):
1919
with pytest.raises(ValueError):
2020
spack_fs.S3FetchStrategy(None)
2121

2222

23-
@pytest.mark.parametrize('use_curl', [True, False])
24-
def test_s3fetchstrategy_bad_url(tmpdir, use_curl):
23+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
24+
def test_s3fetchstrategy_bad_url(tmpdir, _fetch_method):
2525
"""Ensure fetch with bad URL fails as expected."""
2626
testpath = str(tmpdir)
2727

28-
with spack_config.override('config:use_curl', use_curl):
28+
with spack_config.override('config:url_fetch_method', _fetch_method):
2929
fetcher = spack_fs.S3FetchStrategy(url='file:///does-not-exist')
3030
assert fetcher is not None
3131

@@ -36,13 +36,13 @@ def test_s3fetchstrategy_bad_url(tmpdir, use_curl):
3636
fetcher.fetch()
3737

3838

39-
@pytest.mark.parametrize('use_curl', [True, False])
40-
def test_s3fetchstrategy_downloaded(tmpdir, use_curl):
39+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
40+
def test_s3fetchstrategy_downloaded(tmpdir, _fetch_method):
4141
"""Ensure fetch with archive file already downloaded is a noop."""
4242
testpath = str(tmpdir)
4343
archive = os.path.join(testpath, 's3.tar.gz')
4444

45-
with spack_config.override('config:use_curl', use_curl):
45+
with spack_config.override('config:url_fetch_method', _fetch_method):
4646
class Archived_S3FS(spack_fs.S3FetchStrategy):
4747
@property
4848
def archive_file(self):

lib/spack/spack/test/url_fetch.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ def fn(v):
4949
return factory
5050

5151

52-
@pytest.mark.parametrize('use_curl', [True, False])
53-
def test_urlfetchstrategy_sans_url(use_curl):
52+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
53+
def test_urlfetchstrategy_sans_url(_fetch_method):
5454
"""Ensure constructor with no URL fails."""
55-
with spack.config.override('config:use_curl', use_curl):
55+
with spack.config.override('config:url_fetch_method', _fetch_method):
5656
with pytest.raises(ValueError):
5757
with fs.URLFetchStrategy(None):
5858
pass
5959

6060

61-
@pytest.mark.parametrize('use_curl', [True, False])
62-
def test_urlfetchstrategy_bad_url(tmpdir, use_curl):
61+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
62+
def test_urlfetchstrategy_bad_url(tmpdir, _fetch_method):
6363
"""Ensure fetch with bad URL fails as expected."""
6464
testpath = str(tmpdir)
65-
with spack.config.override('config:use_curl', use_curl):
65+
with spack.config.override('config:url_fetch_method', _fetch_method):
6666
with pytest.raises(fs.FailedDownloadError):
6767
fetcher = fs.URLFetchStrategy(url='file:///does-not-exist')
6868
assert fetcher is not None
@@ -75,7 +75,7 @@ def test_urlfetchstrategy_bad_url(tmpdir, use_curl):
7575

7676
def test_fetch_options(tmpdir, mock_archive):
7777
testpath = str(tmpdir)
78-
with spack.config.override('config:use_curl', True):
78+
with spack.config.override('config:url_fetch_method', 'curl'):
7979
fetcher = fs.URLFetchStrategy(url=mock_archive.url,
8080
fetch_options={'cookie': 'True',
8181
'timeout': 10})
@@ -87,11 +87,11 @@ def test_fetch_options(tmpdir, mock_archive):
8787
fetcher.fetch()
8888

8989

90-
@pytest.mark.parametrize('use_curl', [True, False])
91-
def test_archive_file_errors(tmpdir, mock_archive, use_curl):
90+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
91+
def test_archive_file_errors(tmpdir, mock_archive, _fetch_method):
9292
"""Ensure FetchStrategy commands may only be used as intended"""
9393
testpath = str(tmpdir)
94-
with spack.config.override('config:use_curl', use_curl):
94+
with spack.config.override('config:url_fetch_method', _fetch_method):
9595
fetcher = fs.URLFetchStrategy(url=mock_archive.url)
9696
assert fetcher is not None
9797
with pytest.raises(fs.FailedDownloadError):
@@ -112,7 +112,7 @@ def test_archive_file_errors(tmpdir, mock_archive, use_curl):
112112

113113

114114
@pytest.mark.parametrize('secure', [True, False])
115-
@pytest.mark.parametrize('use_curl', [True, False])
115+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
116116
@pytest.mark.parametrize('mock_archive',
117117
[('.tar.gz', 'z'), ('.tgz', 'z'),
118118
('.tar.bz2', 'j'), ('.tbz2', 'j'),
@@ -121,7 +121,7 @@ def test_archive_file_errors(tmpdir, mock_archive, use_curl):
121121
def test_fetch(
122122
mock_archive,
123123
secure,
124-
use_curl,
124+
_fetch_method,
125125
checksum_type,
126126
config,
127127
mutable_mock_repo
@@ -147,7 +147,7 @@ def test_fetch(
147147
# Enter the stage directory and check some properties
148148
with pkg.stage:
149149
with spack.config.override('config:verify_ssl', secure):
150-
with spack.config.override('config:use_curl', use_curl):
150+
with spack.config.override('config:url_fetch_method', _fetch_method):
151151
pkg.do_stage()
152152
with working_dir(pkg.stage.source_path):
153153
assert os.path.exists('configure')
@@ -168,13 +168,13 @@ def test_fetch(
168168
('url-list-test @3.0a1', 'foo-3.0a1.tar.gz', 'abc30a1'),
169169
('url-list-test @4.5-rc5', 'foo-4.5-rc5.tar.gz', 'abc45rc5'),
170170
])
171-
@pytest.mark.parametrize('use_curl', [True, False])
172-
def test_from_list_url(mock_packages, config, spec, url, digest, use_curl):
171+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
172+
def test_from_list_url(mock_packages, config, spec, url, digest, _fetch_method):
173173
"""
174174
Test URLs in the url-list-test package, which means they should
175175
have checksums in the package.
176176
"""
177-
with spack.config.override('config:use_curl', use_curl):
177+
with spack.config.override('config:url_fetch_method', _fetch_method):
178178
specification = Spec(spec).concretized()
179179
pkg = spack.repo.get(specification)
180180
fetch_strategy = fs.from_list_url(pkg)
@@ -187,10 +187,10 @@ def test_from_list_url(mock_packages, config, spec, url, digest, use_curl):
187187
assert fetch_strategy.extra_options == {'timeout': 60}
188188

189189

190-
@pytest.mark.parametrize('use_curl', [True, False])
191-
def test_from_list_url_unspecified(mock_packages, config, use_curl):
190+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
191+
def test_from_list_url_unspecified(mock_packages, config, _fetch_method):
192192
"""Test non-specific URLs from the url-list-test package."""
193-
with spack.config.override('config:use_curl', use_curl):
193+
with spack.config.override('config:url_fetch_method', _fetch_method):
194194
pkg = spack.repo.get('url-list-test')
195195

196196
spec = Spec('url-list-test @2.0.0').concretized()
@@ -236,7 +236,7 @@ def is_true():
236236

237237
monkeypatch.setattr(sys.stdout, 'isatty', is_true)
238238
monkeypatch.setattr(tty, 'msg_enabled', is_true)
239-
with spack.config.override('config:use_curl', True):
239+
with spack.config.override('config:url_fetch_method', 'curl'):
240240
fetcher = fs.URLFetchStrategy(mock_archive.url)
241241
with Stage(fetcher, path=testpath) as stage:
242242
assert fetcher.archive_file is None
@@ -246,10 +246,10 @@ def is_true():
246246
assert '##### 100' in status
247247

248248

249-
@pytest.mark.parametrize('use_curl', [True, False])
250-
def test_url_extra_fetch(tmpdir, mock_archive, use_curl):
249+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
250+
def test_url_extra_fetch(tmpdir, mock_archive, _fetch_method):
251251
"""Ensure a fetch after downloading is effectively a no-op."""
252-
with spack.config.override('config:use_curl', use_curl):
252+
with spack.config.override('config:url_fetch_method', _fetch_method):
253253
testpath = str(tmpdir)
254254
fetcher = fs.URLFetchStrategy(mock_archive.url)
255255
with Stage(fetcher, path=testpath) as stage:
@@ -267,12 +267,12 @@ def test_url_extra_fetch(tmpdir, mock_archive, use_curl):
267267
['https://ftpmirror.gnu.org/autoconf/autoconf-2.62.tar.gz',
268268
'https://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz'])
269269
])
270-
@pytest.mark.parametrize('use_curl', [True, False])
271-
def test_candidate_urls(pkg_factory, url, urls, version, expected, use_curl):
270+
@pytest.mark.parametrize('_fetch_method', ['curl', 'urllib'])
271+
def test_candidate_urls(pkg_factory, url, urls, version, expected, _fetch_method):
272272
"""Tests that candidate urls include mirrors and that they go through
273273
pattern matching and substitution for versions.
274274
"""
275-
with spack.config.override('config:use_curl', use_curl):
275+
with spack.config.override('config:url_fetch_method', _fetch_method):
276276
pkg = pkg_factory(url, urls)
277277
f = fs._from_merged_attrs(fs.URLFetchStrategy, pkg, version)
278278
assert f.candidate_urls == expected
@@ -298,7 +298,7 @@ def _which(*args, **kwargs):
298298

299299
testpath = str(tmpdir)
300300
url = 'http://github.com/spack/spack'
301-
with spack.config.override('config:use_curl', True):
301+
with spack.config.override('config:url_fetch_method', 'curl'):
302302
fetcher = fs.URLFetchStrategy(url=url)
303303
assert fetcher is not None
304304
with pytest.raises(TypeError, match='object is not callable'):

0 commit comments

Comments
 (0)