mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-18 23:10:14 +01:00
Merge pull request #425 from dataversioncontrol/misk_changes_3
Misk changes 3: checkout test, show workflow and misc
This commit is contained in:
+1
-1
@@ -230,7 +230,7 @@ def parse_args(argv=None):
|
||||
workflow_parser.add_argument(
|
||||
'target',
|
||||
nargs='?',
|
||||
help='Target metric data file')
|
||||
help='Target metric file')
|
||||
workflow_parser.add_argument(
|
||||
'-d',
|
||||
'--dvc-commits',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import stat
|
||||
|
||||
from dvc.command.common.base import CmdBase
|
||||
from dvc.logger import Logger
|
||||
@@ -15,6 +16,7 @@ class CmdCheckout(CmdBase):
|
||||
|
||||
for file in self.project.cache.find_cache(untracked).keys():
|
||||
Logger.info(u'Remove \'{}\''.format(file))
|
||||
os.chmod(file, stat.S_IWRITE)
|
||||
os.remove(file)
|
||||
|
||||
dir = os.path.dirname(file)
|
||||
|
||||
@@ -23,7 +23,7 @@ class CmdBase(object):
|
||||
if os.path.isdir(dvc_dir):
|
||||
return root
|
||||
root = os.path.dirname(root)
|
||||
msg = "Not a dvc repository (or any parent up to mount point {})"
|
||||
msg = "Not a dvc repository (checked up to mount point {})"
|
||||
raise DvcException(msg.format(root))
|
||||
|
||||
def run_cmd(self):
|
||||
|
||||
@@ -7,6 +7,7 @@ from dvc.command.common.base import CmdBase
|
||||
from dvc.graph.workflow import Workflow
|
||||
from dvc.graph.commit import Commit
|
||||
from dvc.executor import Executor, ExecutorError
|
||||
from dvc.utils import parse_target_metric_file
|
||||
|
||||
|
||||
class CmdShowWorkflow(CmdBase):
|
||||
@@ -48,7 +49,7 @@ class CmdShowWorkflow(CmdBase):
|
||||
if target not in changed_files:
|
||||
return False, None
|
||||
|
||||
metric = utils.parse_target_metric_file(target)
|
||||
metric = parse_target_metric_file(target)
|
||||
if metric is None:
|
||||
return False, None
|
||||
|
||||
|
||||
+10
-3
@@ -5,7 +5,6 @@ import os
|
||||
import configparser
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.logger import Logger
|
||||
|
||||
|
||||
class ConfigError(DvcException):
|
||||
@@ -16,6 +15,7 @@ class ConfigError(DvcException):
|
||||
|
||||
class Config(object):
|
||||
CONFIG = 'config'
|
||||
SECTION_GLOBAL = 'Global'
|
||||
CONFIG_TEMPLATE = '''
|
||||
[Global]
|
||||
# Supported clouds: AWS, GCP
|
||||
@@ -59,9 +59,16 @@ ProjectName =
|
||||
def __init__(self, dvc_dir):
|
||||
self.dvc_dir = os.path.abspath(os.path.realpath(dvc_dir))
|
||||
self.config_file = os.path.join(dvc_dir, self.CONFIG)
|
||||
|
||||
|
||||
self._config = configparser.SafeConfigParser()
|
||||
self._config.read(self.config_file)
|
||||
|
||||
try:
|
||||
self._config.read(self.config_file)
|
||||
except configparser.Error as ex:
|
||||
raise ConfigError(ex.message)
|
||||
|
||||
if not self._config.has_section(self.SECTION_GLOBAL):
|
||||
raise ConfigError(u'section \'{}\' was not found'.format(self.SECTION_GLOBAL))
|
||||
|
||||
@staticmethod
|
||||
def init(dvc_dir):
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import colorama
|
||||
|
||||
from dvc.config import Config
|
||||
|
||||
colorama.init()
|
||||
|
||||
@@ -26,7 +26,7 @@ class Logger(object):
|
||||
|
||||
def __init__(self, config=None):
|
||||
if config:
|
||||
level = config['Global'].get('LogLevel', None)
|
||||
level = config[Config.SECTION_GLOBAL].get('LogLevel', None)
|
||||
Logger.set_level(level)
|
||||
|
||||
@staticmethod
|
||||
|
||||
+2
-2
@@ -232,7 +232,6 @@ class Output(Dependency):
|
||||
if self.project.scm.is_tracked(self.path):
|
||||
raise CmdOutputAlreadyTrackedError(self.path)
|
||||
|
||||
self.project.scm.ignore(self.path)
|
||||
self.link()
|
||||
|
||||
def remove(self):
|
||||
@@ -242,7 +241,6 @@ class Output(Dependency):
|
||||
self.project.logger.debug("Removing '{}'".format(self.path))
|
||||
os.chmod(self.path, stat.S_IWUSR)
|
||||
os.unlink(self.path)
|
||||
self.project.scm.ignore_remove(self.path)
|
||||
if os.path.exists(self.cache):
|
||||
os.chmod(self.cache, stat.S_IREAD)
|
||||
|
||||
@@ -295,6 +293,7 @@ class Stage(object):
|
||||
def remove_outs(self):
|
||||
for out in self.outs:
|
||||
out.remove()
|
||||
self.project.scm.ignore_remove(out.path)
|
||||
|
||||
def remove(self):
|
||||
self.remove_outs()
|
||||
@@ -354,6 +353,7 @@ class Stage(object):
|
||||
for out in self.outs:
|
||||
out.update()
|
||||
out.save()
|
||||
self.project.scm.ignore(out.path)
|
||||
|
||||
def run(self):
|
||||
if not self.is_data_source:
|
||||
|
||||
+91
-5
@@ -4,11 +4,7 @@ import shutil
|
||||
import filecmp
|
||||
|
||||
from dvc.main import main
|
||||
from dvc.data_cloud import file_md5
|
||||
from dvc.stage import Stage, CmdOutputNoCacheError, CmdOutputOutsideOfRepoError
|
||||
from dvc.stage import CmdOutputDoesNotExistError, CmdOutputIsNotFileError
|
||||
from dvc.project import StageNotFoundError
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
from tests.test_repro import TestRepro
|
||||
|
||||
|
||||
@@ -35,3 +31,93 @@ class TestCmdCheckout(TestCheckout):
|
||||
ret = main(['checkout'])
|
||||
self.assertEqual(ret, 0)
|
||||
self._test_checkout()
|
||||
|
||||
|
||||
class CheckoutBase(TestDvc):
|
||||
GIT_IGNORE = '.gitignore'
|
||||
|
||||
def commit_data_file(self, fname, content='random text'):
|
||||
with open(fname, 'w') as fd:
|
||||
fd.write(content)
|
||||
self.dvc.add(fname)
|
||||
self.dvc.scm.add([fname + '.dvc', '.gitignore'])
|
||||
self.dvc.scm.commit('adding ' + fname)
|
||||
|
||||
def read_ignored(self):
|
||||
return list(map(lambda s: s.strip('\n'), open(self.GIT_IGNORE).readlines()))
|
||||
|
||||
|
||||
class TestRemoveFilesWhenCheckout(CheckoutBase):
|
||||
def test(self):
|
||||
fname = 'file_in_a_branch'
|
||||
branch_master = 'master'
|
||||
branch_1 = 'b1'
|
||||
|
||||
self.dvc.scm.add(self.dvc.scm.untracked_files())
|
||||
self.dvc.scm.commit('add all files')
|
||||
|
||||
# add the file into a separate branch
|
||||
self.dvc.scm.checkout(branch_1, True)
|
||||
main(['checkout'])
|
||||
self.commit_data_file(fname)
|
||||
|
||||
# Checkout back in master
|
||||
self.dvc.scm.checkout(branch_master)
|
||||
self.assertTrue(os.path.exists(fname))
|
||||
|
||||
# Make sure `dvc checkout` removes the file
|
||||
# self.dvc.checkout()
|
||||
main(['checkout'])
|
||||
self.assertFalse(os.path.exists(fname))
|
||||
|
||||
|
||||
class TestGitIgnoreBasic(CheckoutBase):
|
||||
def test(self):
|
||||
fname1 = 'file_1'
|
||||
fname2 = 'file_2'
|
||||
|
||||
self.dvc.scm.add(self.dvc.scm.untracked_files())
|
||||
self.dvc.scm.commit('add all files')
|
||||
|
||||
self.assertFalse(os.path.exists(self.GIT_IGNORE))
|
||||
|
||||
self.commit_data_file(fname1)
|
||||
self.commit_data_file(fname2)
|
||||
|
||||
self.assertTrue(os.path.exists(self.GIT_IGNORE))
|
||||
|
||||
ignored = self.read_ignored()
|
||||
|
||||
self.assertEqual(len(ignored), 2) # FAILS!!!
|
||||
|
||||
self.assertIn(fname1, ignored)
|
||||
self.assertIn(fname2, ignored) # FAILS!!!
|
||||
|
||||
|
||||
class TestGitIgnoreWhenCheckout(CheckoutBase):
|
||||
def test(self):
|
||||
fname_master = 'file_in_a_master'
|
||||
branch_master = 'master'
|
||||
fname_branch = 'file_in_a_branch'
|
||||
branch_1 = 'b1'
|
||||
|
||||
self.dvc.scm.add(self.dvc.scm.untracked_files())
|
||||
self.dvc.scm.commit('add all files')
|
||||
self.commit_data_file(fname_master)
|
||||
|
||||
self.dvc.scm.checkout(branch_1, True)
|
||||
main(['checkout'])
|
||||
self.commit_data_file(fname_branch)
|
||||
|
||||
self.dvc.scm.checkout(branch_master)
|
||||
main(['checkout'])
|
||||
|
||||
ignored = self.read_ignored()
|
||||
|
||||
self.assertEqual(len(ignored), 1)
|
||||
self.assertIn(fname_master, ignored)
|
||||
|
||||
self.dvc.scm.checkout(branch_1)
|
||||
main(['checkout'])
|
||||
ignored = self.read_ignored()
|
||||
self.assertIn(fname_branch, ignored) # FAILS!!!
|
||||
|
||||
Reference in New Issue
Block a user