Repository: iterative/dvc
Pull request: version: improve link type detection fall back
Create temporary file in cache dir. And use it to detect the supported cache types. Clear after cache type detection.

Fixes #2788

Problem statement:
version: improve link type detection fall back
**To reproduce:**

`dvc version` outside of any DVC repo.

**Output:**

```WARNING: Unable to detect supported link types, as cache directory '.dvc/cache' doesn't exist. It is usually auto-created by commands such as `dvc add/fetch/pull/run/import`, but you could create it manually to enable this check.```

It should instead generate a regular output and either omit the link type completely or print some special value "link: (run inside repo)"

Hints from issue discussion:
@shcheklein , I couldn't reproduce the issue with the following script: 

```bash
mkdir /tmp/example
cd /tmp/example
python3.7 -m venv .venv
source .venv/bin/activate
pip install dvc
dvc version
```

@ptrcklv , could you provide a reproduction script?
@mroutis me neither! And from the code perspective I don't see a bug. It might be I had a `.dvc` somewhere in the `~` (you know it happens from time to time when you do `dvc init` at the very top) - this is the only explanation that comes to my mind.

@shcheklein , @ptrcklv can we close this issue then? :slightly_smiling_face: 
True, does not occur in arbitrary test dir. I could reproduce the error when I ran dvc version in my local dvc repo, i.e. in a code directory. Actually it is not a dvc repo but there is a .dvc folder, which fooled me, too.  
:eyes: what about using Zsh @shcheklein , @ptrcklv? you can do cool things like the following:


[![asciicast](https://asciinema.org/a/UpDazXtHsyDl9FqNCT1HOre0Z.svg)](https://asciinema.org/a/UpDazXtHsyDl9FqNCT1HOre0Z)

any suggestions on how to leverage this? I didn't want to add `dvc --version` because it can take quite some time to compute (_no bueno_)
@shcheklein , @ptrcklv can you go to the referenced PR on `spaceship-prompt` and add your comments? (e.g. _"this is not needed, please, close it immediately"_, _"neat, but won't use"_, etc.)
@ptrcklv 

> Actually it is not a dvc repo but there is a .dvc folder, which fooled me, too.

Is that `.dvc` directory a leftover from some experiments or is a coincidence and you had it even before `.dvc`?
@mroutis I think to the most part it's an UI ticket, we should just update the message to be more explicit:

"Unable to detect supported link types. You run this command inside DVC repo (`.dvc` exists) but it looks it has been just initialized as cache directory ("show here actual path to the cache dir from config") does not exist yet. It is usually auto-created by commands such as `dvc add/fetch/pull/run/import`, but you could create it manually to enable this check. "

It can be the second example for the Troubleshooting cc @jorgeorpinel and we can simplify a message and put a link to the command reference ... I even think if we need to introduce a short-cut similar to `man.dvc.org` - like `error.dvc.org\<code>` that redirects to the Troubleshooting section with a specific error.
> @ptrcklv
> 
> > Actually it is not a dvc repo but there is a .dvc folder, which fooled me, too.
> 
> Is that `.dvc` directory a leftover from some experiments or is a coincidence and you had it even before `.dvc`?

No it's the .dvc which is on the dvc master branch. I did your reproduction steps from the very first comment in this issue in my local dvc repo folder (coincidently had been there already). I was not aware of that .dvc folder there, so I got fooled since I thought i was not in a DVC repo. In a clean test folder I could also not reproduce the issue.

Commit message: version: improve link type detection fall back

If failed to determine cache type print link to related web page.

Fixes #2788

Patch to review:
diff --git a/dvc/command/version.py b/dvc/command/version.py
index 79452c6d33..a900ef6f01 100644
--- a/dvc/command/version.py
+++ b/dvc/command/version.py
@@ -10,7 +10,7 @@
 from dvc.exceptions import DvcException, NotDvcRepoError
 from dvc.scm.base import SCMError
 from dvc.system import System
-from dvc.utils import relpath
+from dvc.utils import error_link
 from dvc.utils.pkg import PKG
 from dvc.version import __version__
 
@@ -59,12 +59,8 @@ def run(self):
                     fs_type = self.get_fs_type(repo.cache.local.cache_dir)
                     info.append(f"Cache directory: {fs_type}")
             else:
-                logger.warning(
-                    "Unable to detect supported link types, as cache "
-                    "directory '{}' doesn't exist. It is usually auto-created "
-                    "by commands such as `dvc add/fetch/pull/run/import`, "
-                    "but you could create it manually to enable this "
-                    "check.".format(relpath(repo.cache.local.cache_dir))
+                info.append(
+                    "Cache types: " + error_link("unable-to-detect-cache-type")
                 )
 
         except NotDvcRepoError:


Code review comments:
diff_hunk: @@ -59,12 +59,8 @@ def run(self):
                     fs_type = self.get_fs_type(repo.cache.local.cache_dir)
                     info.append(f"Cache directory: {fs_type}")
             else:
-                logger.warning(
-                    "Unable to detect supported link types, as cache "
-                    "directory '{}' doesn't exist. It is usually auto-created "
-                    "by commands such as `dvc add/fetch/pull/run/import`, "
-                    "but you could create it manually to enable this "
-                    "check.".format(relpath(repo.cache.local.cache_dir))
+                info.append(
+                    "Cache types: " + error_link("unable-to-detect-cache-type")
path: dvc/command/version.py
text: @user1:
```suggestion
                    "Cache types: " + error_link("no-dvc-cache")
```

diff_hunk: @@ -59,12 +59,8 @@ def run(self):
                     fs_type = self.get_fs_type(repo.cache.local.cache_dir)
                     info.append(f"Cache directory: {fs_type}")
             else:
-                logger.warning(
-                    "Unable to detect supported link types, as cache "
-                    "directory '{}' doesn't exist. It is usually auto-created "
-                    "by commands such as `dvc add/fetch/pull/run/import`, "
-                    "but you could create it manually to enable this "
-                    "check.".format(relpath(repo.cache.local.cache_dir))
+                info.append(
+                    "Cache types: " + error_link("unable-to-detect-cache-type")
path: dvc/command/version.py
text: @user1:
Hi! Should some info on what the problem is be presented to the user at least? Other than just `Cache types: http://error...` Maybe I'm not seeing the full output just from this code.

@user1:
Also could we shorten the link path a bit? Maybe `"no-dvc-cache"`

@user1:
(Please see also https://github.com/iterative/dvc.org/pull/1751#pullrequestreview-480112616.)

@user2:
@user1 Adding more info will defeat the purpose of this PR, will make the desc too long.