From dfb48469491885d3a90efd17cb01dc05da3af82b Mon Sep 17 00:00:00 2001 From: Miles Wells Date: Fri, 25 Oct 2024 15:00:37 +0300 Subject: [PATCH] Resolves #145; resolves #144 --- CHANGELOG.md | 9 ++++++++- one/__init__.py | 2 +- one/params.py | 13 +++++++++++-- one/remote/aws.py | 2 +- one/tests/test_params.py | 12 ++++++++++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 587853d6..dddf14ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog -## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [2.10.0] +## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [2.10.1] + +### Modified + +- prompt user to strip quotation marks if used during ONE setup +- indicate when downloading from S3 + +## [2.10.0] This version improves behaviour of loading revisions and loading datasets from list_datasets output. ### Modified diff --git a/one/__init__.py b/one/__init__.py index 07a5d384..442d51f1 100644 --- a/one/__init__.py +++ b/one/__init__.py @@ -1,2 +1,2 @@ """The Open Neurophysiology Environment (ONE) API.""" -__version__ = '2.10.0' +__version__ = '2.10.1' diff --git a/one/params.py b/one/params.py index 6de042cc..83f31b7b 100644 --- a/one/params.py +++ b/one/params.py @@ -124,6 +124,7 @@ def setup(client=None, silent=False, make_default=None, username=None, cache_dir if not silent: prompt = 'Param %s, current value is ["%s"]:' par = iopar.as_dict(par_default) + quotes = '"\'`' # Iterate through non-password pars for k in filter(lambda k: 'PWD' not in k, par.keys()): cpar = _get_current_par(k, par_current) @@ -137,10 +138,18 @@ def setup(client=None, silent=False, make_default=None, username=None, cache_dir url_parsed = urlsplit(par[k]) if not (url_parsed.netloc and re.match('https?', url_parsed.scheme)): raise ValueError(f'{k} must be valid HTTP URL') - if k == 'ALYX_URL': - client = par[k] else: par[k] = input(prompt % (k, cpar)).strip() or cpar + # Check whether user erroneously entered quotation marks + # Prompting the user here (hopefully) corrects them before they input a password + # where the use of quotation marks may be legitimate + if par[k] and len(par[k]) >= 2 and par[k][0] in quotes and par[k][-1] in quotes: + warnings.warn('Do not use quotation marks with input answers', UserWarning) + ans = input('Strip quotation marks from response? [Y/n]:').strip() or 'y' + if ans.lower()[0] == 'y': + par[k] = par[k].strip(quotes) + if k == 'ALYX_URL': + client = par[k] cpar = _get_current_par('HTTP_DATA_SERVER_PWD', par_current) prompt = f'Enter the FlatIron HTTP password for {par["HTTP_DATA_SERVER_LOGIN"]} '\ diff --git a/one/remote/aws.py b/one/remote/aws.py index 9ae2792a..cc0a07ff 100644 --- a/one/remote/aws.py +++ b/one/remote/aws.py @@ -254,7 +254,7 @@ def s3_download_file(source, destination, s3=None, bucket_name=None, overwrite=F _logger.debug(f"{destination} exists and match size -- skipping") return destination with tqdm(total=filesize, unit='B', - unit_scale=True, desc=str(destination)) as t: + unit_scale=True, desc=f'(S3) {destination}') as t: file_object.download_file(Filename=str(destination), Callback=_callback_hook(t)) except (NoCredentialsError, PartialCredentialsError) as ex: raise ex # Credentials need updating in Alyx # pragma: no cover diff --git a/one/tests/test_params.py b/one/tests/test_params.py index 0ae61079..9aeccd28 100644 --- a/one/tests/test_params.py +++ b/one/tests/test_params.py @@ -57,8 +57,16 @@ def test_setup(self, _): # Check verification prompt resp_map = {'ALYX_LOGIN': 'mistake', 'settings correct?': 'N'} with mock.patch('one.params.input', new=partial(self._mock_input, **resp_map)): - cache = one.params.setup() - self.assertNotEqual(cache.ALYX_LOGIN, 'mistake') + one.params.setup() + par = one.params.get(self.url, silent=True) + self.assertNotEqual(par.ALYX_LOGIN, 'mistake') + + # Check prompt when quotation marks used + resp_map = {'ALYX_LOGIN': '"foo"', 'Strip quotation marks': 'y', 'settings correct?': 'Y'} + with mock.patch('one.params.input', new=partial(self._mock_input, **resp_map)): + self.assertWarnsRegex(UserWarning, 'quotation marks', one.params.setup) + par = one.params.get(self.url, silent=True) + self.assertEqual(par.ALYX_LOGIN, 'foo', 'failed to strip quotes from user input') # Check that raises ValueError when bad URL provided self.url = 'ftp://foo.bar.org'