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

ENH: extend message for a NoDatasetArgumentFound in require_dataset #4285

Merged
merged 3 commits into from Mar 13, 2020
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
4 changes: 2 additions & 2 deletions datalad/core/local/tests/test_diff.py
Expand Up @@ -16,7 +16,7 @@
import os.path as op
from datalad.support.external_versions import external_versions
from datalad.support.exceptions import (
NoDatasetArgumentFound,
NoDatasetFound,
)

from datalad.consts import PRE_INIT_COMMIT_SHA
Expand Down Expand Up @@ -154,7 +154,7 @@ def _dirty_results(res):
@with_tempfile(mkdir=True)
def test_diff(path, norepo):
with chpwd(norepo):
assert_raises(NoDatasetArgumentFound, diff)
assert_raises(NoDatasetFound, diff)
ds = Dataset(path).create()
assert_repo_status(ds.path)
# reports stupid revision input
Expand Down
4 changes: 2 additions & 2 deletions datalad/core/local/tests/test_run.py
Expand Up @@ -34,7 +34,7 @@
from datalad.cmdline.main import main
from datalad.distribution.dataset import Dataset
from datalad.support.exceptions import (
NoDatasetArgumentFound,
NoDatasetFound,
CommandError,
)
from datalad.api import (
Expand Down Expand Up @@ -76,7 +76,7 @@
def test_invalid_call(path):
with chpwd(path):
# no dataset, no luck
assert_raises(NoDatasetArgumentFound, run, 'doesntmatter')
assert_raises(NoDatasetFound, run, 'doesntmatter')
# dirty dataset
ds = Dataset(path).create()
create_tree(ds.path, {'this': 'dirty'})
Expand Down
4 changes: 2 additions & 2 deletions datalad/core/local/tests/test_status.py
Expand Up @@ -24,7 +24,7 @@
with_tempfile,
)
from datalad.support.exceptions import (
NoDatasetArgumentFound,
NoDatasetFound,
IncompleteResultsError,
)
from datalad.distribution.dataset import Dataset
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_status_basics(path, linkpath, otherdir):
path = linkpath

with chpwd(path):
assert_raises(NoDatasetArgumentFound, status)
assert_raises(NoDatasetFound, status)
ds = Dataset(path).create()
# outcome identical between ds= and auto-discovery
with chpwd(path):
Expand Down
8 changes: 6 additions & 2 deletions datalad/distribution/dataset.py
Expand Up @@ -29,7 +29,7 @@
# DueCredit
from datalad.support.due import due
from datalad.support.due_utils import duecredit_dataset
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support.exceptions import NoDatasetFound
from datalad.support.gitrepo import (
GitRepo,
InvalidGitRepositoryError,
Expand Down Expand Up @@ -563,7 +563,11 @@ def require_dataset(dataset, check_installed=True, purpose=None):
if dataset is None: # possible scenario of cmdline calls
dspath = get_dataset_root(getpwd())
if not dspath:
raise NoDatasetArgumentFound("No dataset found")
raise NoDatasetFound(
"No dataset found at '{}'. Specify a dataset to work with "
"by providing its path via the `dataset` option, "
"or change the current working directory to be in a "
"dataset.".format(getpwd()))
dataset = Dataset(dspath)

assert(dataset is not None)
Expand Down
4 changes: 2 additions & 2 deletions datalad/interface/download_url.py
Expand Up @@ -33,7 +33,7 @@
from ..support.annexrepo import AnnexRepo, AnnexBatchCommandError
from ..support.param import Parameter
from ..support.constraints import EnsureStr, EnsureNone
from ..support.exceptions import NoDatasetArgumentFound
from ..support.exceptions import NoDatasetFound

from logging import getLogger
lgr = getLogger('datalad.api.download-url')
Expand Down Expand Up @@ -104,7 +104,7 @@ def __call__(urls, dataset=None, path=None, overwrite=False,
ds = require_dataset(
dataset, check_installed=True,
purpose='downloading urls')
except NoDatasetArgumentFound:
except NoDatasetFound:
pass

common_report = {"action": "download_url",
Expand Down
4 changes: 2 additions & 2 deletions datalad/interface/run_procedure.py
Expand Up @@ -33,7 +33,7 @@
from datalad.support.param import Parameter
from datalad.distribution.dataset import datasetmethod
from datalad.support.exceptions import InsufficientArgumentsError
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support.exceptions import NoDatasetFound
from datalad.utils import (
quote_cmdlinearg,
split_cmdline,
Expand Down Expand Up @@ -320,7 +320,7 @@ def __call__(
ds = require_dataset(
dataset, check_installed=False,
purpose='run a procedure')
except NoDatasetArgumentFound:
except NoDatasetFound:
ds = None

if discover:
Expand Down
4 changes: 2 additions & 2 deletions datalad/interface/tests/test_unlock.py
Expand Up @@ -21,7 +21,7 @@
from datalad.api import unlock
from datalad.utils import Path
from datalad.support.exceptions import InsufficientArgumentsError
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support.exceptions import NoDatasetFound
from datalad.support.annexrepo import AnnexRepo
from datalad.tests.utils import with_tempfile
from datalad.tests.utils import assert_false
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_unlock_raises(path, path2, path3):
assert_raises(InsufficientArgumentsError,
unlock, dataset=None, path=None)
# no dataset and path not within a dataset:
assert_raises(NoDatasetArgumentFound,
assert_raises(NoDatasetFound,
unlock, dataset=None, path=path2)

create(path=path, no_annex=True)
Expand Down
10 changes: 5 additions & 5 deletions datalad/metadata/search.py
Expand Up @@ -44,7 +44,7 @@
get_suggestions_msg,
unique,
)
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support.exceptions import NoDatasetFound
from datalad.ui import ui
from datalad.dochelpers import single_or_plural
from datalad.dochelpers import exc_str
Expand Down Expand Up @@ -191,7 +191,7 @@ def _search_from_virgin_install(dataset, query):
exc_info = sys.exc_info()
if dataset is None:
if not ui.is_interactive:
raise NoDatasetArgumentFound(
raise NoDatasetFound(
"No DataLad dataset found. Specify a dataset to be "
"searched, or run interactively to get assistance "
"installing a queriable superdataset."
Expand All @@ -212,7 +212,7 @@ def _search_from_virgin_install(dataset, query):
else:
raise exc_info[1]
else:
raise NoDatasetArgumentFound(
raise NoDatasetFound(
"No DataLad dataset found at current location. "
"The DataLad superdataset location %r exists, "
"but does not contain an dataset."
Expand Down Expand Up @@ -1207,11 +1207,11 @@ def __call__(query=None,
try:
ds = require_dataset(dataset, check_installed=True, purpose='dataset search')
if ds.id is None:
raise NoDatasetArgumentFound(
raise NoDatasetFound(
"This does not seem to be a dataset (no DataLad dataset ID "
"found). 'datalad create --force %s' can initialize "
"this repository as a DataLad dataset" % ds.path)
except NoDatasetArgumentFound:
except NoDatasetFound:
for r in _search_from_virgin_install(dataset, query):
yield r
return
Expand Down
4 changes: 2 additions & 2 deletions datalad/metadata/tests/test_base.py
Expand Up @@ -40,7 +40,7 @@
from datalad.tests.utils import assert_re_in
from datalad.tests.utils import known_failure_githubci_win
from datalad.support.exceptions import InsufficientArgumentsError
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support.exceptions import NoDatasetFound
from datalad.support.gitrepo import GitRepo
from datalad.support.annexrepo import AnnexRepo

Expand Down Expand Up @@ -228,7 +228,7 @@ def _kill_time(meta):

@with_tempfile(mkdir=True)
def test_get_aggregates_fails(path):
with chpwd(path), assert_raises(NoDatasetArgumentFound):
with chpwd(path), assert_raises(NoDatasetFound):
metadata(get_aggregates=True)
ds = Dataset(path).create()
res = ds.metadata(get_aggregates=True, on_failure='ignore')
Expand Down
12 changes: 6 additions & 6 deletions datalad/metadata/tests/test_search.py
Expand Up @@ -33,7 +33,7 @@
from datalad.tests.utils import SkipTest
from datalad.tests.utils import eq_
from datalad.tests.utils import known_failure_githubci_win
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support.exceptions import NoDatasetFound

from datalad.api import search

Expand All @@ -46,7 +46,7 @@
def test_search_outside1_noninteractive_ui(tdir):
# we should raise an informative exception
with chpwd(tdir):
with assert_raises(NoDatasetArgumentFound) as cme:
with assert_raises(NoDatasetFound) as cme:
list(search("bu"))
assert_in('run interactively', str(cme.exception))

Expand All @@ -60,7 +60,7 @@ def test_search_outside1(tdir, newhome):
with patch_config({'datalad.locations.default-dataset': newhome}):
gen = search("bu", return_type='generator')
assert_is_generator(gen)
assert_raises(NoDatasetArgumentFound, next, gen)
assert_raises(NoDatasetFound, next, gen)

# and if we point to some non-existing dataset
with assert_raises(ValueError):
Expand Down Expand Up @@ -94,14 +94,14 @@ def test_search_outside1_install_default_ds(tdir, default_dspath):
# and what if we say "no" to install?
ui.add_responses('no')
mock_install.reset_mock()
with assert_raises(NoDatasetArgumentFound):
with assert_raises(NoDatasetFound):
list(search("."))

# and if path exists and is a valid dataset and we say "no"
Dataset(default_dspath).create()
ui.add_responses('no')
mock_install.reset_mock()
with assert_raises(NoDatasetArgumentFound):
with assert_raises(NoDatasetFound):
list(search("."))


Expand Down Expand Up @@ -173,7 +173,7 @@ def test_our_metadataset_search(tdir):
def test_search_non_dataset(tdir):
from datalad.support.gitrepo import GitRepo
GitRepo(tdir, create=True)
with assert_raises(NoDatasetArgumentFound) as cme:
with assert_raises(NoDatasetFound) as cme:
list(search('smth', dataset=tdir))
# Should instruct user how that repo could become a datalad dataset
assert_in("datalad create --force", str(cme.exception))
Expand Down
4 changes: 2 additions & 2 deletions datalad/plugin/wtf.py
Expand Up @@ -335,13 +335,13 @@ class WTF(Interface):
@eval_results
def __call__(dataset=None, sensitive=None, sections=None, decor=None, clipboard=None):
from datalad.distribution.dataset import require_dataset
from datalad.support.exceptions import NoDatasetArgumentFound
from datalad.support.exceptions import NoDatasetFound
from datalad.interface.results import get_status_dict

ds = None
try:
ds = require_dataset(dataset, check_installed=False, purpose='reporting')
except NoDatasetArgumentFound:
except NoDatasetFound:
# failure is already logged
pass
if ds and not ds.is_installed():
Expand Down
5 changes: 5 additions & 0 deletions datalad/support/exceptions.py
Expand Up @@ -224,6 +224,11 @@ class NoDatasetArgumentFound(InsufficientArgumentsError):
pass


class NoDatasetFound(NoDatasetArgumentFound):
"""Raised whenever a dataset is required, but none could be determined"""
pass


class OutOfSpaceError(CommandError):
"""To be raised whenever a command fails if we have no sufficient space

Expand Down