Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-83417: Allowvenv to add a.gitignore file to environments via a newscm_ignore_file parameter#108125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
f889dc6
GH-83417: Allow `venv` add a `.gitignore` file to environments
brettcannonAug 18, 2023
1faf4b0
Add a news entry
brettcannonAug 18, 2023
31d0558
Apply suggestions from code review
brettcannonAug 21, 2023
41e541c
Merge branch 'main' into issue-83417-venv-gitignore
brettcannonAug 21, 2023
ce17684
Switch to `scm_ignore_file`
brettcannonSep 4, 2023
90eb700
Merge branch 'main' into issue-83417-venv-gitignore
brettcannonSep 6, 2023
c3b96e0
Make `scm_ignore_files` accept an iterable
brettcannonSep 10, 2023
a8528dd
Merge branch 'main' into issue-83417-venv-gitignore
brettcannonSep 10, 2023
ddc2225
Update Doc/library/venv.rst
brettcannonSep 10, 2023
547879d
Fix capitalization of "Git"
brettcannonSep 11, 2023
8ba65b5
Merge branch 'main' into issue-83417-venv-gitignore
brettcannonSep 11, 2023
f75b26c
Add a What's new entry
brettcannonSep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletionsDoc/library/venv.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,8 @@ creation according to their needs, the :class:`EnvBuilder` class.

.. class:: EnvBuilder(system_site_packages=False, clear=False, \
symlinks=False, upgrade=False, with_pip=False, \
prompt=None, upgrade_deps=False)
prompt=None, upgrade_deps=False, \
*, scm_ignore_files=frozenset())

The :class:`EnvBuilder` class accepts the following keyword arguments on
instantiation:
Expand DownExpand Up@@ -172,6 +173,12 @@ creation according to their needs, the :class:`EnvBuilder` class.

* ``upgrade_deps`` -- Update the base venv modules to the latest on PyPI

* ``scm_ignore_files`` -- Create ignore files based for the specified source
control managers (SCM) in the iterable. Support is defined by having a
method named ``create_{scm}_ignore_file``. The only value supported by
default is ``"git"`` via :meth:`create_git_ignore_file`.


.. versionchanged:: 3.4
Added the ``with_pip`` parameter

Expand All@@ -181,6 +188,9 @@ creation according to their needs, the :class:`EnvBuilder` class.
.. versionadded:: 3.9
Added the ``upgrade_deps`` parameter

.. versionadded:: 3.13
Added the ``scm_ignore_files`` parameter

Creators of third-party virtual environment tools will be free to use the
provided :class:`EnvBuilder` class as a base class.

Expand DownExpand Up@@ -339,11 +349,18 @@ creation according to their needs, the :class:`EnvBuilder` class.
The directories are allowed to exist (for when an existing environment
is being upgraded).

.. method:: create_git_ignore_file(context)

Creates a ``.gitignore`` file within the virtual environment that causes
the entire directory to be ignored by the ``git`` source control manager.

.. versionadded:: 3.13

There is also a module-level convenience function:

.. function:: create(env_dir, system_site_packages=False, clear=False, \
symlinks=False, with_pip=False, prompt=None, \
upgrade_deps=False)
upgrade_deps=False, *, scm_ignore_files=frozenset())

Create an :class:`EnvBuilder` with the given keyword arguments, and call its
:meth:`~EnvBuilder.create` method with the *env_dir* argument.
Expand All@@ -359,6 +376,9 @@ There is also a module-level convenience function:
.. versionchanged:: 3.9
Added the ``upgrade_deps`` parameter

.. versionchanged:: 3.13
Added the ``scm_ignore_files`` parameter

An example of extending ``EnvBuilder``
--------------------------------------

Expand Down
73 changes: 42 additions & 31 deletionsDoc/using/venv-create.inc
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,37 +35,48 @@ your :ref:`Python installation <using-on-windows>`::

The command, if run with ``-h``, will show the available options::

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
[--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
ENV_DIR A directory to create the environment in.

optional arguments:
-h, --help show this help message and exit
--system-site-packages
Give the virtual environment access to the system
site-packages dir.
--symlinks Try to use symlinks rather than copies, when symlinks
are not the default for the platform.
--copies Try to use copies rather than symlinks, even when
symlinks are the default for the platform.
--clear Delete the contents of the environment directory if it
already exists, before environment creation.
--upgrade Upgrade the environment directory to use this version
of Python, assuming Python has been upgraded in-place.
--without-pip Skips installing or upgrading pip in the virtual
environment (pip is bootstrapped by default)
--prompt PROMPT Provides an alternative prompt prefix for this
environment.
--upgrade-deps Upgrade core dependencies (pip) to the
latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
[--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
[--without-scm-ignore-file]
ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
ENV_DIR A directory to create the environment in.

options:
-h, --help show this help message and exit
--system-site-packages
Give the virtual environment access to the system
site-packages dir.
--symlinks Try to use symlinks rather than copies, when
symlinks are not the default for the platform.
--copies Try to use copies rather than symlinks, even when
symlinks are the default for the platform.
--clear Delete the contents of the environment directory if
it already exists, before environment creation.
--upgrade Upgrade the environment directory to use this
version of Python, assuming Python has been upgraded
in-place.
--without-pip Skips installing or upgrading pip in the virtual
environment (pip is bootstrapped by default)
--prompt PROMPT Provides an alternative prompt prefix for this
environment.
--upgrade-deps Upgrade core dependencies (pip) to the latest
version in PyPI
--without-scm-ignore-file
Skips adding the default SCM ignore file to the
environment directory (the default is a .gitignore
file).

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.

.. versionchanged:: 3.13

``--without-scm-ignore-file`` was added along with creating an ignore file
for ``git`` by default.

.. versionchanged:: 3.12

Expand Down
10 changes: 10 additions & 0 deletionsDoc/whatsnew/3.13.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -220,6 +220,16 @@ typing
check whether a class is a :class:`typing.Protocol`. (Contributed by Jelle Zijlstra in
:gh:`104873`.)

venv
----

* Add support for adding source control management (SCM) ignore files to a
virtual environment's directory. By default, Git is supported. This is
implemented as opt-in via the API which can be extended to support other SCMs
(:class:`venv.EnvBuilder` and :func:`venv.create`), and opt-out via the CLI
(using ``--without-scm-ignore-files``). (Contributed by Brett Cannon in
:gh:`108125`.)

Optimizations
=============

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp