Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BF: check special remotes of type git by uuid to (not) inform if they are not enabled #3547

Merged
merged 2 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions datalad/distribution/tests/test_clone.py
Expand Up @@ -16,6 +16,7 @@
slow
)

import logging
import os
from os.path import join as opj
from os.path import isdir
Expand Down Expand Up @@ -54,6 +55,7 @@
from datalad.tests.utils import ok_startswith
from datalad.tests.utils import ok_clean_git
from datalad.tests.utils import serve_path_via_http
from datalad.tests.utils import swallow_logs
from datalad.tests.utils import use_cassette
from datalad.tests.utils import skip_if_no_network
from datalad.tests.utils import skip_if
Expand Down Expand Up @@ -358,3 +360,15 @@ def test_clone_report_permission_issue(tdir):
message="could not create work tree dir '%s/%s': Permission denied"
% (pdir, get_datasets_topdir())
)


@skip_if_no_network
@with_tempfile
def test_autoenabled_remote_msg(path):
# Verify that no message about a remote not been enabled is displayed
# whenever the remote we clone is the type=git special remote, so the name
# of the remote might not match
with swallow_logs(new_level=logging.INFO) as cml:
res = clone('///repronim/containers', path)
assert_status('ok', res)
assert_not_in("not auto-enabled", cml.out)
68 changes: 53 additions & 15 deletions datalad/distribution/utils.py
Expand Up @@ -19,13 +19,14 @@

from six.moves.urllib.parse import unquote as urlunquote

from ..dochelpers import single_or_plural
from datalad.support.annexrepo import GitRepo
from datalad.support.annexrepo import AnnexRepo
from datalad.support.network import DataLadRI
from datalad.support.network import URL
from datalad.support.network import RI
from datalad.support.network import PathRI
from datalad.utils import knows_annex
from datalad.utils import knows_annex, assure_bool


lgr = logging.getLogger('datalad.distribution.utils')
Expand Down Expand Up @@ -152,20 +153,57 @@ def _handle_possible_annex_dataset(dataset, reckless, description=None):
repo._init(description=description)
if reckless:
repo._run_annex_command('untrust', annex_options=['here'])
# go through list of special remotes and issue info message that
# some additional ones are present and were not auto-enabled
remote_names = repo.get_remotes(
with_urls_only=False,
exclude_special_remotes=False)
for k, v in repo.get_special_remotes().items():
sr_name = v.get('name', None)
if sr_name and sr_name not in remote_names:
# if it is not listed among the remotes, it wasn't enabled
lgr.info(
'access to dataset sibling "%s" not auto-enabled, enable with:\n\t\tdatalad siblings -d "%s" enable -s %s',
sr_name,
dataset.path,
sr_name)

srs = {True: [], False: []} # special remotes by "autoenable" key
remote_uuids = None # might be necessary to discover known UUIDs

for uuid, config in repo.get_special_remotes().items():
sr_name = config.get('name', None)
sr_autoenable = config.get('autoenable', False)
try:
sr_autoenable = assure_bool(sr_autoenable)
except ValueError:
# Be resilient against misconfiguration. Here it is only about
# informing the user, so no harm would be done
lgr.warning(
'Failed to process "autoenable" value %r for sibling %s in '
'dataset %s as bool. You might need to enable it later '
'manually and/or fix it up to avoid this message in the future.',
sr_autoenable, sr_name, dataset.path)
continue

# determine either there is a registered remote with matching UUID
if uuid:
if remote_uuids is None:
remote_uuids = {
repo.config.get('remote.%s.annex-uuid' % r)
for r in repo.get_remotes()
}
if uuid not in remote_uuids:
srs[sr_autoenable].append(sr_name)

if srs[True]:
lgr.debug(
"configuration for %s %s added because of autoenable,"
" but no UUIDs for them yet known for dataset %s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see much value in this because it seems to be the norm, but it's of course not a big deal given that it's logged at the debug level.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Debug messages have only hypothetical value of helping to troubleshoot when something goes wrong. Given the tricky nature of all this, might come handy IMHO

# since we are only at debug level, we could call things their
# proper names
single_or_plural("special remote", "special remotes", len(srs[True]), True),
", ".join(srs[True]),
dataset.path
)

if srs[False]:
# if has no auto-enable special remotes
lgr.info(
'access to %s %s not auto-enabled, enable with:\n\t\tdatalad siblings -d "%s" enable -s %s',
# but since humans might read it, we better confuse them with our
# own terms!
single_or_plural("dataset sibling", "dataset siblings", len(srs[False]), True),
", ".join(srs[False]),
dataset.path,
srs[False][0] if len(srs[False]) == 1 else "SIBLING",
)


def _get_installationpath_from_url(url):
Expand Down