etiennebacher / altdoc

Alternative to pkgdown to document R packages
https://altdoc.etiennebacher.com
Other
62 stars 9 forks source link

mkdocs: more informative virtual environment message #248

Closed vincentarelbundock closed 7 months ago

vincentarelbundock commented 7 months ago

I was a bit confused by the error message about virtual environment for mkdocs, because it seemed like I did not in fact need to activate the environment, because altdoc took care of it automatically.

Here's a proposal for a more informative message. Note that the code is not enclosed in backticks. This allows users to select/copy/paste the lines from the error message directly in their consoles instead of typing them manually.

Error:
✖ `altdoc` needs `mkdocs` to be installed in a Python virtual environment. The best way to create the
  required `.venv_altdoc` directory depends on your development environment. On a unix-like system, it usually
  involves executing these commands from the root directory of your R package:

  python -m venv .venv_altdoc
  .venv_altdoc/bin/pip install mkdocs mkdocs-material

ℹ You can learn more at this link: <https://docs.python.org/3/library/venv.html#how-venvs-work>.
Run `rlang::last_trace()` to see where the error occurred.
vincentarelbundock commented 7 months ago

I did not dive deep into this code, and I'm not great with Python environments, so I'll wait for @etiennebacher to take a look before merging.

etiennebacher commented 7 months ago

I'm also not an expert on venv so I don't know how this will behave on Windows. Overall, I'd like to show the code to copy-paste only if we can provide it for all OS, not just Unix-like.

I can try on windows in a couple of days

etiennebacher commented 7 months ago

The second line doesn't work on Windows, it should be this instead:

.venv_altdoc\Scripts\pip.exe install mkdocs mkdocs-material

You can use .is_windows() to show one or the other depending on the user's OS (or show both like "if you are on Windows, use this, and if you are on Unix, use that". I don't have strong opinions on that).