mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
Data item class renaming
This commit is contained in:
+2
-2
@@ -106,5 +106,5 @@ class CmdBase(object):
|
||||
def get_cache_file_s3_name(self, cache_file):
|
||||
cache_prefix_file_name = os.path.relpath(os.path.realpath(cache_file), os.path.realpath(self.git.git_dir))
|
||||
file_name = os.path.relpath(cache_prefix_file_name, self.config.cache_dir)
|
||||
nlx_file_path_trim = file_name.replace(os.sep, '/').strip('/')
|
||||
return self.config.aws_storage_prefix + '/' + nlx_file_path_trim
|
||||
dvc_file_path_trim = file_name.replace(os.sep, '/').strip('/')
|
||||
return self.config.aws_storage_prefix + '/' + dvc_file_path_trim
|
||||
|
||||
+14
-14
@@ -71,40 +71,40 @@ class CmdDataImport(CmdBase):
|
||||
if os.path.isdir(output):
|
||||
output = os.path.join(output, os.path.basename(input))
|
||||
|
||||
data_path = self.path_factory.data_path(output)
|
||||
data_item = self.path_factory.data_item(output)
|
||||
|
||||
if os.path.exists(data_path.data.relative):
|
||||
raise DataImportError('Output file "{}" already exists'.format(data_path.data.relative))
|
||||
if not os.path.isdir(os.path.dirname(data_path.data.relative)):
|
||||
if os.path.exists(data_item.data.relative):
|
||||
raise DataImportError('Output file "{}" already exists'.format(data_item.data.relative))
|
||||
if not os.path.isdir(os.path.dirname(data_item.data.relative)):
|
||||
raise DataImportError('Output file directory "{}" does not exists'.format(
|
||||
os.path.dirname(data_path.data.relative)))
|
||||
os.path.dirname(data_item.data.relative)))
|
||||
|
||||
cache_dir = os.path.dirname(data_path.cache.relative)
|
||||
cache_dir = os.path.dirname(data_item.cache.relative)
|
||||
if not os.path.exists(cache_dir):
|
||||
os.makedirs(cache_dir)
|
||||
|
||||
if CmdDataImport.is_url(input):
|
||||
Logger.debug('Downloading file {} ...'.format(input))
|
||||
self.download_file(input, data_path.cache.relative)
|
||||
self.download_file(input, data_item.cache.relative)
|
||||
Logger.debug('Input file "{}" was downloaded to cache "{}"'.format(
|
||||
input, data_path.cache.relative))
|
||||
input, data_item.cache.relative))
|
||||
else:
|
||||
copyfile(input, data_path.cache.relative)
|
||||
copyfile(input, data_item.cache.relative)
|
||||
Logger.debug('Input file "{}" was copied to cache "{}"'.format(
|
||||
input, data_path.cache.relative))
|
||||
input, data_item.cache.relative))
|
||||
|
||||
data_path.create_symlink()
|
||||
data_item.create_symlink()
|
||||
Logger.debug('Symlink from data file "{}" to the cache file "{}" was created'.
|
||||
format(data_path.data.relative, data_path.cache.relative))
|
||||
format(data_item.data.relative, data_item.cache.relative))
|
||||
|
||||
state_file = StateFile(data_path.state.relative,
|
||||
state_file = StateFile(data_item.state.relative,
|
||||
self.git,
|
||||
[input],
|
||||
[output],
|
||||
[],
|
||||
is_reproducible)
|
||||
state_file.save()
|
||||
Logger.debug('State file "{}" was created'.format(data_path.state.relative))
|
||||
Logger.debug('State file "{}" was created'.format(data_item.state.relative))
|
||||
pass
|
||||
|
||||
URL_REGEX = re.compile(
|
||||
|
||||
+19
-19
@@ -71,8 +71,8 @@ class CmdDataRemove(CmdBase):
|
||||
if not self.args.recursive:
|
||||
raise DataRemoveError('Directory "%s" cannot be removed. Use --recurcive flag.' % target)
|
||||
|
||||
data_path = self.path_factory.data_path(target)
|
||||
if data_path.data_dvc_short == '':
|
||||
data_item = self.path_factory.data_item(target)
|
||||
if data_item.data_dvc_short == '':
|
||||
raise DataRemoveError('Data directory "%s" cannot be removed' % target)
|
||||
|
||||
return self.remove_dir_file_by_file(target)
|
||||
@@ -86,35 +86,35 @@ class CmdDataRemove(CmdBase):
|
||||
|
||||
def remove_data_instance(self, target):
|
||||
# it raises exception if not a symlink is provided
|
||||
data_path = self.path_factory.existing_data_path(target)
|
||||
data_item = self.path_factory.existing_data_item(target)
|
||||
|
||||
self._remove_cache_file(data_path)
|
||||
self._remove_state_file(data_path)
|
||||
self._remove_cloud_cache(data_path)
|
||||
self._remove_cache_file(data_item)
|
||||
self._remove_state_file(data_item)
|
||||
self._remove_cloud_cache(data_item)
|
||||
|
||||
os.remove(data_path.data.relative)
|
||||
os.remove(data_item.data.relative)
|
||||
pass
|
||||
|
||||
def _remove_cloud_cache(self, data_path):
|
||||
def _remove_cloud_cache(self, data_item):
|
||||
if not self.args.keep_in_cloud:
|
||||
aws_key = self.cache_file_aws_key(data_path.cache.dvc)
|
||||
aws_key = self.cache_file_aws_key(data_item.cache.dvc)
|
||||
self.remove_from_cloud(aws_key)
|
||||
|
||||
def _remove_state_file(self, data_path):
|
||||
if os.path.isfile(data_path.state.relative):
|
||||
os.remove(data_path.state.relative)
|
||||
self.remove_dir_if_empty(data_path.state.relative)
|
||||
def _remove_state_file(self, data_item):
|
||||
if os.path.isfile(data_item.state.relative):
|
||||
os.remove(data_item.state.relative)
|
||||
self.remove_dir_if_empty(data_item.state.relative)
|
||||
else:
|
||||
Logger.warn(u'State file {} for data instance {} does not exist'.format(
|
||||
data_path.state.relative, data_path.data.relative))
|
||||
data_item.state.relative, data_item.data.relative))
|
||||
|
||||
def _remove_cache_file(self, data_path):
|
||||
if not self.args.keep_in_cache and os.path.isfile(data_path.cache.relative):
|
||||
os.remove(data_path.cache.relative)
|
||||
self.remove_dir_if_empty(data_path.cache.relative)
|
||||
def _remove_cache_file(self, data_item):
|
||||
if not self.args.keep_in_cache and os.path.isfile(data_item.cache.relative):
|
||||
os.remove(data_item.cache.relative)
|
||||
self.remove_dir_if_empty(data_item.cache.relative)
|
||||
else:
|
||||
if not self.args.keep_in_cache:
|
||||
Logger.warn(u'Unable to find cache file for data instance %s' % data_path.data.relative)
|
||||
Logger.warn(u'Unable to find cache file for data instance %s' % data_item.data.relative)
|
||||
|
||||
def remove_from_cloud(self, aws_file_name):
|
||||
conn = S3Connection(self.config.aws_access_key_id, self.config.aws_secret_access_key)
|
||||
|
||||
+15
-15
@@ -53,8 +53,8 @@ class CmdDataSync(CmdBase):
|
||||
|
||||
def run(self):
|
||||
if os.path.islink(self.args.target):
|
||||
data_path = self.path_factory.existing_data_path(self.args.target)
|
||||
return self.sync_symlink(data_path)
|
||||
data_item = self.path_factory.existing_data_item(self.args.target)
|
||||
return self.sync_symlink(data_item)
|
||||
|
||||
if os.path.isdir(self.args.target):
|
||||
return self.sync_dir(self.args.target)
|
||||
@@ -67,48 +67,48 @@ class CmdDataSync(CmdBase):
|
||||
if os.path.isdir(fname):
|
||||
self.sync_dir(fname)
|
||||
elif os.path.islink(fname):
|
||||
self.sync_symlink(self.path_factory.existing_data_path(fname))
|
||||
self.sync_symlink(self.path_factory.existing_data_item(fname))
|
||||
else:
|
||||
raise DataSyncError('Unsupported file type "{}"'.format(fname))
|
||||
pass
|
||||
|
||||
def sync_symlink(self, data_path):
|
||||
if os.path.isfile(data_path.cache.relative):
|
||||
self.sync_to_cloud(data_path)
|
||||
def sync_symlink(self, data_item):
|
||||
if os.path.isfile(data_item.cache.relative):
|
||||
self.sync_to_cloud(data_item)
|
||||
else:
|
||||
self.sync_from_cloud(data_path)
|
||||
self.sync_from_cloud(data_item)
|
||||
pass
|
||||
|
||||
def sync_from_cloud(self, data_path):
|
||||
aws_key = self.cache_file_aws_key(data_path.cache.dvc)
|
||||
def sync_from_cloud(self, item):
|
||||
aws_key = self.cache_file_aws_key(item.cache.dvc)
|
||||
key = self._bucket.get_key(aws_key)
|
||||
if not key:
|
||||
raise DataSyncError('File "{}" does not exist in the cloud'.format(aws_key))
|
||||
|
||||
Logger.printing('Downloading cache file from S3 "{}/{}"'.format(self._bucket.name,
|
||||
aws_key))
|
||||
key.get_contents_to_filename(data_path.cache.relative, cb=percent_cb)
|
||||
key.get_contents_to_filename(item.cache.relative, cb=percent_cb)
|
||||
Logger.printing('Downloading completed')
|
||||
pass
|
||||
|
||||
def sync_to_cloud(self, data_path):
|
||||
aws_key = self.cache_file_aws_key(data_path.cache.dvc)
|
||||
def sync_to_cloud(self, data_item):
|
||||
aws_key = self.cache_file_aws_key(data_item.cache.dvc)
|
||||
key = self._bucket.get_key(aws_key)
|
||||
if key:
|
||||
Logger.debug('File already uploaded to the cloud. Checksum validation...')
|
||||
|
||||
md5_cloud = key.etag[1:-1]
|
||||
md5_local = file_md5(data_path.cache.relative)
|
||||
md5_local = file_md5(data_item.cache.relative)
|
||||
if md5_cloud == md5_local:
|
||||
Logger.debug('File checksum matches. No uploading is needed.')
|
||||
return
|
||||
|
||||
Logger.printing('Checksum miss-match. Re-uploading is required.')
|
||||
|
||||
Logger.printing('Uploading cache file "{}" to S3 "{}"'.format(data_path.cache.relative,
|
||||
Logger.printing('Uploading cache file "{}" to S3 "{}"'.format(data_item.cache.relative,
|
||||
aws_key))
|
||||
key = self._bucket.new_key(aws_key)
|
||||
key.set_contents_from_filename(data_path.cache.relative, cb=percent_cb)
|
||||
key.set_contents_from_filename(data_item.cache.relative, cb=percent_cb)
|
||||
Logger.printing('Uploading completed')
|
||||
pass
|
||||
|
||||
|
||||
+20
-20
@@ -55,29 +55,29 @@ class CmdRepro(CmdRun):
|
||||
if not self.skip_git_actions and not self.git.is_ready_to_go():
|
||||
return 1
|
||||
|
||||
data_path_list, external_files = self.path_factory.to_data_path(self.args.target)
|
||||
if external_files:
|
||||
data_item_list, external_files_names = self.path_factory.to_data_items(self.args.target)
|
||||
if external_files_names:
|
||||
Logger.error('Files from outside of the data directory "{}" could not be reproduced: {}'.
|
||||
format(self.config.data_dir, ' '.join(external_files)))
|
||||
format(self.config.data_dir, ' '.join(external_files_names)))
|
||||
return 1
|
||||
|
||||
error = False
|
||||
changed = False
|
||||
for data_path in data_path_list:
|
||||
for data_item in data_item_list:
|
||||
try:
|
||||
repro_change = ReproChange(data_path, self)
|
||||
repro_change = ReproChange(data_item, self)
|
||||
if repro_change.reproduce():
|
||||
changed = True
|
||||
Logger.info(u'Data file "{}" was reproduced.'.format(
|
||||
data_path.data.relative
|
||||
data_item.data.relative
|
||||
))
|
||||
else:
|
||||
Logger.info(u'Reproduction is not required for data file "{}".'.format(
|
||||
data_path.data.relative
|
||||
data_item.data.relative
|
||||
))
|
||||
except ReproError as err:
|
||||
Logger.error('Error in reproducing data file {}: {}'.format(
|
||||
data_path.data.relative, str(err)
|
||||
data_item.data.relative, str(err)
|
||||
))
|
||||
error = True
|
||||
break
|
||||
@@ -100,11 +100,11 @@ class CmdRepro(CmdRun):
|
||||
|
||||
|
||||
class ReproChange(object):
|
||||
def __init__(self, data_path, cmd_obj):
|
||||
self._data_path = data_path
|
||||
def __init__(self, data_item, cmd_obj):
|
||||
self._data_item = data_item
|
||||
self.git = cmd_obj.git
|
||||
self._cmd_obj = cmd_obj
|
||||
self._state = StateFile.load(data_path.state.relative, self.git)
|
||||
self._state = StateFile.load(data_item.state.relative, self.git)
|
||||
|
||||
cmd_obj._code = self._state.code_sources # HACK!!!
|
||||
|
||||
@@ -112,7 +112,7 @@ class ReproChange(object):
|
||||
|
||||
if not argv:
|
||||
raise ReproError('Error: parameter {} is nor defined in state file "{}"'.
|
||||
format(StateFile.PARAM_NORM_ARGV, data_path.state.relative))
|
||||
format(StateFile.PARAM_NORM_ARGV, data_item.state.relative))
|
||||
if len(argv) < 2:
|
||||
raise ReproError('Error: reproducible command in state file "{}" is too short'.
|
||||
format(self._state.file))
|
||||
@@ -129,39 +129,39 @@ class ReproChange(object):
|
||||
|
||||
def reproduce_data_file(self):
|
||||
Logger.debug('Reproducing data file "{}". Removing the file...'.format(
|
||||
self._data_path.data.relative))
|
||||
os.remove(self._data_path.data.relative)
|
||||
self._data_item.data.relative))
|
||||
os.remove(self._data_item.data.relative)
|
||||
|
||||
Logger.debug('Reproducing data file "{}". Re-runs command: {}'.format(
|
||||
self._data_path.data.relative, ' '.join(self._repro_argv)))
|
||||
self._data_item.data.relative, ' '.join(self._repro_argv)))
|
||||
return self._cmd_obj.run_command(self._repro_argv)
|
||||
|
||||
def reproduce(self, force=False):
|
||||
were_input_files_changed = False
|
||||
|
||||
if not self._state.is_reproducible:
|
||||
Logger.debug('Data file "{}" is not reproducible'.format(self._data_path.data.relative))
|
||||
Logger.debug('Data file "{}" is not reproducible'.format(self._data_item.data.relative))
|
||||
return False
|
||||
|
||||
for input_file in self._state.input_files:
|
||||
try:
|
||||
data_path = self._cmd_obj.path_factory.data_path(input_file)
|
||||
data_item = self._cmd_obj.path_factory.data_item(input_file)
|
||||
except NotInDataDirError:
|
||||
raise ReproError(u'The dependency files "{}" is not a data file'.format(input_file))
|
||||
except Exception as ex:
|
||||
raise ReproError(u'The dependency files "{}" can not be reproduced: {}'.format(
|
||||
input_file, ex))
|
||||
|
||||
change = ReproChange(data_path, self._cmd_obj)
|
||||
change = ReproChange(data_item, self._cmd_obj)
|
||||
if change.reproduce(force):
|
||||
were_input_files_changed = True
|
||||
|
||||
was_source_code_changed = self.git.were_files_changed(self._data_path.data.relative,
|
||||
was_source_code_changed = self.git.were_files_changed(self._data_item.data.relative,
|
||||
self._state.code_sources)
|
||||
|
||||
if not force and not was_source_code_changed and not were_input_files_changed:
|
||||
Logger.debug('Data file "{}" is up to date'.format(
|
||||
self._data_path.data.relative))
|
||||
self._data_item.data.relative))
|
||||
return False
|
||||
|
||||
return self.reproduce_data_file()
|
||||
|
||||
+14
-13
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import fasteners
|
||||
|
||||
@@ -90,28 +91,28 @@ class CmdRun(CmdBase):
|
||||
self.remove_new_files(repo_change)
|
||||
return False
|
||||
|
||||
changed_files_nlx = self.git.abs_paths_to_nlx(repo_change.changed_files)
|
||||
output_files = changed_files_nlx + self.git.abs_paths_to_nlx(self.declaration_output_files)
|
||||
args_files_nlx = self.git.abs_paths_to_nlx(self.get_data_files_from_args(argv))
|
||||
changed_files_nlx = self.git.abs_paths_to_dvc(repo_change.changed_files)
|
||||
output_files = changed_files_nlx + self.git.abs_paths_to_dvc(self.declaration_output_files)
|
||||
args_files_nlx = self.git.abs_paths_to_dvc(self.get_data_files_from_args(argv))
|
||||
|
||||
input_files_from_args = list(set(args_files_nlx) - set(changed_files_nlx))
|
||||
input_files = self.git.abs_paths_to_nlx(input_files_from_args + self.declaration_input_files)
|
||||
input_files = self.git.abs_paths_to_dvc(input_files_from_args + self.declaration_input_files)
|
||||
|
||||
for data_path in repo_change.data_paths_for_changed_files:
|
||||
dirname = os.path.dirname(data_path.cache.relative)
|
||||
for data_item in repo_change.data_items_for_changed_files:
|
||||
dirname = os.path.dirname(data_item.cache.relative)
|
||||
if not os.path.isdir(dirname):
|
||||
os.makedirs(dirname)
|
||||
|
||||
Logger.debug('Move output file "{}" to cache dir "{}" and create a symlink'.format(
|
||||
data_path.data.relative, data_path.cache.relative))
|
||||
shutil.move(data_path.data.relative, data_path.cache.relative)
|
||||
data_item.data.relative, data_item.cache.relative))
|
||||
shutil.move(data_item.data.relative, data_item.cache.relative)
|
||||
|
||||
data_path.create_symlink()
|
||||
data_item.create_symlink()
|
||||
|
||||
nlx_code_sources = map(lambda x: self.git.abs_paths_to_nlx([x])[0], self.code)
|
||||
nlx_code_sources = map(lambda x: self.git.abs_paths_to_dvc([x])[0], self.code)
|
||||
|
||||
Logger.debug('Create state file "{}"'.format(data_path.state.relative))
|
||||
state_file = StateFile(data_path.state.relative, self.git,
|
||||
Logger.debug('Create state file "{}"'.format(data_item.state.relative))
|
||||
state_file = StateFile(data_item.state.relative, self.git,
|
||||
input_files,
|
||||
output_files,
|
||||
nlx_code_sources,
|
||||
@@ -166,7 +167,7 @@ class CmdRun(CmdBase):
|
||||
for arg in argv:
|
||||
try:
|
||||
if os.path.isfile(arg):
|
||||
self.path_factory.data_path(arg)
|
||||
self.path_factory.data_item(arg)
|
||||
result.append(arg)
|
||||
except NotInDataDirError:
|
||||
pass
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ class GitWrapper(GitWrapperI):
|
||||
|
||||
return result
|
||||
|
||||
def abs_paths_to_nlx(self, files):
|
||||
def abs_paths_to_dvc(self, files):
|
||||
result = []
|
||||
for file in files:
|
||||
result.append(os.path.relpath(os.path.abspath(file), self.git_dir_abs))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import os
|
||||
|
||||
from dvc.path.path import DvcPath
|
||||
from dvc.path.path import Path
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.utils import cached_property
|
||||
|
||||
|
||||
class DataFilePathError(DvcException):
|
||||
class DataItemError(DvcException):
|
||||
def __init__(self, msg):
|
||||
DvcException.__init__(self, 'Data file error: {}'.format(msg))
|
||||
|
||||
@@ -17,7 +17,7 @@ class NotInDataDirError(DvcException):
|
||||
format(file, data_dir))
|
||||
|
||||
|
||||
class DataPath(object):
|
||||
class DataItem(object):
|
||||
STATE_FILE_SUFFIX = '.state'
|
||||
CACHE_FILE_SEP = '_'
|
||||
|
||||
@@ -26,7 +26,7 @@ class DataPath(object):
|
||||
self._config = config
|
||||
self._cache_file = cache_file
|
||||
|
||||
self._data = DvcPath(data_file, git)
|
||||
self._data = Path(data_file, git)
|
||||
if not self._data.abs.startswith(self.data_dir_abs):
|
||||
raise NotInDataDirError(data_file, self._config.data_dir)
|
||||
|
||||
@@ -46,17 +46,17 @@ class DataPath(object):
|
||||
def state(self):
|
||||
state_dir = os.path.join(self._git.git_dir_abs, self._config.state_dir)
|
||||
state_file = os.path.join(state_dir, self.data_dvc_short + self.STATE_FILE_SUFFIX)
|
||||
return DvcPath(state_file, self._git)
|
||||
return Path(state_file, self._git)
|
||||
|
||||
@cached_property
|
||||
def cache(self):
|
||||
if self._cache_file:
|
||||
return DvcPath(self._cache_file, self._git)
|
||||
return Path(self._cache_file, self._git)
|
||||
else:
|
||||
cache_dir = os.path.join(self._git.git_dir_abs, self._config.cache_dir)
|
||||
cache_file_suffix = self.CACHE_FILE_SEP + self._git.curr_commit
|
||||
cache_file = os.path.join(cache_dir, self.data_dvc_short + cache_file_suffix)
|
||||
return DvcPath(cache_file, self._git)
|
||||
return Path(cache_file, self._git)
|
||||
|
||||
@cached_property
|
||||
def data_dir_abs(self):
|
||||
|
||||
+13
-13
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
from dvc.path.data_item import DataPath, DataFilePathError, NotInDataDirError
|
||||
from dvc.path.path import DvcPath
|
||||
from dvc.path.data_item import DataItem, DataItemError, NotInDataDirError
|
||||
from dvc.path.path import Path
|
||||
|
||||
|
||||
class PathFactory(object):
|
||||
@@ -11,25 +11,25 @@ class PathFactory(object):
|
||||
self._curr_dir_abs = os.path.realpath(os.curdir)
|
||||
|
||||
def path(self, relative_raw):
|
||||
return DvcPath(relative_raw, self._git)
|
||||
return Path(relative_raw, self._git)
|
||||
|
||||
def data_path(self, data_file):
|
||||
return DataPath(data_file, self._git, self._config)
|
||||
def data_item(self, data_file):
|
||||
return DataItem(data_file, self._git, self._config)
|
||||
|
||||
def existing_data_path(self, data_file):
|
||||
if not os.path.islink(data_file):
|
||||
raise DataFilePathError(u'Data file "%s" must be a symbolic link' % data_file)
|
||||
resolved_symlink = os.path.realpath(data_file)
|
||||
return DataPath(data_file, self._git, self._config, resolved_symlink)
|
||||
def existing_data_item(self, file):
|
||||
if not os.path.islink(file):
|
||||
raise DataItemError(u'Data file "%s" must be a symbolic link' % file)
|
||||
resolved_symlink = os.path.realpath(file)
|
||||
return DataItem(file, self._git, self._config, resolved_symlink)
|
||||
|
||||
def to_data_path(self, files):
|
||||
def to_data_items(self, files):
|
||||
result = []
|
||||
externally_created_files = []
|
||||
|
||||
for file in files:
|
||||
try:
|
||||
data_path = DataPath(file, self._git, self._config)
|
||||
result.append(data_path)
|
||||
data_item = DataItem(file, self._git, self._config)
|
||||
result.append(data_item)
|
||||
except NotInDataDirError:
|
||||
externally_created_files.append(file)
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
|
||||
class DvcPath(object):
|
||||
class Path(object):
|
||||
def __init__(self, relative_raw, git):
|
||||
self._abs = os.path.abspath(relative_raw)
|
||||
self._dvc = os.path.relpath(self.abs, git.git_dir_abs)
|
||||
|
||||
@@ -51,7 +51,7 @@ class RepositoryChange(object):
|
||||
GitWrapper.exec_cmd_only_success(args, stdout, stderr)
|
||||
self._file_states = self._get_file_states()
|
||||
|
||||
self._changed_data_paths, self._externally_created_files = path_factory.to_data_path(self.changed_files)
|
||||
self._changed_data_items, self._externally_created_files = path_factory.to_data_items(self.changed_files)
|
||||
|
||||
@staticmethod
|
||||
def exec_cmd(args, stdout, stderr, git, path_factory):
|
||||
@@ -112,8 +112,8 @@ class RepositoryChange(object):
|
||||
pass
|
||||
|
||||
@property
|
||||
def data_paths_for_changed_files(self):
|
||||
return self._changed_data_paths
|
||||
def data_items_for_changed_files(self):
|
||||
return self._changed_data_items
|
||||
|
||||
@property
|
||||
def externally_created_files(self):
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ from unittest import TestCase
|
||||
|
||||
from dvc.config import ConfigI
|
||||
from dvc.git_wrapper import GitWrapperI, GitWrapper
|
||||
from dvc.path.data_item import DataPath
|
||||
from dvc.path.data_item import DataItem
|
||||
from dvc.path.factory import PathFactory
|
||||
|
||||
|
||||
@@ -98,12 +98,12 @@ class DirHierarchyEnvironment(BasicEnvironment):
|
||||
|
||||
def crate_data_item(self, data_file, cache_file=True, content='random text'):
|
||||
file_result = os.path.join('data', data_file)
|
||||
state_result = os.path.join('state', data_file + DataPath.STATE_FILE_SUFFIX)
|
||||
state_result = os.path.join('state', data_file + DataItem.STATE_FILE_SUFFIX)
|
||||
|
||||
self.create_content_file(state_result, 'state content')
|
||||
|
||||
if cache_file:
|
||||
cache_result = os.path.join('cache', data_file + DataPath.CACHE_FILE_SEP + self._commit)
|
||||
cache_result = os.path.join('cache', data_file + DataItem.CACHE_FILE_SEP + self._commit)
|
||||
self.create_content_file(cache_result, content)
|
||||
|
||||
relevant_dir = self.relevant_dir(data_file)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
from dvc.cmd_data_remove import CmdDataRemove, DataRemoveError
|
||||
from dvc.path.data_item import DataFilePathError
|
||||
from dvc.path.data_item import DataItemError
|
||||
from tests.basic_env import DirHierarchyEnvironment
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class TestRemoveDataItem(DirHierarchyEnvironment):
|
||||
self.assertIsNone(self.cache6)
|
||||
self.assertTrue(os.path.isfile(self.state6))
|
||||
|
||||
with self.assertRaises(DataFilePathError):
|
||||
with self.assertRaises(DataItemError):
|
||||
cmd.remove_data_instance(self.file6)
|
||||
|
||||
|
||||
|
||||
+16
-16
@@ -2,7 +2,7 @@ import os
|
||||
|
||||
from dvc.config import ConfigI
|
||||
from dvc.git_wrapper import GitWrapperI
|
||||
from dvc.path.data_item import NotInDataDirError, DataFilePathError, DataPath
|
||||
from dvc.path.data_item import NotInDataDirError, DataItemError, DataItem
|
||||
from dvc.path.factory import PathFactory
|
||||
from tests.basic_env import BasicEnvironment
|
||||
|
||||
@@ -15,7 +15,7 @@ class TestDataFileObjBasic(BasicEnvironment):
|
||||
config = ConfigI('data', 'cache', 'state')
|
||||
|
||||
file = os.path.join('data', 'file.txt')
|
||||
self._data_path = DataPath(file, git, config)
|
||||
self._data_path = DataItem(file, git, config)
|
||||
pass
|
||||
|
||||
def test_data_file(self):
|
||||
@@ -56,27 +56,27 @@ class TestPathFactory(BasicEnvironment):
|
||||
pass
|
||||
|
||||
def test_data_file_factory(self):
|
||||
data_path = self.path_factory.data_path(self.file)
|
||||
data_path = self.path_factory.data_item(self.file)
|
||||
self.assertEqual(data_path.data.dvc, self.file)
|
||||
|
||||
indirect_file_path = os.path.join('..', self._proj_dir, self.file)
|
||||
data_path_indirect = self.path_factory.data_path(indirect_file_path)
|
||||
data_path_indirect = self.path_factory.data_item(indirect_file_path)
|
||||
self.assertEqual(data_path_indirect.data.dvc, self.file)
|
||||
pass
|
||||
|
||||
def test_data_symlink_factory(self):
|
||||
data_path = self.path_factory.existing_data_path(self.file_symlink)
|
||||
data_path = self.path_factory.existing_data_item(self.file_symlink)
|
||||
self.assertEqual(data_path.data.dvc, self.file_symlink)
|
||||
pass
|
||||
|
||||
def test_data_symlink_factory_cache(self):
|
||||
data_path = self.path_factory.existing_data_path(self.file_symlink)
|
||||
data_path = self.path_factory.existing_data_item(self.file_symlink)
|
||||
self.assertEqual(data_path.cache.dvc, self.file)
|
||||
pass
|
||||
|
||||
def test_data_symlink_factory_exception(self):
|
||||
with self.assertRaises(DataFilePathError):
|
||||
self.path_factory.existing_data_path(self.file)
|
||||
with self.assertRaises(DataItemError):
|
||||
self.path_factory.existing_data_item(self.file)
|
||||
pass
|
||||
|
||||
def test_data_path(self):
|
||||
@@ -96,7 +96,7 @@ class TestPathFactory(BasicEnvironment):
|
||||
data_path_file2
|
||||
]
|
||||
|
||||
data_path_list, exclude_file_list = self.path_factory.to_data_path(files)
|
||||
data_path_list, exclude_file_list = self.path_factory.to_data_items(files)
|
||||
|
||||
self.assertEqual(len(data_path_list), 2)
|
||||
self.assertEqual(len(exclude_file_list), 1)
|
||||
@@ -116,7 +116,7 @@ class TestDataPathInDataDir(BasicEnvironment):
|
||||
self.path_factory = PathFactory(git, config)
|
||||
|
||||
deep_path = os.path.join(self.data_dir, 'dir1', 'd2', 'file.txt')
|
||||
self.data_path = self.path_factory.data_path(deep_path)
|
||||
self.data_path = self.path_factory.data_item(deep_path)
|
||||
pass
|
||||
|
||||
def test_data_file(self):
|
||||
@@ -135,7 +135,7 @@ class TestDataPathInDataDir(BasicEnvironment):
|
||||
self.assertEqual(self.data_path._symlink_file, '../../../ca/dir1/d2/file.txt_eeeff8f')
|
||||
|
||||
def test_data_dir(self):
|
||||
data_path = self.path_factory.data_path(self.data_dir)
|
||||
data_path = self.path_factory.data_item(self.data_dir)
|
||||
self.assertEqual(data_path.data.dvc, self.data_dir)
|
||||
self.assertEqual(data_path.data_dvc_short, '')
|
||||
|
||||
@@ -154,7 +154,7 @@ class TestDataFileObjLongPath(BasicEnvironment):
|
||||
|
||||
# self._dobj = DataFileObj(os.path.join('..', '..', 'data', 'file1.txt'),
|
||||
# self._git, self._config)
|
||||
self.data_path = self.path_factory.data_path(os.path.join('..', '..', 'data', 'file1.txt'))
|
||||
self.data_path = self.path_factory.data_item(os.path.join('..', '..', 'data', 'file1.txt'))
|
||||
pass
|
||||
|
||||
def test_data_file(self):
|
||||
@@ -171,17 +171,17 @@ class TestDataFileObjLongPath(BasicEnvironment):
|
||||
|
||||
def test_file_name_only(self):
|
||||
with self.assertRaises(NotInDataDirError):
|
||||
self.path_factory.data_path('file.txt')
|
||||
self.path_factory.data_item('file.txt')
|
||||
pass
|
||||
|
||||
def test_relative_git_dir(self):
|
||||
with self.assertRaises(NotInDataDirError):
|
||||
self.path_factory.data_path('data/file.txt')
|
||||
self.path_factory.data_item('data/file.txt')
|
||||
pass
|
||||
|
||||
def test_relative_path_error(self):
|
||||
with self.assertRaises(NotInDataDirError):
|
||||
self.path_factory.data_path('../data/file.txt')
|
||||
self.path_factory.data_item('../data/file.txt')
|
||||
pass
|
||||
|
||||
|
||||
@@ -199,5 +199,5 @@ class RunOutsideGitRepoTest(BasicEnvironment):
|
||||
path_factory = PathFactory(git, config)
|
||||
|
||||
with self.assertRaises(NotInDataDirError):
|
||||
path_factory.data_path('file.txt')
|
||||
path_factory.data_item('file.txt')
|
||||
pass
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import shutil
|
||||
from unittest import TestCase
|
||||
|
||||
from dvc.path.path import DvcPath
|
||||
from dvc.path.path import Path
|
||||
from dvc.git_wrapper import GitWrapperI
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class TestDvcPathTest(TestCase):
|
||||
os.chdir(self.test_dir)
|
||||
|
||||
file = os.path.join('data', 'file.txt')
|
||||
path = DvcPath(file, self._git)
|
||||
path = Path(file, self._git)
|
||||
self._validate_dvc_path(path, file, file)
|
||||
pass
|
||||
|
||||
@@ -37,7 +37,7 @@ class TestDvcPathTest(TestCase):
|
||||
file_dvc_path = os.path.join('data', 'file1.txt')
|
||||
file_relative_path = os.path.join('..', file_dvc_path)
|
||||
|
||||
path = DvcPath(file_relative_path, self._git)
|
||||
path = Path(file_relative_path, self._git)
|
||||
self._validate_dvc_path(path, file_dvc_path, file_relative_path)
|
||||
pass
|
||||
|
||||
@@ -48,7 +48,7 @@ class TestDvcPathTest(TestCase):
|
||||
file_dvc = os.path.join('code', 'lib', 'context_switcher_structs.asm')
|
||||
file_relative = os.path.join('..', '..', '..', file_dvc)
|
||||
|
||||
path = DvcPath(file_relative, self._git)
|
||||
path = Path(file_relative, self._git)
|
||||
self._validate_dvc_path(path, file_dvc, file_relative)
|
||||
pass
|
||||
|
||||
@@ -59,6 +59,6 @@ class TestDvcPathTest(TestCase):
|
||||
file_relative_path = os.path.join(deep_dir, 'd4', 'dir5', 'rawdata.tsv')
|
||||
file_dvc_path = os.path.join(deep_dir, file_relative_path)
|
||||
|
||||
path = DvcPath(file_relative_path, self._git)
|
||||
path = Path(file_relative_path, self._git)
|
||||
self._validate_dvc_path(path, file_dvc_path, file_relative_path)
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user