From 7990422eb49094434a8344584c293d523358a2ab Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sat, 25 Mar 2017 21:19:01 -0700 Subject: [PATCH] Data item class renaming --- dvc/cmd_base.py | 4 ++-- dvc/cmd_data_import.py | 28 ++++++++++++------------ dvc/cmd_data_remove.py | 38 ++++++++++++++++----------------- dvc/cmd_data_sync.py | 30 +++++++++++++------------- dvc/cmd_repro.py | 40 +++++++++++++++++------------------ dvc/cmd_run.py | 27 +++++++++++------------ dvc/git_wrapper.py | 2 +- dvc/path/data_item.py | 14 ++++++------ dvc/path/factory.py | 26 +++++++++++------------ dvc/path/path.py | 2 +- dvc/repository_change.py | 6 +++--- tests/basic_env.py | 6 +++--- tests/test_cmd_data_remove.py | 4 ++-- tests/test_data_file_obj.py | 32 ++++++++++++++-------------- tests/test_dvc_path.py | 10 ++++----- 15 files changed, 135 insertions(+), 134 deletions(-) diff --git a/dvc/cmd_base.py b/dvc/cmd_base.py index 80ed1c7f4..14f3b8fc6 100644 --- a/dvc/cmd_base.py +++ b/dvc/cmd_base.py @@ -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 diff --git a/dvc/cmd_data_import.py b/dvc/cmd_data_import.py index 83f8b9ab2..7bcc57673 100644 --- a/dvc/cmd_data_import.py +++ b/dvc/cmd_data_import.py @@ -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( diff --git a/dvc/cmd_data_remove.py b/dvc/cmd_data_remove.py index e91c11b79..a348ebf63 100644 --- a/dvc/cmd_data_remove.py +++ b/dvc/cmd_data_remove.py @@ -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) diff --git a/dvc/cmd_data_sync.py b/dvc/cmd_data_sync.py index b3ae26914..ce748662b 100644 --- a/dvc/cmd_data_sync.py +++ b/dvc/cmd_data_sync.py @@ -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 diff --git a/dvc/cmd_repro.py b/dvc/cmd_repro.py index 11cd580a9..96326e8e3 100644 --- a/dvc/cmd_repro.py +++ b/dvc/cmd_repro.py @@ -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() diff --git a/dvc/cmd_run.py b/dvc/cmd_run.py index 13c9032d8..ca817e44c 100644 --- a/dvc/cmd_run.py +++ b/dvc/cmd_run.py @@ -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 diff --git a/dvc/git_wrapper.py b/dvc/git_wrapper.py index 70b75aa5a..6f55492ee 100644 --- a/dvc/git_wrapper.py +++ b/dvc/git_wrapper.py @@ -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)) diff --git a/dvc/path/data_item.py b/dvc/path/data_item.py index a9710ad2a..cf369c3e4 100644 --- a/dvc/path/data_item.py +++ b/dvc/path/data_item.py @@ -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): diff --git a/dvc/path/factory.py b/dvc/path/factory.py index 5398f728f..d39e4b99e 100644 --- a/dvc/path/factory.py +++ b/dvc/path/factory.py @@ -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) diff --git a/dvc/path/path.py b/dvc/path/path.py index 9f297577d..21e0c049a 100644 --- a/dvc/path/path.py +++ b/dvc/path/path.py @@ -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) diff --git a/dvc/repository_change.py b/dvc/repository_change.py index b2d74ce56..23a03d252 100644 --- a/dvc/repository_change.py +++ b/dvc/repository_change.py @@ -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): diff --git a/tests/basic_env.py b/tests/basic_env.py index 3ef8c51ec..bb258ac69 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -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) diff --git a/tests/test_cmd_data_remove.py b/tests/test_cmd_data_remove.py index 75ae87b63..aec338ad4 100644 --- a/tests/test_cmd_data_remove.py +++ b/tests/test_cmd_data_remove.py @@ -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) diff --git a/tests/test_data_file_obj.py b/tests/test_data_file_obj.py index 573b8c427..e8c799feb 100644 --- a/tests/test_data_file_obj.py +++ b/tests/test_data_file_obj.py @@ -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 diff --git a/tests/test_dvc_path.py b/tests/test_dvc_path.py index b408d9766..0fe3b7bb8 100644 --- a/tests/test_dvc_path.py +++ b/tests/test_dvc_path.py @@ -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