Skip to content

Commit

Permalink
Resolves #145; resolves #144
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed Oct 25, 2024
1 parent c83b7e6 commit dfb4846
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion one/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""The Open Neurophysiology Environment (ONE) API."""
__version__ = '2.10.0'
__version__ = '2.10.1'
13 changes: 11 additions & 2 deletions one/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]} '\
Expand Down
2 changes: 1 addition & 1 deletion one/remote/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions one/tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit dfb4846

Please sign in to comment.