bug fix: Display error when curl is missing even in non-debug mode (#19695)
This commit is contained in:
		| @@ -42,7 +42,7 @@ | |||||||
| from llnl.util.filesystem import ( | from llnl.util.filesystem import ( | ||||||
|     working_dir, mkdirp, temp_rename, temp_cwd, get_single_file) |     working_dir, mkdirp, temp_rename, temp_cwd, get_single_file) | ||||||
| from spack.util.compression import decompressor_for, extension | from spack.util.compression import decompressor_for, extension | ||||||
| from spack.util.executable import which | from spack.util.executable import which, CommandNotFoundError | ||||||
| from spack.util.string import comma_and, quote | from spack.util.string import comma_and, quote | ||||||
| from spack.version import Version, ver | from spack.version import Version, ver | ||||||
| 
 | 
 | ||||||
| @@ -267,7 +267,10 @@ def __init__(self, url=None, checksum=None, **kwargs): | |||||||
|     @property |     @property | ||||||
|     def curl(self): |     def curl(self): | ||||||
|         if not self._curl: |         if not self._curl: | ||||||
|  |             try: | ||||||
|                 self._curl = which('curl', required=True) |                 self._curl = which('curl', required=True) | ||||||
|  |             except CommandNotFoundError as exc: | ||||||
|  |                 tty.error(str(exc)) | ||||||
|         return self._curl |         return self._curl | ||||||
| 
 | 
 | ||||||
|     def source_id(self): |     def source_id(self): | ||||||
|   | |||||||
| @@ -18,6 +18,7 @@ | |||||||
| from spack.stage import Stage | from spack.stage import Stage | ||||||
| from spack.version import ver | from spack.version import ver | ||||||
| import spack.util.crypto as crypto | import spack.util.crypto as crypto | ||||||
|  | import spack.util.executable | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.fixture(params=list(crypto.hashes.keys())) | @pytest.fixture(params=list(crypto.hashes.keys())) | ||||||
| @@ -225,3 +226,29 @@ def test_candidate_urls(pkg_factory, url, urls, version, expected): | |||||||
|     pkg = pkg_factory(url, urls, fetch_options={'timeout': 60}) |     pkg = pkg_factory(url, urls, fetch_options={'timeout': 60}) | ||||||
|     f = fs._from_merged_attrs(fs.URLFetchStrategy, pkg, version) |     f = fs._from_merged_attrs(fs.URLFetchStrategy, pkg, version) | ||||||
|     assert f.extra_options == {'timeout': 60} |     assert f.extra_options == {'timeout': 60} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @pytest.mark.regression('19673') | ||||||
|  | def test_missing_curl(tmpdir, monkeypatch): | ||||||
|  |     """Ensure a fetch involving missing curl package reports the error.""" | ||||||
|  |     err_fmt = 'No such command {0}' | ||||||
|  | 
 | ||||||
|  |     def _which(*args, **kwargs): | ||||||
|  |         err_msg = err_fmt.format(args[0]) | ||||||
|  |         raise spack.util.executable.CommandNotFoundError(err_msg) | ||||||
|  | 
 | ||||||
|  |     # Patching the 'which' symbol imported by fetch_strategy works | ||||||
|  |     # since it is too late in import processing to patch the defining | ||||||
|  |     # (spack.util.executable) module's symbol. | ||||||
|  |     monkeypatch.setattr(fs, 'which', _which) | ||||||
|  | 
 | ||||||
|  |     testpath = str(tmpdir) | ||||||
|  |     url = 'http://github.com/spack/spack' | ||||||
|  |     fetcher = fs.URLFetchStrategy(url=url) | ||||||
|  |     assert fetcher is not None | ||||||
|  | 
 | ||||||
|  |     with pytest.raises(TypeError, match='object is not callable'): | ||||||
|  |         with Stage(fetcher, path=testpath) as stage: | ||||||
|  |             out = stage.fetch() | ||||||
|  | 
 | ||||||
|  |         assert err_fmt.format('curl') in out | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tamara Dahlgren
					Tamara Dahlgren