Skip to content

Commit 5017d1b

Browse files
committed
GH-129382: change venv's API symlinks default to match the CLI
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent 10ee2d9 commit 5017d1b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Doc/library/venv.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ See :pep:`405` for more background on Python virtual environments.
6161

6262
.. include:: ../includes/wasm-mobile-notavail.rst
6363

64+
.. _venv-cli:
65+
6466
Creating virtual environments
6567
-----------------------------
6668

@@ -298,7 +300,8 @@ creation according to their needs, the :class:`EnvBuilder` class.
298300
any existing target directory, before creating the environment.
299301

300302
* *symlinks* -- a boolean value indicating whether to attempt to symlink the
301-
Python binary rather than copying.
303+
Python binary rather than copying (defaults to ``False`` on Windows, and
304+
to ``True`` on all other platforms).
302305

303306
* *upgrade* -- a boolean value which, if true, will upgrade an existing
304307
environment with the running Python - for use when that Python has been
@@ -333,6 +336,11 @@ creation according to their needs, the :class:`EnvBuilder` class.
333336
.. versionchanged:: 3.13
334337
Added the ``scm_ignore_files`` parameter
335338

339+
.. versionchanged:: 3.14
340+
The ``symlinks`` parameter's default value was changed from always
341+
``False`` to being platform dependent — ``False`` on Windows, ``True`` on
342+
all other platforms — matching the :ref:`CLI <venv-cli>`.
343+
336344
:class:`EnvBuilder` may be used as a base class.
337345

338346
.. method:: create(env_dir)

Lib/venv/__init__.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
CORE_VENV_DEPS = ('pip',)
1818
logger = logging.getLogger(__name__)
1919

20+
_USE_SYMLINKS = os.name != 'nt'
21+
2022

2123
class EnvBuilder:
2224
"""
@@ -47,7 +49,7 @@ class EnvBuilder:
4749
"""
4850

4951
def __init__(self, system_site_packages=False, clear=False,
50-
symlinks=False, upgrade=False, with_pip=False, prompt=None,
52+
symlinks=_USE_SYMLINKS, upgrade=False, with_pip=False, prompt=None,
5153
upgrade_deps=False, *, scm_ignore_files=frozenset()):
5254
self.system_site_packages = system_site_packages
5355
self.clear = clear
@@ -631,17 +633,13 @@ def main(args=None):
631633
action='store_true', dest='system_site',
632634
help='Give the virtual environment access to the '
633635
'system site-packages dir.')
634-
if os.name == 'nt':
635-
use_symlinks = False
636-
else:
637-
use_symlinks = True
638636
group = parser.add_mutually_exclusive_group()
639-
group.add_argument('--symlinks', default=use_symlinks,
637+
group.add_argument('--symlinks', default=_USE_SYMLINKS,
640638
action='store_true', dest='symlinks',
641639
help='Try to use symlinks rather than copies, '
642640
'when symlinks are not the default for '
643641
'the platform.')
644-
group.add_argument('--copies', default=not use_symlinks,
642+
group.add_argument('--copies', default=not _USE_SYMLINKS,
645643
action='store_false', dest='symlinks',
646644
help='Try to use copies rather than symlinks, '
647645
'even when symlinks are the default for '
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Change :class:`venv.EnvBuilder`'s ``symlinks`` parameter's default to match
2+
the :ref:`CLI <venv-cli>`.

0 commit comments

Comments
 (0)