Move Wincmd and Virtualenv docs from reST to MyST (#2954)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rowlando13 · committed by GitHub · parents f9c1b88, 60b9c0e · Browse files · 4 files·+105 added−118 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+105 added−118 removed
- other:+105 added−118 removed
Provenance
- Commit
499bbee- Tree
ef9accf- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
f9c1b88- Parent 2
60b9c0e
4 files changed+105 added−118 removed
added:docs/virtualenv.md+58 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758(virtualenv-heading)=
# Virtualenv
## Why Use Virtualenv?
You should use [Virtualenv](https://virtualenv.pypa.io/en/latest/) because:
- It allows you to install multiple versions of the same dependency.- If you have an operating system version of Python, it prevents you from changing its dependencies and potentially messing up your os.
## How to Use Virtualenv
Create your project folder, then a virtualenv within it:
```console$ mkdir myproject$ cd myproject$ python3 -m venv .venv```
Now, whenever you want to work on a project, you only have to activate the corresponding environment.
```{eval-rst}.. tabs::
.. group-tab:: OSX/Linux
.. code-block:: text
$ . .venv/bin/activate (venv) $
.. group-tab:: Windows
.. code-block:: text
> .venv\scripts\activate (venv) >```
You are now using your virtualenv (notice how the prompt of your shell has changed to show the active environment).
To install packages in the virtual environment:
```console$ pip install click```
And if you want to stop using the virtualenv, use the following command:
```console$ deactivate```
After doing this, the prompt of your shell should be as familiar as before.deleted:docs/virtualenv.rst-54 removed
1-.. _virtualenv-heading:2-3-Virtualenv4-=========================5-6-Why Use Virtualenv?7--------------------------8-9-You should use `Virtualenv <https://virtualenv.pypa.io/en/latest/>`_ because:10-11-* It allows you to install multiple versions of the same dependency.12-13-* If you have an operating system version of Python, it prevents you from changing its dependencies and potentially messing up your os.14-15-How to Use Virtualenv16------------------------------17-18-Create your project folder, then a virtualenv within it::19-20- $ mkdir myproject21- $ cd myproject22- $ python3 -m venv .venv23-24-Now, whenever you want to work on a project, you only have to activate the25-corresponding environment.26-27-.. tabs::28-29- .. group-tab:: OSX/Linux30-31- .. code-block:: text32-33- $ . .venv/bin/activate34- (venv) $35-36- .. group-tab:: Windows37-38- .. code-block:: text39-40- > .venv\scripts\activate41- (venv) >42-43-44-You are now using your virtualenv (notice how the prompt of your shell has changed to show the active environment).45-46-To install packages in the virtual environment::47-48- $ pip install click49-50-And if you want to stop using the virtualenv, use the following command::51-52- $ deactivate53-54-After doing this, the prompt of your shell should be as familiar as before.added:docs/wincmd.md+47 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647# Windows Console Notes
```{versionadded} 6.0```
Click emulates output streams on Windows to support unicode to the Windows console through separate APIs and we performdifferent decoding of parameters.
Here is a brief overview of how this works and what it means to you.
## Unicode Arguments
Click internally is generally based on the concept that any argument can come in as either byte string or unicode stringand conversion is performed to the type expected value as late as possible. This has some advantages as it allows us toaccept the data in the most appropriate form for the operating system and Python version.
This caused some problems on Windows where initially the wrong encoding was used and garbage ended up in your inputdata. We not only fixed the encoding part, but we also now extract unicode parameters from `sys.argv`.
There is also another limitation with this: if `sys.argv` was modified prior to invoking a click handler, we have tofall back to the regular byte input in which case not all unicode values are available but only a subset of the codepageused for parameters.
## Unicode Output and Input
Unicode output and input on Windows is implemented through the concept of a dispatching text stream. What this means isthat when click first needs a text output (or input) stream on windows it goes through a few checks to figure out of awindows console is connected or not. If no Windows console is present then the text output stream is returned as suchand the encoding for that stream is set to `utf-8` like on all platforms.
However if a console is connected the stream will instead be emulated and use the cmd.exe unicode APIs to output textinformation. In this case the stream will also use `utf-16-le` as internal encoding. However there is some hackery goingon that the underlying raw IO buffer is still bypassing the unicode APIs and byte output through an indirection is stillpossible.
- This unicode support is limited to `click.echo`, `click.prompt` as well as `click.get_text_stream`.- Depending on if unicode values or byte strings are passed the control flow goes completely different places internally which can have some odd artifacts if data partially ends up being buffered. Click attempts to protect against that by manually always flushing but if you are mixing and matching different string types to `stdout` or `stderr` you will need to manually flush.- The raw output stream is set to binary mode, which is a global operation on Windows, so `print` calls will be affected. Prefer `click.echo` over `print`.- On Windows 7 and below, there is a limitation where at most 64k characters can be written in one call in binary mode. In this situation, `sys.stdout` and `sys.stderr` are replaced with wrappers that work around the limitation.
Another important thing to note is that the Windows console's default fonts do not support a lot of characters whichmeans that you are mostly limited to international letters but no emojis or special characters.deleted:docs/wincmd.rst-64 removed
1-Windows Console Notes2-=====================3-4-.. versionadded:: 6.05-6-Click emulates output streams on Windows to support unicode to the7-Windows console through separate APIs and we perform different decoding of8-parameters.9-10-Here is a brief overview of how this works and what it means to you.11-12-Unicode Arguments13------------------14-15-Click internally is generally based on the concept that any argument can16-come in as either byte string or unicode string and conversion is17-performed to the type expected value as late as possible. This has some18-advantages as it allows us to accept the data in the most appropriate form19-for the operating system and Python version.20-21-This caused some problems on Windows where initially the wrong encoding22-was used and garbage ended up in your input data. We not only fixed the23-encoding part, but we also now extract unicode parameters from `sys.argv`.24-25-There is also another limitation with this: if `sys.argv` was modified26-prior to invoking a click handler, we have to fall back to the regular27-byte input in which case not all unicode values are available but only a28-subset of the codepage used for parameters.29-30-Unicode Output and Input31-------------------------32-33-Unicode output and input on Windows is implemented through the concept of34-a dispatching text stream. What this means is that when click first needs35-a text output (or input) stream on windows it goes through a few checks to36-figure out of a windows console is connected or not. If no Windows37-console is present then the text output stream is returned as such and the38-encoding for that stream is set to ``utf-8`` like on all platforms.39-40-However if a console is connected the stream will instead be emulated and41-use the cmd.exe unicode APIs to output text information. In this case the42-stream will also use ``utf-16-le`` as internal encoding. However there is43-some hackery going on that the underlying raw IO buffer is still bypassing44-the unicode APIs and byte output through an indirection is still possible.45-46-* This unicode support is limited to ``click.echo``, ``click.prompt`` as47- well as ``click.get_text_stream``.48-* Depending on if unicode values or byte strings are passed the control49- flow goes completely different places internally which can have some50- odd artifacts if data partially ends up being buffered. Click51- attempts to protect against that by manually always flushing but if52- you are mixing and matching different string types to ``stdout`` or53- ``stderr`` you will need to manually flush.54-* The raw output stream is set to binary mode, which is a global55- operation on Windows, so ``print`` calls will be affected. Prefer56- ``click.echo`` over ``print``.57-* On Windows 7 and below, there is a limitation where at most 64k58- characters can be written in one call in binary mode. In this59- situation, ``sys.stdout`` and ``sys.stderr`` are replaced with60- wrappers that work around the limitation.61-62-Another important thing to note is that the Windows console's default63-fonts do not support a lot of characters which means that you are mostly64-limited to international letters but no emojis or special characters.