diff --git a/docs/cli_interface.rst b/docs/cli_interface.rst index 3994074f5..7f5513ffd 100644 --- a/docs/cli_interface.rst +++ b/docs/cli_interface.rst @@ -71,21 +71,18 @@ variable ``VIRTUALENV_PYTHON`` like: env VIRTUALENV_PYTHON=/opt/python-3.8/bin/python virtualenv -Multiple values can be provided separated with a comma: +Where the option accepts multiple values, for example for :option:`python` or +:option:`extra-search-dir`, the values can be separated either by comma or a +literal newline: .. code-block:: console env VIRTUALENV_PYTHON=/opt/python-3.8/bin/python,python3.8 virtualenv + env VIRTUALENV_EXTRA_SEARCH_DIR=/path/to/dists\n/path/to/other/dists virtualenv -This also works for appending command line options, like :option:`extra-search-dir`, where a literal newline -is used to separate the values: - -.. code-block:: console - - env VIRTUALENV_EXTRA_SEARCH_DIR=/path/to/dists\n/path/to/other/dists virtualenv - -The equivalent CLI-flags based invocation, for the above example, would be: +The equivalent CLI-flags based invocation for the above examples would be: .. code-block:: console + virtualenv --python=/opt/python-3.8/bin/python --python=python3.8 virtualenv --extra-search-dir=/path/to/dists --extra-search-dir=/path/to/other/dists diff --git a/src/virtualenv/config/convert.py b/src/virtualenv/config/convert.py index b74584967..a0381bcc7 100644 --- a/src/virtualenv/config/convert.py +++ b/src/virtualenv/config/convert.py @@ -57,19 +57,22 @@ def convert(self, value, flatten=True): def split_values(self, value): """Split the provided value into a list. - For strings this is a comma-separated. For more complex types (`Path` - for example) this is newline-separated. + First this is done by newlines. If there were no newlines in the text, + then we next try to split by comma. """ if isinstance(value, (str, bytes)): - if self.as_type is str: - # Simple split - value = value.split(",") - else: - value = value.splitlines() - - value = filter(None, [x.strip() for x in value]) - - return list(value) + # Use `splitlines` rather than a custom check for whether there is + # more than one lines. This ensures that the full `splitlines()` + # logic is supported here. + values = value.splitlines() + if len(values) <= 1: + values = value.split(",") + + values = filter(None, [x.strip() for x in values]) + else: + values = list(value) + + return values def convert(value, as_type, source):