Skip to content

Commit

Permalink
Extend comma support to all list values
Browse files Browse the repository at this point in the history
  • Loading branch information
pneff committed Oct 28, 2020
1 parent 3a6fe60 commit a0c3568
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
15 changes: 6 additions & 9 deletions docs/cli_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 14 additions & 11 deletions src/virtualenv/config/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a0c3568

Please sign in to comment.