Skip to content

Commit

Permalink
experiments: disable feature by default
Browse files Browse the repository at this point in the history
* experiments only enabled in test environment (DVC_TEST) or when
  core.experiments config option is true
  • Loading branch information
pmrowla committed Jul 16, 2020
1 parent 4aa6942 commit a7b6d65
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions dvc/command/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def run(self):
from rich.console import Console
from dvc.utils.pager import pager

if not self.repo.experiments:
return 0

try:
all_experiments = self.repo.experiments.show(
all_branches=self.args.all_branches,
Expand All @@ -139,6 +142,9 @@ def run(self):

class CmdExperimentsCheckout(CmdBase):
def run(self):
if not self.repo.experiments:
return 0

self.repo.experiments.checkout(
self.args.experiment, force=self.args.force
)
Expand Down Expand Up @@ -185,6 +191,9 @@ def _round(val):

class CmdExperimentsDiff(CmdBase):
def run(self):
if not self.repo.experiments:
return 0

try:
diff = self.repo.experiments.diff(
a_rev=self.args.a_rev,
Expand Down
1 change: 1 addition & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class RelPath(str):
Optional("analytics", default=True): Bool,
Optional("hardlink_lock", default=False): Bool,
Optional("no_scm", default=False): Bool,
Optional("experiments", default=False): Bool,
},
"cache": {
"local": str,
Expand Down
8 changes: 6 additions & 2 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def __init__(self, root_dir=None, scm=None, rev=None):
self.plots = Plots(self)
self.params = Params(self)

self.experiments = Experiments(self)
try:
self.experiments = Experiments(self)
except NotImplementedError:
self.experiments = None

self._ignore()

Expand Down Expand Up @@ -196,8 +199,9 @@ def _ignore(self):
flist = [
self.config.files["local"],
self.tmp_dir,
self.experiments.exp_dir,
]
if self.experiments:
flist.append(self.experiments.exp_dir)

if path_isin(self.cache.local.cache_dir, self.root_dir):
flist += [self.cache.local.cache_dir]
Expand Down
8 changes: 7 additions & 1 deletion dvc/repo/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dvc.exceptions import DvcException
from dvc.scm.git import Git
from dvc.stage.serialize import to_lockfile
from dvc.utils import dict_sha256, relpath
from dvc.utils import dict_sha256, env2bool, relpath
from dvc.utils.fs import remove

logger = logging.getLogger(__name__)
Expand All @@ -28,6 +28,12 @@ class Experiments:
EXPERIMENTS_DIR = "experiments"

def __init__(self, repo):
if not (
env2bool("DVC_TEST")
or repo.config["core"].get("experiments", False)
):
raise NotImplementedError

self.repo = repo

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def reproduce(
)

experiment = kwargs.pop("experiment", False)
if experiment:
if experiment and self.experiments:
try:
return self.experiments.new(
target=target,
Expand Down

0 comments on commit a7b6d65

Please sign in to comment.