From ce83231128d77f3c2c8f8c55f9baf77db0e5493a Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Fri, 24 May 2019 16:00:47 -0500 Subject: [PATCH] Updates to 1. zsh autocomplete script and 2. slow link type warning message (#2003) * Document dvc.scm.git::Git::_get_diff_trees and shorten commit hashes in dvc.scm.git::Git::get_diff_trees * diff: Changes to dvc.scm.git so `dvc diff` outputs short SHAs - Docstring for Git class constructor - Renames self.git for self.repo throughout module (involves several test changes) - Better doc and logical refactor in Git._get_diff_trees - `dvc diff` now outputs short SHA strings (Git._get_diff_trees) - hard coded to 7 length str (involves some test changes in tests/func/test_diff.py) For #1902 * Undoes "Renames self.git for self.repo throughout module" introduced in 3d2dc83. * autocomplete: Brings scripts/completion/dvc.zsh up-to-date - Reorganizes commands in alphabetical order; - Updates the command dscriptions according to their current usage (-h) output; - Adds comments for MISSING command entries * Update scripts/completion/dvc.zsh Co-Authored-By: Ruslan Kuprieiev * Update scripts/completion/dvc.zsh Co-Authored-By: Ruslan Kuprieiev * Update scripts/completion/dvc.zsh Co-Authored-By: Ruslan Kuprieiev * Update scripts/completion/dvc.zsh Co-Authored-By: Ruslan Kuprieiev * autocomplete: Adds missing commands to Zsh script * cache: updates slow link type warning message (and test) in accordance with https://github.com/iterative/dvc.org/pull/331 * Fixes accidental docstring rewrap per https://github.com/iterative/dvc/pull/2003#discussion_r286206870 * Actually fixes accidental docstring rewrap... per https://github.com/iterative/dvc/pull/2003#pullrequestreview-240994592 * Really fixes accidental docstring rewrap this time... --- dvc/remote/local/slow_link_detection.py | 11 +- dvc/scm/git/__init__.py | 16 +- scripts/completion/dvc.zsh | 285 +++++++++--------- tests/unit/remote/test_slow_link_detection.py | 11 +- 4 files changed, 165 insertions(+), 158 deletions(-) diff --git a/dvc/remote/local/slow_link_detection.py b/dvc/remote/local/slow_link_detection.py index 7af62f815..2a197f8d7 100644 --- a/dvc/remote/local/slow_link_detection.py +++ b/dvc/remote/local/slow_link_detection.py @@ -31,13 +31,12 @@ class SlowLinkDetectorDecorator(object): and self.should_display() ): msg = ( - "You can cut execution time considerably. Check:\n" + "You can cut execution time considerably by using a different" + " `cache.type` configuration.\nSee " "{blue}https://dvc.org/doc/commands-reference/config#cache{" - "reset}" - "\nfor " - "more information.\nTo disable this message, run:\n'dvc " - "config " - "cache.slow_link_warning False'".format( + "reset} for more information.\n" + "To disable this message, run:\n" + "'dvc config cache.slow_link_warning false'".format( blue=colorama.Fore.BLUE, reset=colorama.Fore.RESET ) ) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 04e14f336..3522f74d0 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -260,15 +260,14 @@ class Git(Base): def _get_diff_trees(self, a_ref, b_ref): """Private method for getting the trees and commit hashes of 2 git - references. - Requires `gitdb` module (from gitpython package). + references. Requires `gitdb` module (from gitpython package). Args: - a_ref(str) - git reference - b_ref(str) - second git reference. If None, uses HEAD + a_ref (str): git reference + b_ref (str): second git reference. If None, uses HEAD Returns: - tuple - tuple with elements: (trees, commits) + tuple: tuple with elements: (trees, commits) """ from gitdb.exc import BadObject, BadName @@ -294,11 +293,12 @@ class Git(Base): Returns the dvc hash names of changed file/directory Args: - a_ref(str) - git reference - b_ref(str) - optional second git reference, default None + a_ref (str): git reference + b_ref (str): optional second git reference, default None Returns: - dict - dictionary with keys: (a_tree, b_tree, a_ref, b_ref, equal) + dict: dictionary with keys: (a_tree, b_tree, a_ref, b_ref, + equal) """ diff_dct = {DIFF_EQUAL: False} trees, commits = self._get_diff_trees(a_ref, b_ref) diff --git a/scripts/completion/dvc.zsh b/scripts/completion/dvc.zsh index f7d71f3f5..4ceef21b9 100644 --- a/scripts/completion/dvc.zsh +++ b/scripts/completion/dvc.zsh @@ -12,30 +12,33 @@ _dvc_commands() { local _commands=( - "init:Initialize dvc over a directory (should already be a git dir)." - "destroy:Destroy dvc. Will remove all project's information, data files and cache." - "add:Add files/directories to dvc." - "import:Import files from URL." + "add:Take data files or directories under DVC control." + "cache:Manage cache settings." "checkout:Checkout data files from cache." - "run:Generate a stage file from a given command and execute the command." - "pull:Pull data files from the cloud." - "push:Push data files to the cloud." - "fetch:Fetch data files from the cloud." - "status:Show the project status." - "repro:Reproduce DVC file. Default file name - 'Dvcfile'." - "remove:Remove outputs of DVC file." - "move:Move output of DVC file." - "unprotect:Unprotect data file/directory." - "gc:Collect garbage." - "config:Get or set config options." - "remote:Manage set of tracked repositories." - "metrics:Get metrics from all branches." - "install:Install dvc hooks into the repository." - "root:Relative path to project's directory." + "commit:Save changed data to cache and update DVC files." + "config:Get or set config settings." + "destroy:Remove DVC files, local DVC config and data cache." + "diff:Show a diff of a DVC controlled data file or a directory." + "fetch:Fetch data files from a DVC remote storage." + "gc:Collect unused data from DVC cache or a remote storage." + "import:Download or copy files from URL and take under DVC control." + "init:Initialize DVC in the current directory." + "install:Install DVC git hooks into the repository." "lock:Lock DVC file." + "metrics:Commands to add, manage, collect and display metrics." + "move:Rename or move a DVC controlled data file or a directory." + "pipeline:Manage pipelines." + "pull:Pull data files from a DVC remote storage." + "push:Push data files to a DVC remote storage." + "remote:Manage remote storage configuration." + "remove:Remove outputs of DVC file." + "repro:Check for changes and reproduce DVC file and dependencies." + "root:Relative path to project's directory." + "run:Generate a stage file from a command and execute the command." + "status:Show changed stages, compare local cache and a remote storage." "unlock:Unlock DVC file." - "pipeline:Manage pipeline." - "commit:Record changes to the repository." + "unprotect:Unprotect data file/directory." + "version:Show DVC version and system/environment informaion." ) _describe 'dvc commands' _commands @@ -52,15 +55,6 @@ _dvc_options=( "(-)"{-v,--version}"[Show program's version]" ) -_dvc_init=( - "--no-scm[Initiate dvc in directory that is not tracket by any scm tool]" - {-f,--force}"[Overwrite '.dvc' if it exists. Will remove all local cache.]" -) - -_dvc_destroy=( - {-f,--force}"[Overwrite '.dvc' if it exists. Will remove all local cache.]" -) - _dvc_add=( {-R,--recursive}"[Recursively add each file under the directory.]" {-f,--file}"[Specify name of the stage file.]:File:_files" @@ -68,10 +62,8 @@ _dvc_add=( "1:File:_files" ) -_dvc_import=( - "--resume[Resume previously started download.]" - "1:URL:" - "2:Output:" +_dvc_cache=( + "1:Sub command:(dir)" ) _dvc_checkout=( @@ -80,24 +72,77 @@ _dvc_checkout=( "1:Stages:_files -g '(*.dvc|Dvcfile)'" ) -_dvc_unprotect=( - "*:Data files:_files" +_dvc_commit=( + "*:Stages:_files -g '(*.dvc|Dvcfile)'" + {-d,--with-deps}"[Commit all dependencies of the specified target.]" + {-f,--force}"[Commit even if checksums for dependencies/outputs changed.]" + {-R,--recursive}"[Commit cache for subdirectories of the specified directory.]" ) -_dvc_run=( - "--no-exec[Only create stage file without actually running it.]" - "--overwrite-dvcfile[Overwrite existing dvc file without asking for confirmation.]" - "--ignore-build-cache[Run this stage even if it has been already ran with the same command/dependencies/outputs/etc before.]" - "--no-commit[Don't put files/directories into cache.]" - {-f,--file}"[Specify name of the stage file.]:File:_files" - {-c,--cwd}"[Deprecated, use -w and -f instead.]:CWD:_files -/" - {-w,--wdir}"[Directory to run your command and place state file in.]:WDIR:_files -/" - "*"{-d,--deps}"[Declare dependencies for reproducible cmd.]:Dependency:_files" - "*"{-o,--outs}"[Declare output data file or data directory.]:Output data:_files" - "*"{-O,--outs-no-cache}"[Declare output regular file or directory.]:Output regular:_files" - "*"{-M,--metrics-no-cache}"[Declare output metric file or directory (do not put into DVC cache)]:Metrics (no cache):_files" - "*"{-m,--metrics}"[Declare output metric file or directory]:Metrics:_files" - {-y,--yes}"[Automatic 'yes' answer to all prompts.]" +_dvc_config=( + {-u,--unset}"[Unset option.]" + "--local[Unset option.]" + "--system[Use system config.]" + "--global[Use global config.]" +) + +_dvc_destroy=( + {-f,--force}"[Overwrite '.dvc' if it exists. Will remove all local cache.]" +) + +_dvc_diff=( + {-t,--target}"[Source path to a data file or directory.]:Target file(s):" +) + +_dvc_fetch=( + "*:Stages:_files -g '(*.dvc|Dvcfile)'" + "--show-checksums[Show checksums instead of file names]" + {-j,--jobs}"[Number of jobs to run simultaneously]:Number of jobs:" + {-r,--remote}"[Remote repository to pull from]:Remote repository:" + {-a,--all-branches}"[Fetch cache for all branches]" + {-T,--all-tags}"[Fetch cache for all tags]" + {-d,--with-deps}"[Fetch cache for all dependencies of the specified target]" + {-R,--recursive}"[Fetch cache for subdirectories of the specified directory.]" +) + +_dvc_gc=( + {-a,--all-branches}"[Collect garbage for all branches]" + {-T,--all-tags}"[Collect garbage for all tags]" + {-c,--cloud}"[Collect garbage in remote repository]" + {-r,--remote}"[Remote repository to collect garbage in]:Remote repository:" + {-f,--force}"[Force garbage collection - automatically agree to all prompts.]" + + {-p,--projects}"[Keep data files required by these projects in addition to the current one. Useful if you share a single cache across repos.]:Repos:_files" +) + +_dvc_import=( + "--resume[Resume previously started download.]" + "1:URL:" + "2:Output:" +) + +_dvc_init=( + "--no-scm[Initiate dvc in directory that is not tracket by any scm tool]" + {-f,--force}"[Overwrite '.dvc' if it exists. Will remove all local cache.]" +) + +_dvc_install=() + +_dvc_lock=( + "*:Stages:_files -g '(*.dvc|Dvcfile)'" +) + +_dvc_metrics=( + "1:Sub command:(show add modify remove)" +) + +_dvc_move=( + "1:Source:_files" + "2:Destination:" +) + +_dvc_pipeline=( + "1:Sub command:(show,list)" ) _dvc_pull=( @@ -123,27 +168,16 @@ _dvc_push=( {-R,--recursive}"[Push cache for subdirectories of the specified directory.]" ) -_dvc_fetch=( - "*:Stages:_files -g '(*.dvc|Dvcfile)'" - "--show-checksums[Show checksums instead of file names]" - {-j,--jobs}"[Number of jobs to run simultaneously]:Number of jobs:" - {-r,--remote}"[Remote repository to pull from]:Remote repository:" - {-a,--all-branches}"[Fetch cache for all branches]" - {-T,--all-tags}"[Fetch cache for all tags]" - {-d,--with-deps}"[Fetch cache for all dependencies of the specified target]" - {-R,--recursive}"[Fetch cache for subdirectories of the specified directory.]" +_dvc_remote=( + "1:Sub command:(add default remove modify list)" ) -_dvc_status=( +_dvc_remove=( "*:Stages:_files -g '(*.dvc|Dvcfile)'" - "--show-checksums[Show checksums instead of file names]" - {-j,--jobs}"[Number of jobs to run simultaneously]:Number of jobs:" - {-r,--remote}"[Remote repository to pull from]:Remote repository:" - {-a,--all-branches}"[Fetch cache for all branches]" - {-T,--all-tags}"[Fetch cache for all tags]" - {-d,--with-deps}"[Fetch cache for all dependencies of the specified target]" - {-c,--cloud}"[Show status of a local cache compared to a remote repository]" - {-q,--quiet}"[Suppresses all output. Exit with 0 if pipeline is up]" + "--dry[Only print the commands that would be executed without actually executing]" + {-o,--outs}"[Only remove DVC file outputs.(default)]" + {-p,--purge}"[Remove DVC file and all its outputs]" + {-f,--force}"[Force purge.]" ) _dvc_repro=( @@ -160,69 +194,42 @@ _dvc_repro=( {-d,--downstream}"[Reproduce the pipeline starting from the specified stage.]" ) -_dvc_remove=( - "*:Stages:_files -g '(*.dvc|Dvcfile)'" - "--dry[Only print the commands that would be executed without actually executing]" - {-o,--outs}"[Only remove DVC file outputs.(default)]" - {-p,--purge}"[Remove DVC file and all its outputs]" - {-f,--force}"[Force purge.]" -) - -_dvc_move=( - "1:Source:_files" - "2:Destination:" -) - -_dvc_gc=( - {-a,--all-branches}"[Collect garbage for all branches]" - {-T,--all-tags}"[Collect garbage for all tags]" - {-c,--cloud}"[Collect garbage in remote repository]" - {-r,--remote}"[Remote repository to collect garbage in]:Remote repository:" - {-f,--force}"[Force garbage collection - automatically agree to all prompts.]" - - {-p,--projects}"[Keep data files required by these projects in addition to the current one. Useful if you share a single cache across repos.]:Repos:_files" -) - -_dvc_config=( - {-u,--unset}"[Unset option.]" - "--local[Unset option.]" - "--system[Use system config.]" - "--global[Use global config.]" -) - -_dvc_remote=( - "1:Sub command:(add default remove modify list)" -) - -_dvc_cache=( - "1:Sub command:(dir)" -) - -_dvc_metrics=( - "1:Sub command:(show add modify remove)" -) - -_dvc_install=() - _dvc_root=() -_dvc_lock=( +_dvc_run=( + "--no-exec[Only create stage file without actually running it.]" + "--overwrite-dvcfile[Overwrite existing dvc file without asking for confirmation.]" + "--ignore-build-cache[Run this stage even if it has been already ran with the same command/dependencies/outputs/etc before.]" + "--no-commit[Don't put files/directories into cache.]" + {-f,--file}"[Specify name of the stage file.]:File:_files" + {-c,--cwd}"[Deprecated, use -w and -f instead.]:CWD:_files -/" + {-w,--wdir}"[Directory to run your command and place state file in.]:WDIR:_files -/" + "*"{-d,--deps}"[Declare dependencies for reproducible cmd.]:Dependency:_files" + "*"{-o,--outs}"[Declare output data file or data directory.]:Output data:_files" + "*"{-O,--outs-no-cache}"[Declare output regular file or directory.]:Output regular:_files" + "*"{-M,--metrics-no-cache}"[Declare output metric file or directory (do not put into DVC cache)]:Metrics (no cache):_files" + "*"{-m,--metrics}"[Declare output metric file or directory]:Metrics:_files" + {-y,--yes}"[Automatic 'yes' answer to all prompts.]" +) + +_dvc_status=( "*:Stages:_files -g '(*.dvc|Dvcfile)'" + "--show-checksums[Show checksums instead of file names]" + {-j,--jobs}"[Number of jobs to run simultaneously]:Number of jobs:" + {-r,--remote}"[Remote repository to pull from]:Remote repository:" + {-a,--all-branches}"[Fetch cache for all branches]" + {-T,--all-tags}"[Fetch cache for all tags]" + {-d,--with-deps}"[Fetch cache for all dependencies of the specified target]" + {-c,--cloud}"[Show status of a local cache compared to a remote repository]" + {-q,--quiet}"[Suppresses all output. Exit with 0 if pipeline is up]" ) _dvc_unlock=( "*:Stages:_files -g '(*.dvc|Dvcfile)'" ) -_dvc_pipeline=( - "1:Sub command:(show,list)" -) - -_dvc_commit=( - "*:Stages:_files -g '(*.dvc|Dvcfile)'" - {-d,--with-deps}"[Commit all dependencies of the specified target.]" - {-f,--force}"[Commit even if checksums for dependencies/outputs changed.]" - {-R,--recursive}"[Commit cache for subdirectories of the specified directory.]" +_dvc_unprotect=( + "*:Data files:_files" ) typeset -A opt_args @@ -234,28 +241,30 @@ _arguments \ '*::args:->args' case $words[1] in - init) _arguments $_dvc_global_options $_dvc_init ;; - destroy) _arguments $_dvc_global_options $_dvc_destroy ;; add) _arguments $_dvc_global_options $_dvc_add ;; - import) _arguments $_dvc_global_options $_dvc_import ;; + cache) _arguments $_dvc_global_options $_dvc_cache ;; checkout) _arguments $_dvc_global_options $_dvc_checkout ;; - run) _arguments $_dvc_global_options $_dvc_run ;; + commit) _arguments $_dvc_global_options $_dvc_commit ;; + config) _arguments $_dvc_global_options $_dvc_config ;; + destroy) _arguments $_dvc_global_options $_dvc_destroy ;; + diff) _arguments $_dvc_global_options $_dvc_diff ;; + fetch) _arguments $_dvc_global_options $_dvc_fetch ;; + gc) _arguments $_dvc_global_options $_dvc_gc ;; + import) _arguments $_dvc_global_options $_dvc_import ;; + init) _arguments $_dvc_global_options $_dvc_init ;; + install) _arguments $_dvc_global_options $_dvc_install ;; + lock) _arguments $_dvc_global_options $_dvc_lock ;; + metrics) _arguments $_dvc_global_options $_dvc_metrics ;; + move) _arguments $_dvc_global_options $_dvc_move ;; + pipeline) _arguments $_dvc_global_options $_dvc_pipeline ;; pull) _arguments $_dvc_global_options $_dvc_pull ;; push) _arguments $_dvc_global_options $_dvc_push ;; - fetch) _arguments $_dvc_global_options $_dvc_fetch ;; - status) _arguments $_dvc_global_options $_dvc_status ;; - repro) _arguments $_dvc_global_options $_dvc_repro ;; - remove) _arguments $_dvc_global_options $_dvc_remove ;; - move) _arguments $_dvc_global_options $_dvc_move ;; - gc) _arguments $_dvc_global_options $_dvc_gc ;; - config) _arguments $_dvc_global_options $_dvc_config ;; remote) _arguments $_dvc_global_options $_dvc_remote ;; - metrics) _arguments $_dvc_global_options $_dvc_metrics ;; - install) _arguments $_dvc_global_options $_dvc_install ;; + remove) _arguments $_dvc_global_options $_dvc_remove ;; + repro) _arguments $_dvc_global_options $_dvc_repro ;; root) _arguments $_dvc_global_options $_dvc_root ;; - lock) _arguments $_dvc_global_options $_dvc_lock ;; + run) _arguments $_dvc_global_options $_dvc_run ;; + status) _arguments $_dvc_global_options $_dvc_status ;; unlock) _arguments $_dvc_global_options $_dvc_unlock ;; - pipeline) _arguments $_dvc_global_options $_dvc_pipeline ;; - commit) _arguments $_dvc_global_options $_dvc_commit ;; unprotect) _arguments $_dvc_global_options $_dvc_unprotect ;; esac diff --git a/tests/unit/remote/test_slow_link_detection.py b/tests/unit/remote/test_slow_link_detection.py index e6c846582..3b981e69e 100644 --- a/tests/unit/remote/test_slow_link_detection.py +++ b/tests/unit/remote/test_slow_link_detection.py @@ -89,13 +89,12 @@ class TestSlowLinkDetectorDecorator(object): assert self.method_result_mock == result msg = ( - "You can cut execution time considerably. Check:\n" + "You can cut execution time considerably by using a different" + " `cache.type` configuration.\nSee " "{blue}https://dvc.org/doc/commands-reference/config#cache{" - "reset}" - "\nfor " - "more information.\nTo disable this message, run:\n'dvc " - "config " - "cache.slow_link_warning False'".format( + "reset} for more information.\n" + "To disable this message, run:\n" + "'dvc config cache.slow_link_warning false'".format( blue=colorama.Fore.BLUE, reset=colorama.Fore.RESET ) )