From a1ad59ed03c7ecd82de055da41bdc1a113386eb9 Mon Sep 17 00:00:00 2001 From: joshua postel Date: Wed, 21 Aug 2019 12:49:17 -0400 Subject: [PATCH 01/37] ssh: add minimal support for gss_auth Fixes #2327 --- dvc/config.py | 2 ++ dvc/remote/ssh/__init__.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dvc/config.py b/dvc/config.py index 87311842f..c7925aec2 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -253,6 +253,7 @@ class Config(object): # pylint: disable=too-many-instance-attributes SECTION_REMOTE_TIMEOUT = "timeout" SECTION_REMOTE_PASSWORD = "password" SECTION_REMOTE_ASK_PASSWORD = "ask_password" + SECTION_REMOTE_GSS_AUTH = "gss_auth" SECTION_REMOTE_NO_TRAVERSE = "no_traverse" SECTION_REMOTE_SCHEMA = { SECTION_REMOTE_URL: str, @@ -273,6 +274,7 @@ class Config(object): # pylint: disable=too-many-instance-attributes Optional(SECTION_REMOTE_TIMEOUT): Use(int), Optional(SECTION_REMOTE_PASSWORD): str, Optional(SECTION_REMOTE_ASK_PASSWORD): BOOL_SCHEMA, + Optional(SECTION_REMOTE_GSS_AUTH): BOOL_SCHEMA, Optional(SECTION_AZURE_CONNECTION_STRING): str, Optional(SECTION_OSS_ACCESS_KEY_ID): str, Optional(SECTION_OSS_ACCESS_KEY_SECRET): str, diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index 086a2fd71..d6f034fd4 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -87,6 +87,7 @@ class RemoteSSH(RemoteBASE): self.ask_password = config.get( Config.SECTION_REMOTE_ASK_PASSWORD, False ) + self.gss_auth = config.get(Config.SECTION_REMOTE_GSS_AUTH, False) @staticmethod def ssh_config_filename(): @@ -145,6 +146,7 @@ class RemoteSSH(RemoteBASE): key_filename=self.keyfile, timeout=self.timeout, password=self.password, + gss_auth=self.gss_auth, ) def exists(self, path_info): From cc87531df3e8534d82be17c76c455f402176701a Mon Sep 17 00:00:00 2001 From: joshua postel Date: Wed, 21 Aug 2019 13:20:38 -0400 Subject: [PATCH 02/37] tests: added test for ssh gss_auth Fixes #2327 --- tests/unit/remote/ssh/test_ssh.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unit/remote/ssh/test_ssh.py b/tests/unit/remote/ssh/test_ssh.py index b48bf082c..0dee1ac3e 100644 --- a/tests/unit/remote/ssh/test_ssh.py +++ b/tests/unit/remote/ssh/test_ssh.py @@ -160,3 +160,25 @@ def test_ssh_keyfile(mock_file, mock_exists, config, expected_keyfile): mock_exists.assert_called_with(RemoteSSH.ssh_config_filename()) mock_file.assert_called_with(RemoteSSH.ssh_config_filename()) assert remote.keyfile == expected_keyfile + + +@pytest.mark.parametrize( + "config,expected_gss_auth", + [ + ({"url": "ssh://example.com", "gss_auth": True}, True), + ({"url": "ssh://example.com", "gss_auth": False}, False), + ({"url": "ssh://not_in_ssh_config.com"}, False), + ], +) +@patch("os.path.exists", return_value=True) +@patch( + "{}.open".format(builtin_module_name), + new_callable=mock_open, + read_data=mock_ssh_config, +) +def test_ssh_gss_auth(mock_file, mock_exists, config, expected_gss_auth): + remote = RemoteSSH(None, config) + + mock_exists.assert_called_with(RemoteSSH.ssh_config_filename()) + mock_file.assert_called_with(RemoteSSH.ssh_config_filename()) + assert remote.gss_auth == expected_gss_auth From cbc5e1b52d3cddc14e9b80550fbf05e2b9933405 Mon Sep 17 00:00:00 2001 From: joshua postel Date: Wed, 21 Aug 2019 14:10:53 -0400 Subject: [PATCH 03/37] setup.py: add gssapi requirement Fixes #2327 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e98ef6be8..0edd7e972 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ gs = ["google-cloud-storage==1.13.0"] s3 = ["boto3==1.9.115"] azure = ["azure-storage-blob==2.1.0"] oss = ["oss2==2.6.1"] -ssh = ["paramiko>=2.5.0"] +ssh = ["paramiko[gssapi]>=2.5.0"] hdfs = ["pyarrow==0.14.0"] all_remotes = gs + s3 + azure + ssh + oss From 41351a2df2f36ed04846d5e3d976d6d99b71a151 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 22 Aug 2019 01:51:57 +0300 Subject: [PATCH 04/37] dvc: bump to 0.57.0 --- dvc/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/version.py b/dvc/version.py index 216d6bbed..5433dbd22 100644 --- a/dvc/version.py +++ b/dvc/version.py @@ -7,7 +7,7 @@ import os import subprocess -_BASE_VERSION = "0.56.0" +_BASE_VERSION = "0.57.0" def _generate_version(base_version): From 208b181f9f651693ba5b474a5e9147d71450eb7e Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 22 Aug 2019 04:28:49 +0300 Subject: [PATCH 05/37] readme: add conda-forge badge --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 52ca32a71..9ec3a9833 100644 --- a/README.rst +++ b/README.rst @@ -26,6 +26,9 @@ :target: https://www.patreon.com/DVCorg/overview :alt: Donate +.. image:: https://anaconda.org/conda-forge/dvc/badges/version.svg + :target: https://anaconda.org/conda-forge/dvc + :alt: Conda-forge | **Data Version Control** or **DVC** is an **open-source** tool for data science and machine From 86c3cb785cdfc893eb09b46450217bbb56730de5 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 22 Aug 2019 04:30:44 +0300 Subject: [PATCH 06/37] readme: fix formatting --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 9ec3a9833..5b85e4eda 100644 --- a/README.rst +++ b/README.rst @@ -29,6 +29,7 @@ .. image:: https://anaconda.org/conda-forge/dvc/badges/version.svg :target: https://anaconda.org/conda-forge/dvc :alt: Conda-forge + | **Data Version Control** or **DVC** is an **open-source** tool for data science and machine From 8984e9fed49671e7f8831fcd20f908f9ff82266d Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Thu, 22 Aug 2019 18:41:46 +0700 Subject: [PATCH 07/37] dvc: use wdir == "." on add Fixes #2404 --- dvc/stage.py | 19 ++++++++++++++----- tests/func/test_add.py | 20 +++++++++++--------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/dvc/stage.py b/dvc/stage.py index 373de499e..f91aff25d 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -9,6 +9,7 @@ import subprocess import logging import signal import threading +from itertools import chain from dvc.utils import relpath from dvc.utils.compat import pathlib @@ -438,6 +439,7 @@ class Stage(object): wdir = kwargs.get("wdir", None) cwd = kwargs.get("cwd", None) fname = kwargs.get("fname", None) + add = kwargs.get("add", False) # Backward compatibility for `cwd` option if wdir is None and cwd is not None: @@ -449,8 +451,8 @@ class Stage(object): " directory.".format(fname=fname) ) wdir = cwd - else: - wdir = os.curdir if wdir is None else wdir + elif wdir is None: + wdir = os.curdir stage = Stage( repo=repo, @@ -468,11 +470,18 @@ class Stage(object): stage._check_duplicated_arguments() if not fname: - fname = Stage._stage_fname( - stage.outs, add=kwargs.get("add", False) - ) + fname = Stage._stage_fname(stage.outs, add) stage._check_dvc_filename(fname) + # Autodetecting wdir for add, we need to create outs first to do that, + # so we start with wdir = . and remap out paths later. + if add and kwargs.get("wdir") is None and cwd is None: + wdir = os.path.dirname(fname) + + for out in chain(stage.outs, stage.deps): + if out.is_in_repo: + out.def_path = relpath(out.path_info, wdir) + wdir = os.path.abspath(wdir) if cwd is not None: diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 2c1aa2927..a9c52185c 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -169,15 +169,17 @@ class TestAddModifiedDir(TestDvc): self.assertTrue(stages[0] is not None) -class TestAddFileInDir(TestDvc): - def test(self): - stages = self.dvc.add(self.DATA_SUB) - self.assertEqual(len(stages), 1) - stage = stages[0] - self.assertNotEqual(stage, None) - self.assertEqual(len(stage.deps), 0) - self.assertEqual(len(stage.outs), 1) - self.assertEqual(stage.relpath, self.DATA_SUB + ".dvc") +def test_add_file_in_dir(repo_dir, dvc_repo): + stage, = dvc_repo.add(repo_dir.DATA_SUB) + + assert stage is not None + assert len(stage.deps) == 0 + assert len(stage.outs) == 1 + assert stage.relpath == repo_dir.DATA_SUB + ".dvc" + + # Current dir should not be taken into account + assert stage.wdir == os.path.dirname(stage.path) + assert stage.outs[0].def_path == "data_sub" class TestAddExternalLocalFile(TestDvc): From 096a043e21e992b5b0251162d9a167c26b0d1350 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 22 Aug 2019 22:57:51 +0300 Subject: [PATCH 08/37] dvc: don't include gssapi If user needs it, he can install it by himself through pip. https://github.com/iterative/dvc/pull/2424#issuecomment-523990535 https://github.com/iterative/dvc.org/pull/582 --- setup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0edd7e972..94c3b5153 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,12 @@ gs = ["google-cloud-storage==1.13.0"] s3 = ["boto3==1.9.115"] azure = ["azure-storage-blob==2.1.0"] oss = ["oss2==2.6.1"] -ssh = ["paramiko[gssapi]>=2.5.0"] +ssh = ["paramiko>=2.5.0"] +# gssapi should not be included in all_remotes, because it doesn't have wheels +# for linux and mac, so it will fail to compile if user doesn't have all the +# requirements, including kerberos itself. Once all the wheels are available, +# we can start shipping it by default. +ssh_gssapi = ["paramiko[gssapi]>=2.5.0"] hdfs = ["pyarrow==0.14.0"] all_remotes = gs + s3 + azure + ssh + oss @@ -131,6 +136,7 @@ setup( "azure": azure, "oss": oss, "ssh": ssh, + "ssh_gssapi": ssh_gssapi, "hdfs": hdfs, # NOTE: https://github.com/inveniosoftware/troubleshooting/issues/1 ":python_version=='2.7'": ["futures", "pathlib2"], From edcd1724b4e591e8ee6f550844ee39983a2379ae Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Sat, 24 Aug 2019 15:04:25 +0700 Subject: [PATCH 09/37] cache: skip non-checksum files around cache Fixes #2394 --- dvc/remote/base.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 11e42d066..67b174c44 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -516,7 +516,12 @@ class RemoteBASE(object): raise NotImplementedError def path_to_checksum(self, path): - return "".join(self.path_cls(path).parts[-2:]) + parts = self.path_cls(path).parts[-2:] + + if not (len(parts) == 2 and parts[0] and len(parts[0]) == 2): + raise ValueError("Bad cache file path") + + return "".join(parts) def checksum_to_path_info(self, checksum): return self.path_info / checksum[0:2] / checksum[2:] @@ -529,9 +534,12 @@ class RemoteBASE(object): # is 32 bytes, so ~3200Mb list) and we don't really need all of it at # the same time, so it makes sense to use a generator to gradually # iterate over it, without keeping all of it in memory. - return ( - self.path_to_checksum(path) for path in self.list_cache_paths() - ) + for path in self.list_cache_paths(): + try: + yield self.path_to_checksum(path) + except ValueError: + # We ignore all the non-cache looking files + pass def gc(self, cinfos): used = self.extract_used_local_checksums(cinfos) From c9342754ed2b090f71bc7d97e5f307527f47992d Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 25 Aug 2019 01:18:57 +0100 Subject: [PATCH 10/37] fixed with progress - fixes #2434 --- dvc/progress.py | 15 ++++++++++++--- dvc/remote/base.py | 4 +++- dvc/remote/local/__init__.py | 6 +++--- dvc/remote/ssh/__init__.py | 6 ++++-- dvc/repo/checkout.py | 2 +- setup.py | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index 04d8d953d..c4ce7c6a2 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -40,6 +40,10 @@ class Tqdm(tqdm): bytes=False, # pylint: disable=W0622 desc_truncate=None, leave=None, + bar_format=( + "{percentage:3.0f}%|{bar:10}|{desc} {bar:-10b}{n}/{total}" + " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]" + ), **kwargs ): """ @@ -49,6 +53,7 @@ class Tqdm(tqdm): kwargs : anything accepted by `tqdm.tqdm()` """ kwargs = deepcopy(kwargs) + kwargs.setdefault("unit_scale", True) if bytes: for k, v in dict( unit="B", unit_scale=True, unit_divisor=1024, miniters=1 @@ -62,14 +67,18 @@ class Tqdm(tqdm): >= logging.CRITICAL ) super(Tqdm, self).__init__( - iterable=iterable, disable=disable, leave=leave, **kwargs + iterable=iterable, + disable=disable, + leave=leave, + bar_format=bar_format, + **kwargs ) def update_desc(self, desc, n=1, truncate=True): """ - Calls `set_description(truncate(desc))` and `update(n)` + Calls `set_description_str(truncate(desc))` and `update(n)` """ - self.set_description( + self.set_description_str( self.truncate(desc) if truncate else desc, refresh=False ) self.update(n) diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 67b174c44..544dea2ed 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -638,7 +638,9 @@ class RemoteBASE(object): if not self.no_traverse: return list(set(checksums) & set(self.all())) - with Tqdm(total=len(checksums), unit="md5") as pbar: + with Tqdm( + desc="Querying remote cache", total=len(checksums), unit="md5" + ) as pbar: def exists_with_progress(path_info): ret = self.exists(path_info) diff --git a/dvc/remote/local/__init__.py b/dvc/remote/local/__init__.py index 8381e3511..fdbdc865b 100644 --- a/dvc/remote/local/__init__.py +++ b/dvc/remote/local/__init__.py @@ -254,7 +254,9 @@ class RemoteLOCAL(RemoteBASE): def cache_exists(self, checksums, jobs=None): return [ checksum - for checksum in Tqdm(checksums, unit="md5") + for checksum in Tqdm( + checksums, unit="md5", desc="Querying local cache" + ) if not self.changed_cache_file(checksum) ] @@ -319,7 +321,6 @@ class RemoteLOCAL(RemoteBASE): ret = self._group(checksum_infos, show_checksums=show_checksums) or {} md5s = list(ret) - logger.info("Collecting information from local cache...") local_exists = self.cache_exists(md5s, jobs=jobs) # This is a performance optimization. We can safely assume that, @@ -329,7 +330,6 @@ class RemoteLOCAL(RemoteBASE): if download and sorted(local_exists) == sorted(md5s): remote_exists = local_exists else: - logger.info("Collecting information from remote cache...") remote_exists = list(remote.cache_exists(md5s, jobs=jobs)) self._fill_statuses(ret, local_exists, remote_exists) diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index d5df6a75e..4c48c6b02 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -267,7 +267,9 @@ class RemoteSSH(RemoteBASE): if not self.no_traverse: return list(set(checksums) & set(self.all())) - with Tqdm(total=len(checksums), unit="md5") as pbar: + with Tqdm( + desc="Querying remote cache", total=len(checksums), unit="md5" + ) as pbar: def exists_with_progress(chunks): return self.batch_exists(chunks, callback=pbar.update_desc) @@ -278,5 +280,5 @@ class RemoteSSH(RemoteBASE): results = executor.map(exists_with_progress, chunks) in_remote = itertools.chain.from_iterable(results) ret = list(itertools.compress(checksums, in_remote)) - pbar.update_desc("", 0) # clear path name description + pbar.set_description_str("Querying remote cache") return ret diff --git a/dvc/repo/checkout.py b/dvc/repo/checkout.py index e335763a2..077c18f5c 100644 --- a/dvc/repo/checkout.py +++ b/dvc/repo/checkout.py @@ -51,4 +51,4 @@ def checkout(self, target=None, with_deps=False, force=False, recursive=False): ) stage.checkout(force=force, progress_callback=pbar.update_desc) - pbar.update_desc("Checkout", 0) # clear path name description + pbar.set_description_str("Checkout") diff --git a/setup.py b/setup.py index 94c3b5153..b69333af5 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ install_requires = [ "funcy>=1.12", "pathspec>=0.5.9", "shortuuid>=0.5.0", - "tqdm>=4.34.0", + "tqdm>=4.35.0", "win-unicode-console>=0.5; sys_platform == 'win32'", ] From 06f920d138faf90e1f9b774a0cb81a4f015df07e Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 26 Aug 2019 01:25:50 +0100 Subject: [PATCH 11/37] fix unknown total progress - depends on https://github.com/tqdm/tqdm/pull/800 --- dvc/progress.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index c4ce7c6a2..e921677db 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -32,6 +32,11 @@ class Tqdm(tqdm): """ maximum-compatibility tqdm-based progressbars """ + BAR_FMT_DEFAULT = ( + "{percentage:3.0f}%|{bar:10}|{desc} {bar:-10b}{n}/{total}" + " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]" + ) + BAR_FMT_NOTOTAL = "{desc} {bar:b}{n} [{elapsed}11}{postfix}]" def __init__( self, @@ -40,10 +45,7 @@ class Tqdm(tqdm): bytes=False, # pylint: disable=W0622 desc_truncate=None, leave=None, - bar_format=( - "{percentage:3.0f}%|{bar:10}|{desc} {bar:-10b}{n}/{total}" - " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]" - ), + bar_format=None, **kwargs ): """ @@ -66,6 +68,11 @@ class Tqdm(tqdm): logging.getLogger(__name__).getEffectiveLevel() >= logging.CRITICAL ) + if bar_format is None: + if kwargs.get('total', getattr(iterable, '__len__', None)) is None: + bar_format = self.BAR_FMT_NOTOTAL + else: + bar_format = self.BAR_FMT_DEFAULT super(Tqdm, self).__init__( iterable=iterable, disable=disable, From c68b76f8434ac20f937696421e9a5315475d0085 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Tue, 27 Aug 2019 15:02:21 +0700 Subject: [PATCH 12/37] ui: remove "Reproducing ..." message It as always followed by a more specific one, so it's superfluous. --- dvc/stage.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dvc/stage.py b/dvc/stage.py index f91aff25d..142e94094 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -327,8 +327,6 @@ class Stage(object): if interactive and not prompt.confirm(msg): raise DvcException("reproduction aborted by the user") - logger.info("Reproducing '{stage}'".format(stage=self.relpath)) - self.run(**kwargs) logger.debug("'{stage}' was reproduced".format(stage=self.relpath)) From b52265a1d28c6b89ae23e6bdfd1ea0b0c0f25bb8 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Tue, 27 Aug 2019 15:04:37 +0700 Subject: [PATCH 13/37] ui: remove extraneous stage.save() stage.update() already does that via .run(). That was causing printing a confusing message to user. --- dvc/repo/update.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dvc/repo/update.py b/dvc/repo/update.py index 1eb352c21..bf97fca4e 100644 --- a/dvc/repo/update.py +++ b/dvc/repo/update.py @@ -4,6 +4,5 @@ def update(self, target): stage = Stage.load(self, target) with self.state: stage.update() - stage.save() stage.dump() From c8cb9ecef328a0bc68d591c9168b519b458d4a89 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 09:56:32 +0100 Subject: [PATCH 14/37] minor logic tidy sacrifice accuracy for readability --- dvc/progress.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index e921677db..7fd60969b 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -32,11 +32,14 @@ class Tqdm(tqdm): """ maximum-compatibility tqdm-based progressbars """ + BAR_FMT_DEFAULT = ( "{percentage:3.0f}%|{bar:10}|{desc} {bar:-10b}{n}/{total}" " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]" ) - BAR_FMT_NOTOTAL = "{desc} {bar:b}{n} [{elapsed}11}{postfix}]" + BAR_FMT_NOTOTAL = ( + "{desc} {bar:b}{n} [{elapsed}11}{postfix}]" + ) def __init__( self, @@ -69,10 +72,10 @@ class Tqdm(tqdm): >= logging.CRITICAL ) if bar_format is None: - if kwargs.get('total', getattr(iterable, '__len__', None)) is None: - bar_format = self.BAR_FMT_NOTOTAL - else: + if kwargs.get("total", hasattr(iterable, "__len__")): bar_format = self.BAR_FMT_DEFAULT + else: + bar_format = self.BAR_FMT_NOTOTAL super(Tqdm, self).__init__( iterable=iterable, disable=disable, From 7c6d68ad5af1610fa0114e0751fa2d6d30d6593a Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 10:57:18 +0100 Subject: [PATCH 15/37] decrease verbosity, default progress leave=False --- dvc/progress.py | 15 +++++++++++---- dvc/remote/local/__init__.py | 6 ++++-- dvc/remote/ssh/__init__.py | 1 - dvc/repo/checkout.py | 8 +++++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index 7fd60969b..a638d1bf8 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -5,6 +5,8 @@ from tqdm import tqdm from copy import deepcopy from concurrent.futures import ThreadPoolExecutor +logger = logging.getLogger(__name__) + class TqdmThreadPoolExecutor(ThreadPoolExecutor): """ @@ -49,12 +51,18 @@ class Tqdm(tqdm): desc_truncate=None, leave=None, bar_format=None, + level=logging.ERROR, + level_leave=logging.DEBUG, **kwargs ): """ bytes : shortcut for `unit='B', unit_scale=True, unit_divisor=1024, miniters=1` desc_truncate : like `desc` but will truncate to 10 chars + level : effective logging level for determining `disable`; + used only if `disable` is unspecified + level_leave : effective logging level for determining `leave`; + used only if `leave` is unspecified kwargs : anything accepted by `tqdm.tqdm()` """ kwargs = deepcopy(kwargs) @@ -67,10 +75,9 @@ class Tqdm(tqdm): if desc_truncate is not None: kwargs.setdefault("desc", self.truncate(desc_truncate)) if disable is None: - disable = ( - logging.getLogger(__name__).getEffectiveLevel() - >= logging.CRITICAL - ) + disable = logger.getEffectiveLevel() > level + if leave is None: + leave = logger.getEffectiveLevel() <= level_leave if bar_format is None: if kwargs.get("total", hasattr(iterable, "__len__")): bar_format = self.BAR_FMT_DEFAULT diff --git a/dvc/remote/local/__init__.py b/dvc/remote/local/__init__.py index fdbdc865b..d97fb0159 100644 --- a/dvc/remote/local/__init__.py +++ b/dvc/remote/local/__init__.py @@ -315,12 +315,13 @@ class RemoteLOCAL(RemoteBASE): show_checksums=False, download=False, ): - logger.info( + logger.debug( "Preparing to collect status from {}".format(remote.path_info) ) ret = self._group(checksum_infos, show_checksums=show_checksums) or {} md5s = list(ret) + logger.debug("Collecting information from local cache...") local_exists = self.cache_exists(md5s, jobs=jobs) # This is a performance optimization. We can safely assume that, @@ -330,6 +331,7 @@ class RemoteLOCAL(RemoteBASE): if download and sorted(local_exists) == sorted(md5s): remote_exists = local_exists else: + logger.debug("Collecting information from remote cache...") remote_exists = list(remote.cache_exists(md5s, jobs=jobs)) self._fill_statuses(ret, local_exists, remote_exists) @@ -377,7 +379,7 @@ class RemoteLOCAL(RemoteBASE): show_checksums=False, download=False, ): - logger.info( + logger.debug( "Preparing to {} '{}'".format( "download data from" if download else "upload data to", remote.path_info, diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index 4c48c6b02..8ccb29e8e 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -280,5 +280,4 @@ class RemoteSSH(RemoteBASE): results = executor.map(exists_with_progress, chunks) in_remote = itertools.chain.from_iterable(results) ret = list(itertools.compress(checksums, in_remote)) - pbar.set_description_str("Querying remote cache") return ret diff --git a/dvc/repo/checkout.py b/dvc/repo/checkout.py index 077c18f5c..c7b967710 100644 --- a/dvc/repo/checkout.py +++ b/dvc/repo/checkout.py @@ -38,8 +38,14 @@ def checkout(self, target=None, with_deps=False, force=False, recursive=False): with self.state: _cleanup_unused_links(self, all_stages) total = get_all_files_numbers(stages) + if total == 0: + logger.info("Nothing to do") with Tqdm( - total=total, unit="file", desc="Checkout", disable=total == 0 + total=total, + unit="file", + desc="Checkout", + disable=total == 0, + level_leave=logging.INFO, ) as pbar: for stage in stages: if stage.locked: From de97d3ddac7f560d58ec89823a596cdcd1a45b9d Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 11:08:27 +0100 Subject: [PATCH 16/37] persistent desc --- dvc/progress.py | 20 +++++++++++++++----- dvc/repo/checkout.py | 1 - 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index a638d1bf8..13c05ed36 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -47,18 +47,20 @@ class Tqdm(tqdm): self, iterable=None, disable=None, - bytes=False, # pylint: disable=W0622 + level=logging.ERROR, + desc=None, desc_truncate=None, leave=None, - bar_format=None, - level=logging.ERROR, level_leave=logging.DEBUG, + bar_format=None, + bytes=False, # pylint: disable=W0622 **kwargs ): """ bytes : shortcut for `unit='B', unit_scale=True, unit_divisor=1024, miniters=1` - desc_truncate : like `desc` but will truncate to 10 chars + desc : persists after `close()` + desc_truncate : like `desc` but will `truncate()` and not persist level : effective logging level for determining `disable`; used only if `disable` is unspecified level_leave : effective logging level for determining `leave`; @@ -72,8 +74,10 @@ class Tqdm(tqdm): unit="B", unit_scale=True, unit_divisor=1024, miniters=1 ).items(): kwargs.setdefault(k, v) + if desc is not None: + self.desc_persist = desc if desc_truncate is not None: - kwargs.setdefault("desc", self.truncate(desc_truncate)) + desc = self.truncate(desc_truncate) if disable is None: disable = logger.getEffectiveLevel() > level if leave is None: @@ -87,6 +91,7 @@ class Tqdm(tqdm): iterable=iterable, disable=disable, leave=leave, + desc=desc, bar_format=bar_format, **kwargs ) @@ -105,6 +110,11 @@ class Tqdm(tqdm): self.total = total # pylint: disable=W0613,W0201 self.update(current - self.n) + def close(self): + if hasattr(self, "desc_persist"): + self.set_description_str(self.desc_persist, refresh=False) + super(Tqdm, self).close() + @classmethod def truncate(cls, s, max_len=25, end=True, fill="..."): """ diff --git a/dvc/repo/checkout.py b/dvc/repo/checkout.py index c7b967710..26057c15c 100644 --- a/dvc/repo/checkout.py +++ b/dvc/repo/checkout.py @@ -57,4 +57,3 @@ def checkout(self, target=None, with_deps=False, force=False, recursive=False): ) stage.checkout(force=force, progress_callback=pbar.update_desc) - pbar.set_description_str("Checkout") From 720608f379df6b4db6e751d7fb3902a3626695db Mon Sep 17 00:00:00 2001 From: pared Date: Thu, 22 Aug 2019 12:55:49 +0200 Subject: [PATCH 17/37] repo: make repo.collect collect all stages, not active --- dvc/repo/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index e1139d90a..5cf814991 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -164,7 +164,7 @@ class Repo(object): from dvc.stage import Stage if not target or (recursive and os.path.isdir(target)): - return self.active_stages(target) + return self.stages(target) stage = Stage.load(self, target) if not with_deps: From d02327fb531deee299caa42682d171debf64e93b Mon Sep 17 00:00:00 2001 From: pared Date: Thu, 22 Aug 2019 12:56:52 +0200 Subject: [PATCH 18/37] repo: make repo.active_stages collect active stages only --- dvc/repo/__init__.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index 5cf814991..7e8bd20ba 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -353,15 +353,25 @@ class Repo(object): return G, G_active - def pipelines(self, from_directory=None): + @staticmethod + def _pipelines(graph): import networkx as nx - G, G_active = self.graph(from_directory=from_directory) - return [ - G.subgraph(c).copy() for c in nx.weakly_connected_components(G) + graph.subgraph(c).copy() + for c in nx.weakly_connected_components(graph) ] + def pipelines(self, from_directory=None): + G, _ = self.graph(from_directory=from_directory) + + return self._pipelines(G) + + def pipelines_for_active_nodes(self, from_directory=None): + _, G_active = self.graph(from_directory=from_directory) + + return self._pipelines(G_active) + @staticmethod def _filter_out_dirs(dirs, outs, root_dir): def filter_dirs(dname): @@ -417,7 +427,7 @@ class Repo(object): import networkx as nx stages = [] - for G in self.pipelines(from_directory): + for G in self.pipelines_for_active_nodes(from_directory): stages.extend(list(nx.get_node_attributes(G, "stage").values())) return stages From 16b62d154a4b208426b3f62500e6acc6c9539760 Mon Sep 17 00:00:00 2001 From: pared Date: Thu, 22 Aug 2019 12:58:04 +0200 Subject: [PATCH 19/37] gc: remove unnecessary arguments for gc._load_all_used_cache --- dvc/repo/gc.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index 89b16e35c..bfae569ff 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -21,9 +21,7 @@ def _merge_cache_lists(clists): def _load_all_used_cache( repos, - target=None, all_branches=False, - active=True, with_deps=False, all_tags=False, remote=None, @@ -76,9 +74,7 @@ def gc( all_clists = _load_all_used_cache( all_repos, - target=None, all_branches=all_branches, - active=False, with_deps=with_deps, all_tags=all_tags, remote=remote, From babd5b2a12172cb3260fd757fee1a6054692c30d Mon Sep 17 00:00:00 2001 From: pawel Date: Mon, 26 Aug 2019 21:54:10 +0200 Subject: [PATCH 20/37] repo: drop active_stages --- dvc/repo/__init__.py | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index 7e8bd20ba..d79e2882f 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -225,8 +225,6 @@ class Repo(object): stages.extend( self.collect(target, with_deps=with_deps) ) - elif active: - stages = self.active_stages() else: stages = self.stages() @@ -353,25 +351,15 @@ class Repo(object): return G, G_active - @staticmethod - def _pipelines(graph): + def pipelines(self, from_directory=None): import networkx as nx + G, G_active = self.graph(from_directory=from_directory) + return [ - graph.subgraph(c).copy() - for c in nx.weakly_connected_components(graph) + G.subgraph(c).copy() for c in nx.weakly_connected_components(G) ] - def pipelines(self, from_directory=None): - G, _ = self.graph(from_directory=from_directory) - - return self._pipelines(G) - - def pipelines_for_active_nodes(self, from_directory=None): - _, G_active = self.graph(from_directory=from_directory) - - return self._pipelines(G_active) - @staticmethod def _filter_out_dirs(dirs, outs, root_dir): def filter_dirs(dname): @@ -423,14 +411,6 @@ class Repo(object): return stages - def active_stages(self, from_directory=None): - import networkx as nx - - stages = [] - for G in self.pipelines_for_active_nodes(from_directory): - stages.extend(list(nx.get_node_attributes(G, "stage").values())) - return stages - def find_outs_by_path(self, path, outs=None, recursive=False): if not outs: # there is no `from_directory=path` argument because some data From a9efabbc6e62dc15fe03b4e3b5d60d2685c06870 Mon Sep 17 00:00:00 2001 From: pawel Date: Tue, 27 Aug 2019 14:08:00 +0200 Subject: [PATCH 21/37] repo: used_cache: remove active flag --- dvc/repo/__init__.py | 9 --------- dvc/repo/gc.py | 1 - 2 files changed, 10 deletions(-) diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index d79e2882f..2f743a6ff 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -183,7 +183,6 @@ class Repo(object): self, targets=None, all_branches=False, - active=True, with_deps=False, all_tags=False, remote=None, @@ -229,14 +228,6 @@ class Repo(object): stages = self.stages() for stage in stages: - if active and not targets and stage.locked: - logger.warning( - "DVC-file '{path}' is locked. Its dependencies are" - " not going to be pushed/pulled/fetched.".format( - path=stage.relpath - ) - ) - for out in stage.outs: scheme = out.path_info.scheme used_cache = out.get_used_cache( diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index bfae569ff..c334b5ebe 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -35,7 +35,6 @@ def _load_all_used_cache( repo_clist = repo.used_cache( targets=None, all_branches=all_branches, - active=False, with_deps=with_deps, all_tags=all_tags, remote=remote, From 043119b747d52e73d5e4b34c418960e27b74d9db Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 13:25:43 +0100 Subject: [PATCH 22/37] misc minor tidy as per review --- dvc/progress.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index 13c05ed36..e0a00944c 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -2,7 +2,6 @@ from __future__ import print_function import logging from tqdm import tqdm -from copy import deepcopy from concurrent.futures import ThreadPoolExecutor logger = logging.getLogger(__name__) @@ -67,15 +66,14 @@ class Tqdm(tqdm): used only if `leave` is unspecified kwargs : anything accepted by `tqdm.tqdm()` """ - kwargs = deepcopy(kwargs) + kwargs = kwargs.copy() kwargs.setdefault("unit_scale", True) if bytes: for k, v in dict( unit="B", unit_scale=True, unit_divisor=1024, miniters=1 ).items(): kwargs.setdefault(k, v) - if desc is not None: - self.desc_persist = desc + self.desc_persist = desc if desc_truncate is not None: desc = self.truncate(desc_truncate) if disable is None: @@ -111,7 +109,7 @@ class Tqdm(tqdm): self.update(current - self.n) def close(self): - if hasattr(self, "desc_persist"): + if self.desc_persist: self.set_description_str(self.desc_persist, refresh=False) super(Tqdm, self).close() From 86605b6fa6d98237d5f069c468cdfb84601d0ef4 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 13:41:12 +0100 Subject: [PATCH 23/37] use funcy --- dvc/progress.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index e0a00944c..ffef29255 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -3,6 +3,7 @@ from __future__ import print_function import logging from tqdm import tqdm from concurrent.futures import ThreadPoolExecutor +from funcy import merge logger = logging.getLogger(__name__) @@ -69,10 +70,10 @@ class Tqdm(tqdm): kwargs = kwargs.copy() kwargs.setdefault("unit_scale", True) if bytes: - for k, v in dict( - unit="B", unit_scale=True, unit_divisor=1024, miniters=1 - ).items(): - kwargs.setdefault(k, v) + kwargs = merge( + dict(unit="B", unit_scale=True, unit_divisor=1024, miniters=1), + kwargs, + ) self.desc_persist = desc if desc_truncate is not None: desc = self.truncate(desc_truncate) From 7171712fa998820d0fa3b9bb19ce7a9bf378011f Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 13:41:37 +0100 Subject: [PATCH 24/37] delay bar_format --- dvc/progress.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index ffef29255..c0a67b323 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -81,19 +81,21 @@ class Tqdm(tqdm): disable = logger.getEffectiveLevel() > level if leave is None: leave = logger.getEffectiveLevel() <= level_leave - if bar_format is None: - if kwargs.get("total", hasattr(iterable, "__len__")): - bar_format = self.BAR_FMT_DEFAULT - else: - bar_format = self.BAR_FMT_NOTOTAL super(Tqdm, self).__init__( iterable=iterable, disable=disable, leave=leave, desc=desc, - bar_format=bar_format, + bar_format="", **kwargs ) + if bar_format is None: + self.bar_format = ( + self.BAR_FMT_DEFAULT if len(self) else self.BAR_FMT_NOTOTAL + ) + else: + self.bar_format = bar_format + self.refresh() def update_desc(self, desc, n=1, truncate=True): """ From 03a5c6df5e1d446a8270d02ebb9b72a1bf0cbe4e Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 14:00:04 +0100 Subject: [PATCH 25/37] progress default leave=False as per reviews --- dvc/progress.py | 7 +------ dvc/repo/checkout.py | 2 +- dvc/utils/__init__.py | 6 +++--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index c0a67b323..64c021653 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -50,8 +50,7 @@ class Tqdm(tqdm): level=logging.ERROR, desc=None, desc_truncate=None, - leave=None, - level_leave=logging.DEBUG, + leave=False, bar_format=None, bytes=False, # pylint: disable=W0622 **kwargs @@ -63,8 +62,6 @@ class Tqdm(tqdm): desc_truncate : like `desc` but will `truncate()` and not persist level : effective logging level for determining `disable`; used only if `disable` is unspecified - level_leave : effective logging level for determining `leave`; - used only if `leave` is unspecified kwargs : anything accepted by `tqdm.tqdm()` """ kwargs = kwargs.copy() @@ -79,8 +76,6 @@ class Tqdm(tqdm): desc = self.truncate(desc_truncate) if disable is None: disable = logger.getEffectiveLevel() > level - if leave is None: - leave = logger.getEffectiveLevel() <= level_leave super(Tqdm, self).__init__( iterable=iterable, disable=disable, diff --git a/dvc/repo/checkout.py b/dvc/repo/checkout.py index 26057c15c..40f4b123b 100644 --- a/dvc/repo/checkout.py +++ b/dvc/repo/checkout.py @@ -45,7 +45,7 @@ def checkout(self, target=None, with_deps=False, force=False, recursive=False): unit="file", desc="Checkout", disable=total == 0, - level_leave=logging.INFO, + leave=logger.getEffectiveLevel() < logging.CRITICAL, ) as pbar: for stage in stages: if stage.locked: diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index 050f65366..9878a8c2e 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -51,16 +51,16 @@ def file_md5(fname): hash_md5 = hashlib.md5() binary = not istextfile(fname) size = os.path.getsize(fname) - bar = False + no_progress_bar = True if size >= LARGE_FILE_SIZE: - bar = True + no_progress_bar = False msg = "Computing md5 for a large file {}. This is only done once." logger.info(msg.format(relpath(fname))) name = relpath(fname) with Tqdm( desc_truncate=name, - disable=not bar, + disable=no_progress_bar, total=size, bytes=True, leave=False, From f336afa8611b2b08420edfbe537e6c393595bed5 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 20:23:55 +0100 Subject: [PATCH 26/37] remove Tqdm.truncate => add {ncols_desc} --- dvc/progress.py | 43 ++++++++++++++---------------------- dvc/remote/azure.py | 8 ++----- dvc/remote/http.py | 2 +- dvc/remote/oss.py | 8 ++----- dvc/remote/s3.py | 10 ++------- dvc/remote/ssh/connection.py | 4 ++-- dvc/utils/__init__.py | 7 ++---- 7 files changed, 28 insertions(+), 54 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index 64c021653..a2331fc93 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -36,11 +36,13 @@ class Tqdm(tqdm): """ BAR_FMT_DEFAULT = ( - "{percentage:3.0f}%|{bar:10}|{desc} {bar:-10b}{n}/{total}" + "{percentage:3.0f}%|{bar:10}|" + "{desc:{ncols_desc}.{ncols_desc}}{n}/{total}" " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]" ) BAR_FMT_NOTOTAL = ( - "{desc} {bar:b}{n} [{elapsed}11}{postfix}]" + "{desc:{ncols_desc}.{ncols_desc}}{n}" + " [{elapsed}11}{postfix}]" ) def __init__( @@ -49,7 +51,6 @@ class Tqdm(tqdm): disable=None, level=logging.ERROR, desc=None, - desc_truncate=None, leave=False, bar_format=None, bytes=False, # pylint: disable=W0622 @@ -59,7 +60,6 @@ class Tqdm(tqdm): bytes : shortcut for `unit='B', unit_scale=True, unit_divisor=1024, miniters=1` desc : persists after `close()` - desc_truncate : like `desc` but will `truncate()` and not persist level : effective logging level for determining `disable`; used only if `disable` is unspecified kwargs : anything accepted by `tqdm.tqdm()` @@ -72,8 +72,6 @@ class Tqdm(tqdm): kwargs, ) self.desc_persist = desc - if desc_truncate is not None: - desc = self.truncate(desc_truncate) if disable is None: disable = logger.getEffectiveLevel() > level super(Tqdm, self).__init__( @@ -81,7 +79,7 @@ class Tqdm(tqdm): disable=disable, leave=leave, desc=desc, - bar_format="", + bar_format="!", **kwargs ) if bar_format is None: @@ -92,13 +90,11 @@ class Tqdm(tqdm): self.bar_format = bar_format self.refresh() - def update_desc(self, desc, n=1, truncate=True): + def update_desc(self, desc, n=1): """ - Calls `set_description_str(truncate(desc))` and `update(n)` + Calls `set_description_str(desc)` and `update(n)` """ - self.set_description_str( - self.truncate(desc) if truncate else desc, refresh=False - ) + self.set_description_str(desc, refresh=False) self.update(n) def update_to(self, current, total=None): @@ -107,20 +103,15 @@ class Tqdm(tqdm): self.update(current - self.n) def close(self): - if self.desc_persist: + if self.desc_persist is not None: self.set_description_str(self.desc_persist, refresh=False) super(Tqdm, self).close() - @classmethod - def truncate(cls, s, max_len=25, end=True, fill="..."): - """ - Guarantee len(output) < max_lenself. - >>> truncate("hello", 4) - '...o' - """ - if len(s) <= max_len: - return s - if len(fill) > max_len: - return fill[-max_len:] if end else fill[:max_len] - i = max_len - len(fill) - return (fill + s[-i:]) if end else (s[:i] + fill) + @property + def format_dict(self): + """inject `ncols_desc` to fill the display width (`ncols`)""" + d = super(Tqdm, self).format_dict + ncols = d.get("ncols", 80) + ncols_desc = ncols - len(self.format_meter(ncols_desc=1, **d)) + 1 + d["ncols_desc"] = max(ncols_desc, 0) + return d diff --git a/dvc/remote/azure.py b/dvc/remote/azure.py index 2527b66ba..e891c345d 100644 --- a/dvc/remote/azure.py +++ b/dvc/remote/azure.py @@ -115,9 +115,7 @@ class RemoteAZURE(RemoteBASE): def _upload( self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs ): - with Tqdm( - desc_truncate=name, disable=no_progress_bar, bytes=True - ) as pbar: + with Tqdm(desc=name, disable=no_progress_bar, bytes=True) as pbar: self.blob_service.create_blob_from_path( to_info.bucket, to_info.path, @@ -128,9 +126,7 @@ class RemoteAZURE(RemoteBASE): def _download( self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs ): - with Tqdm( - desc_truncate=name, disable=no_progress_bar, bytes=True - ) as pbar: + with Tqdm(desc=name, disable=no_progress_bar, bytes=True) as pbar: self.blob_service.get_blob_to_path( from_info.bucket, from_info.path, diff --git a/dvc/remote/http.py b/dvc/remote/http.py index 6f430b0e7..c12c6e940 100644 --- a/dvc/remote/http.py +++ b/dvc/remote/http.py @@ -38,7 +38,7 @@ class RemoteHTTP(RemoteBASE): total=None if no_progress_bar else self._content_length(from_info), leave=False, bytes=True, - desc_truncate=from_info.url if name is None else name, + desc=from_info.url if name is None else name, disable=no_progress_bar, ) as pbar: with open(to_file, "wb") as fd: diff --git a/dvc/remote/oss.py b/dvc/remote/oss.py index 57e900087..ca6d5a4e0 100644 --- a/dvc/remote/oss.py +++ b/dvc/remote/oss.py @@ -107,9 +107,7 @@ class RemoteOSS(RemoteBASE): def _upload( self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs ): - with Tqdm( - desc_truncate=name, disable=no_progress_bar, bytes=True - ) as pbar: + with Tqdm(desc=name, disable=no_progress_bar, bytes=True) as pbar: self.oss_service.put_object_from_file( to_info.path, from_file, progress_callback=pbar.update_to ) @@ -117,9 +115,7 @@ class RemoteOSS(RemoteBASE): def _download( self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs ): - with Tqdm( - desc_truncate=name, disable=no_progress_bar, bytes=True - ) as pbar: + with Tqdm(desc=name, disable=no_progress_bar, bytes=True) as pbar: self.oss_service.get_object_to_file( from_info.path, to_file, progress_callback=pbar.update_to ) diff --git a/dvc/remote/s3.py b/dvc/remote/s3.py index 938a9a2ae..7de02f152 100644 --- a/dvc/remote/s3.py +++ b/dvc/remote/s3.py @@ -208,10 +208,7 @@ class RemoteS3(RemoteBASE): def _upload(self, from_file, to_info, name=None, no_progress_bar=False): total = os.path.getsize(from_file) with Tqdm( - disable=no_progress_bar, - total=total, - bytes=True, - desc_truncate=name, + disable=no_progress_bar, total=total, bytes=True, desc=name ) as pbar: self.s3.upload_file( from_file, @@ -229,10 +226,7 @@ class RemoteS3(RemoteBASE): Bucket=from_info.bucket, Key=from_info.path )["ContentLength"] with Tqdm( - disable=no_progress_bar, - total=total, - bytes=True, - desc_truncate=name, + disable=no_progress_bar, total=total, bytes=True, desc=name ) as pbar: self.s3.download_file( from_info.bucket, from_info.path, to_file, Callback=pbar.update diff --git a/dvc/remote/ssh/connection.py b/dvc/remote/ssh/connection.py index fbb0c2b7b..43b380ada 100644 --- a/dvc/remote/ssh/connection.py +++ b/dvc/remote/ssh/connection.py @@ -169,7 +169,7 @@ class SSHConnection: def download(self, src, dest, no_progress_bar=False, progress_title=None): with Tqdm( - desc_truncate=progress_title or os.path.basename(src), + desc=progress_title or os.path.basename(src), disable=no_progress_bar, bytes=True, ) as pbar: @@ -186,7 +186,7 @@ class SSHConnection: progress_title = posixpath.basename(dest) with Tqdm( - desc_truncate=progress_title, disable=no_progress_bar, bytes=True + desc=progress_title, disable=no_progress_bar, bytes=True ) as pbar: self.sftp.put(src, tmp_file, callback=pbar.update_to) diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index 9878a8c2e..59e943707 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -59,7 +59,7 @@ def file_md5(fname): name = relpath(fname) with Tqdm( - desc_truncate=name, + desc=name, disable=no_progress_bar, total=size, bytes=True, @@ -132,10 +132,7 @@ def copyfile(src, dest, no_progress_bar=False, name=None): System.reflink(src, dest) except DvcException: with Tqdm( - desc_truncate=name, - disable=no_progress_bar, - total=total, - bytes=True, + desc=name, disable=no_progress_bar, total=total, bytes=True ) as pbar: with open(src, "rb") as fsrc, open(dest, "wb+") as fdest: while True: From bc452bb68901bdad08d352027c3eb12578a7dba3 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 27 Aug 2019 20:30:43 +0100 Subject: [PATCH 27/37] minor test fix --- dvc/progress.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index a2331fc93..93334c46b 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -83,9 +83,10 @@ class Tqdm(tqdm): **kwargs ) if bar_format is None: - self.bar_format = ( - self.BAR_FMT_DEFAULT if len(self) else self.BAR_FMT_NOTOTAL - ) + if self.__len__(): + self.bar_format = self.BAR_FMT_DEFAULT + else: + self.bar_format = self.BAR_FMT_NOTOTAL else: self.bar_format = bar_format self.refresh() @@ -111,7 +112,7 @@ class Tqdm(tqdm): def format_dict(self): """inject `ncols_desc` to fill the display width (`ncols`)""" d = super(Tqdm, self).format_dict - ncols = d.get("ncols", 80) + ncols = d["ncols"] or 80 ncols_desc = ncols - len(self.format_meter(ncols_desc=1, **d)) + 1 d["ncols_desc"] = max(ncols_desc, 0) return d From 5413576e274be6000267df06bfa04bda57e5d13a Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 28 Aug 2019 17:22:33 +0100 Subject: [PATCH 28/37] decrease final verbosity further; minor tidy --- dvc/progress.py | 6 +++--- dvc/repo/checkout.py | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index 93334c46b..df36726b8 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -67,10 +67,10 @@ class Tqdm(tqdm): kwargs = kwargs.copy() kwargs.setdefault("unit_scale", True) if bytes: - kwargs = merge( - dict(unit="B", unit_scale=True, unit_divisor=1024, miniters=1), - kwargs, + bytes_defaults = dict( + unit="B", unit_scale=True, unit_divisor=1024, miniters=1 ) + kwargs = merge(bytes_defaults, kwargs) self.desc_persist = desc if disable is None: disable = logger.getEffectiveLevel() > level diff --git a/dvc/repo/checkout.py b/dvc/repo/checkout.py index 40f4b123b..de7e77cea 100644 --- a/dvc/repo/checkout.py +++ b/dvc/repo/checkout.py @@ -41,11 +41,7 @@ def checkout(self, target=None, with_deps=False, force=False, recursive=False): if total == 0: logger.info("Nothing to do") with Tqdm( - total=total, - unit="file", - desc="Checkout", - disable=total == 0, - leave=logger.getEffectiveLevel() < logging.CRITICAL, + total=total, unit="file", desc="Checkout", disable=total == 0 ) as pbar: for stage in stages: if stage.locked: From 5f81352f901bbc5b0dc0292aea472973a79e2d3e Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 28 Aug 2019 17:44:12 +0100 Subject: [PATCH 29/37] add cache_dir to progress output --- dvc/remote/base.py | 17 ++++++++++++++--- dvc/remote/local/__init__.py | 17 +++++++++-------- dvc/remote/ssh/__init__.py | 7 +++++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 544dea2ed..2fbf79885 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -140,6 +140,14 @@ class RemoteBASE(object): def cache(self): return getattr(self.repo.cache, self.scheme) + @property + def cache_dir(self): + return ( + getattr(self.path_info, "fspath", self.path_info.url) + if self.path_info + else None + ) + def get_file_checksum(self, path_info): raise NotImplementedError @@ -612,7 +620,7 @@ class RemoteBASE(object): return self._changed_dir_cache(checksum) return self.changed_cache_file(checksum) - def cache_exists(self, checksums, jobs=None): + def cache_exists(self, checksums, jobs=None, name=None): """Check if the given checksums are stored in the remote. There are two ways of performing this check: @@ -630,7 +638,7 @@ class RemoteBASE(object): take much shorter time to just retrieve everything they have under a certain prefix (e.g. s3, gs, ssh, hdfs). Other remotes that can check if particular file exists much quicker, use their own - implementation of cache_exists (see http, local). + implementation of cache_exists (see ssh, local). Returns: A list with checksums that were found in the remote @@ -639,7 +647,10 @@ class RemoteBASE(object): return list(set(checksums) & set(self.all())) with Tqdm( - desc="Querying remote cache", total=len(checksums), unit="md5" + desc="Querying " + + ("cache in " + name if name else "remote cache"), + total=len(checksums), + unit="md5", ) as pbar: def exists_with_progress(path_info): diff --git a/dvc/remote/local/__init__.py b/dvc/remote/local/__init__.py index d97fb0159..5bba17b6a 100644 --- a/dvc/remote/local/__init__.py +++ b/dvc/remote/local/__init__.py @@ -97,10 +97,6 @@ class RemoteLOCAL(RemoteBASE): def state(self): return self.repo.state - @property - def cache_dir(self): - return self.path_info.fspath if self.path_info else None - @classmethod def supported(cls, config): return True @@ -251,11 +247,14 @@ class RemoteLOCAL(RemoteBASE): move(from_info, to_info, mode=mode) - def cache_exists(self, checksums, jobs=None): + def cache_exists(self, checksums, jobs=None, name=None): return [ checksum for checksum in Tqdm( - checksums, unit="md5", desc="Querying local cache" + checksums, + unit="md5", + desc="Querying " + + ("cache in " + name if name else "local cache"), ) if not self.changed_cache_file(checksum) ] @@ -322,7 +321,7 @@ class RemoteLOCAL(RemoteBASE): md5s = list(ret) logger.debug("Collecting information from local cache...") - local_exists = self.cache_exists(md5s, jobs=jobs) + local_exists = self.cache_exists(md5s, jobs=jobs, name=self.cache_dir) # This is a performance optimization. We can safely assume that, # if the resources that we want to fetch are already cached, @@ -332,7 +331,9 @@ class RemoteLOCAL(RemoteBASE): remote_exists = local_exists else: logger.debug("Collecting information from remote cache...") - remote_exists = list(remote.cache_exists(md5s, jobs=jobs)) + remote_exists = list( + remote.cache_exists(md5s, jobs=jobs, name=remote.cache_dir) + ) self._fill_statuses(ret, local_exists, remote_exists) diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index 8ccb29e8e..5c243f471 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -258,7 +258,7 @@ class RemoteSSH(RemoteBASE): return results - def cache_exists(self, checksums, jobs=None): + def cache_exists(self, checksums, jobs=None, name=None): """This is older implementation used in remote/base.py We are reusing it in RemoteSSH, because SSH's batch_exists proved to be faster than current approach (relying on exists(path_info)) applied in @@ -268,7 +268,10 @@ class RemoteSSH(RemoteBASE): return list(set(checksums) & set(self.all())) with Tqdm( - desc="Querying remote cache", total=len(checksums), unit="md5" + desc="Querying " + + ("cache in " + name if name else "remote cache"), + total=len(checksums), + unit="md5", ) as pbar: def exists_with_progress(chunks): From 7be68d9448d2f1dcbaa4a1ca0ab980a2b62db841 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 28 Aug 2019 17:58:53 +0100 Subject: [PATCH 30/37] replace md5 => file --- dvc/remote/base.py | 6 +++--- dvc/remote/local/__init__.py | 2 +- dvc/remote/ssh/__init__.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 2fbf79885..9efd0180e 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -650,16 +650,16 @@ class RemoteBASE(object): desc="Querying " + ("cache in " + name if name else "remote cache"), total=len(checksums), - unit="md5", + unit="file", ) as pbar: def exists_with_progress(path_info): ret = self.exists(path_info) - pbar.update() + pbar.update_desc(str(path_info)) return ret with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor: - path_infos = [self.checksum_to_path_info(x) for x in checksums] + path_infos = map(self.checksum_to_path_info, checksums) in_remote = executor.map(exists_with_progress, path_infos) ret = list(itertools.compress(checksums, in_remote)) return ret diff --git a/dvc/remote/local/__init__.py b/dvc/remote/local/__init__.py index 5bba17b6a..0a0a4b84d 100644 --- a/dvc/remote/local/__init__.py +++ b/dvc/remote/local/__init__.py @@ -252,7 +252,7 @@ class RemoteLOCAL(RemoteBASE): checksum for checksum in Tqdm( checksums, - unit="md5", + unit="file", desc="Querying " + ("cache in " + name if name else "local cache"), ) diff --git a/dvc/remote/ssh/__init__.py b/dvc/remote/ssh/__init__.py index 5c243f471..74280d7bb 100644 --- a/dvc/remote/ssh/__init__.py +++ b/dvc/remote/ssh/__init__.py @@ -271,7 +271,7 @@ class RemoteSSH(RemoteBASE): desc="Querying " + ("cache in " + name if name else "remote cache"), total=len(checksums), - unit="md5", + unit="file", ) as pbar: def exists_with_progress(chunks): From 6c3029deded95ce2dc2ef82f239e3db54090e719 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 28 Aug 2019 18:02:50 +0100 Subject: [PATCH 31/37] revert cache_dir move partially reverts 5f81352f --- dvc/remote/base.py | 8 -------- dvc/remote/local/__init__.py | 8 +++++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 9efd0180e..5f77d8636 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -140,14 +140,6 @@ class RemoteBASE(object): def cache(self): return getattr(self.repo.cache, self.scheme) - @property - def cache_dir(self): - return ( - getattr(self.path_info, "fspath", self.path_info.url) - if self.path_info - else None - ) - def get_file_checksum(self, path_info): raise NotImplementedError diff --git a/dvc/remote/local/__init__.py b/dvc/remote/local/__init__.py index 0a0a4b84d..168c1f9c0 100644 --- a/dvc/remote/local/__init__.py +++ b/dvc/remote/local/__init__.py @@ -97,6 +97,10 @@ class RemoteLOCAL(RemoteBASE): def state(self): return self.repo.state + @property + def cache_dir(self): + return self.path_info.fspath if self.path_info else None + @classmethod def supported(cls, config): return True @@ -332,7 +336,9 @@ class RemoteLOCAL(RemoteBASE): else: logger.debug("Collecting information from remote cache...") remote_exists = list( - remote.cache_exists(md5s, jobs=jobs, name=remote.cache_dir) + remote.cache_exists( + md5s, jobs=jobs, name=str(remote.path_info) + ) ) self._fill_statuses(ret, local_exists, remote_exists) From 5d05e9ab0117a5535f972ff89981bb8ea5a6518d Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 28 Aug 2019 21:13:30 +0300 Subject: [PATCH 32/37] remote: quote pip install command Fixes https://github.com/iterative/dvc/issues/2446 --- dvc/remote/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 67b174c44..02d64b9db 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -99,10 +99,10 @@ class RemoteBASE(object): " pip install {}\n" " 2) Install dvc package that includes those missing " "dependencies: \n" - " pip install dvc[{}]\n" + " pip install 'dvc[{}]'\n" " 3) Install dvc package with all possible " "dependencies included: \n" - " pip install dvc[all]\n" + " pip install 'dvc[all]'\n" "\n" "If you have installed dvc from a binary package and you " "are still seeing this message, please report it to us " From e7665956876c51b1bdbd519f6e9980e992f26869 Mon Sep 17 00:00:00 2001 From: pawel Date: Fri, 30 Aug 2019 12:03:19 +0200 Subject: [PATCH 33/37] workaround for google-resumable-media==0.3.3 build problem --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b69333af5..4e3c30df9 100644 --- a/setup.py +++ b/setup.py @@ -71,7 +71,7 @@ else: install_requires.append("networkx>=2.1") # Extra dependencies for remote integrations -gs = ["google-cloud-storage==1.13.0"] +gs = ["google-resumable-media==0.3.2", "google-cloud-storage==1.13.0"] s3 = ["boto3==1.9.115"] azure = ["azure-storage-blob==2.1.0"] oss = ["oss2==2.6.1"] From 3c01f07ffdb3407d3f98a50620a5739d3131e064 Mon Sep 17 00:00:00 2001 From: pawel Date: Fri, 30 Aug 2019 14:04:12 +0200 Subject: [PATCH 34/37] setup: add note why we restrict google-resumable-media version --- setup.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup.py b/setup.py index 4e3c30df9..e99db79a6 100644 --- a/setup.py +++ b/setup.py @@ -71,6 +71,10 @@ else: install_requires.append("networkx>=2.1") # Extra dependencies for remote integrations + +# Restricting google-resumable-media version is due to fact that +# since 0.3.3 our builds for Linux and MacOs started to fail. This restriction +# is temporary and should be removed ASAP gs = ["google-resumable-media==0.3.2", "google-cloud-storage==1.13.0"] s3 = ["boto3==1.9.115"] azure = ["azure-storage-blob==2.1.0"] From 48ac0b7c27f26e730eff4228804ee125b4d52a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Fri, 30 Aug 2019 18:13:40 +0200 Subject: [PATCH 35/37] Update setup.py Co-Authored-By: Ruslan Kuprieiev --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e99db79a6..9f73a200e 100644 --- a/setup.py +++ b/setup.py @@ -72,7 +72,7 @@ else: # Extra dependencies for remote integrations -# Restricting google-resumable-media version is due to fact that +# Restricting google-resumable-media version is due to the fact that # since 0.3.3 our builds for Linux and MacOs started to fail. This restriction # is temporary and should be removed ASAP gs = ["google-resumable-media==0.3.2", "google-cloud-storage==1.13.0"] From bd04972e9e4115d0658f3ec3239cf105bb34509c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Fri, 30 Aug 2019 18:13:49 +0200 Subject: [PATCH 36/37] Update setup.py Co-Authored-By: Ruslan Kuprieiev --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9f73a200e..ef9255426 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ else: # Extra dependencies for remote integrations # Restricting google-resumable-media version is due to the fact that -# since 0.3.3 our builds for Linux and MacOs started to fail. This restriction +# since 0.3.3 our binaries built by pyinstaller started to fail on Linux and macOS. This restriction will be removed after https://github.com/iterative/dvc/issues/2441 is resolved. # is temporary and should be removed ASAP gs = ["google-resumable-media==0.3.2", "google-cloud-storage==1.13.0"] s3 = ["boto3==1.9.115"] From 331ab8c983c83c41fdca3c1960ceed24a62cfa52 Mon Sep 17 00:00:00 2001 From: pawel Date: Fri, 30 Aug 2019 18:29:35 +0200 Subject: [PATCH 37/37] refactor note --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ef9255426..83db8b3fb 100644 --- a/setup.py +++ b/setup.py @@ -73,8 +73,9 @@ else: # Extra dependencies for remote integrations # Restricting google-resumable-media version is due to the fact that -# since 0.3.3 our binaries built by pyinstaller started to fail on Linux and macOS. This restriction will be removed after https://github.com/iterative/dvc/issues/2441 is resolved. -# is temporary and should be removed ASAP +# since 0.3.3 our binaries built by pyinstaller started to fail on Linux and +# macOS. This restriction will be removed after +# https://github.com/iterative/dvc/issues/2441 is resolved. gs = ["google-resumable-media==0.3.2", "google-cloud-storage==1.13.0"] s3 = ["boto3==1.9.115"] azure = ["azure-storage-blob==2.1.0"]