#############
 Development
#############

*****************
 Getting started
*****************

``virtualenv`` is a volunteer maintained open source project and we welcome contributions of all forms. The sections
below will help you get started with development, testing, and documentation. We’re pleased that you are interested in
working on virtualenv. This document is meant to get you setup to work on virtualenv and to act as a guide and reference
to the development setup. If you face any issues during this process, please `open an issue
<https://github.com/pypa/virtualenv/issues/new?title=Trouble+with+development+environment>`_ about it on the issue
tracker.

Setup
=====

virtualenv is a command line application written in Python. To work on it, you'll need:

- **Source code**: available on `GitHub <https://github.com/pypa/virtualenv>`_. You can use ``git`` to clone the
      repository:

  .. code-block:: console

      git clone https://github.com/pypa/virtualenv
      cd virtualenv

- **Python interpreter**: We recommend using ``CPython``. You can use `this guide
  <https://realpython.com/installing-python/>`_ to set it up.
- :pypi:`tox`: to automatically get the projects development dependencies and run the test suite. We recommend
  installing it using `pipx <https://pipxproject.github.io/pipx/>`_.

Running from source tree
========================

The easiest way to do this is to generate the development tox environment, and then invoke virtualenv from under the
``.tox/dev`` folder

.. code-block:: console

    tox -e dev
    .tox/dev/bin/virtualenv  # on Linux
    .tox/dev/Scripts/virtualenv  # on Windows

Running tests
=============

virtualenv's tests are written using the :pypi:`pytest` test framework. :pypi:`tox` is used to automate the setup and
execution of virtualenv's tests.

To run tests locally execute:

.. code-block:: console

    tox -e py

This will run the test suite for the same Python version as under which ``tox`` is installed. Alternatively you can
specify a specific version of python by using the ``pyNN`` format, such as: ``py314``, ``pypy3``, etc.

``tox`` has been configured to forward any additional arguments it is given to ``pytest``. This enables the use of
pytest's `rich CLI <https://docs.pytest.org/en/latest/usage.html#specifying-tests-selecting-tests>`_. As an example, you
can select tests using the various ways that pytest provides:

.. code-block:: console

    # Using markers
    tox -e py -- -m "not slow"
    # Using keywords
    tox -e py -- -k "test_extra"

Some tests require additional dependencies to be run, such is the various shell activators (``bash``, ``fish``,
``powershell``, etc). These tests will automatically be skipped if these are not present, note however that in CI all
tests are run; so even if all tests succeed locally for you, they may still fail in the CI.

Running linters
===============

virtualenv uses :pypi:`pre-commit` for managing linting of the codebase. ``pre-commit`` performs various checks on all
files in virtualenv and uses tools that help follow a consistent code style within the codebase. To use linters locally,
run:

.. code-block:: console

    tox -e fix

.. note::

    Avoid using ``# noqa`` comments to suppress linter warnings - wherever possible, warnings should be fixed instead.
    ``# noqa`` comments are reserved for rare cases where the recommended style causes severe readability problems.

Type checking
=============

virtualenv ships a :PEP:`561` ``py.typed`` marker and has comprehensive type annotations across the entire codebase.
This means downstream consumers and type checkers automatically recognize virtualenv as an inline-typed package.

All new code **must** include complete type annotations for function parameters and return types. To verify annotations
locally, run:

.. code-block:: console

    tox -e type

This uses `ty <https://docs.astral.sh/ty/>`_ (Astral's Rust-based type checker) to validate annotations against Python
3.14. A second environment checks compatibility with the minimum supported version:

.. code-block:: console

    tox -e type-3.9

Both environments validate that annotations are consistent and correct.

Annotation guidelines
---------------------

- Use ``from __future__ import annotations`` at the top of every module (enforced by ruff's ``required-imports``
  setting).
- Place imports that are only needed for type checking inside an ``if TYPE_CHECKING:`` block to avoid runtime overhead.
- Ruff's ``ANN`` rules are enabled. ``ANN401`` (``typing.Any``) is suppressed on a case-by-case basis with inline ``#
  noqa: ANN401`` comments where ``Any`` is genuinely required (e.g. serialization, dynamic dispatch).
- Prefer concrete types over ``Any``. Use ``Union`` / ``|`` for nullable or multi-type parameters.
- When a type error is genuinely unfixable (e.g. third-party library limitations), suppress it with an inline ``# ty:
  ignore[rule-name]`` comment and a brief justification.

Building documentation
======================

virtualenv's documentation is built using :pypi:`Sphinx`. The documentation is written in reStructuredText. To build it
locally, run:

.. code-block:: console

    tox -e docs

The built documentation can be found in the ``.tox/docs_out`` folder and may be viewed by opening ``index.html`` within
that folder.

Logo and branding
=================

Two logo files live in ``docs/_static`` and serve different roles, so both are kept on purpose:

- ``virtualenv.png`` is the official logo — the snakes wrapped around a terminal, with the wordmark. It is the site logo
  (``light_logo``/``dark_logo`` in ``docs/conf.py``) and the one to use wherever a virtualenv logo is needed.
- ``virtualenv.svg`` is a simplified mark used only as the browser favicon (``html_favicon``), where the detailed PNG
  would be illegible at 16×16. It is not a vector copy of the PNG.

.. _release:

Release
=======

virtualenv's release schedule is tied to ``pip`` and ``setuptools``. We bundle the latest version of these libraries so
each time there's a new version of any of these, there will be a new virtualenv release shortly afterwards (we usually
wait just a few days to avoid pulling in any broken releases).

Performing a release
--------------------

A full release publishes to `PyPI <https://pypi.org/project/virtualenv/>`_, creates a `GitHub Release
<https://github.com/pypa/virtualenv/releases>`_ with the zipapp and SBOMs attached, and updates `get-virtualenv
<https://github.com/pypa/get-virtualenv>`_ so that ``https://bootstrap.pypa.io/virtualenv.pyz`` serves the new version.

Version bumping
^^^^^^^^^^^^^^^

The ``--version`` argument to ``tox r -e release`` controls the version. It defaults to ``auto``, which inspects the
``docs/changelog`` directory: if any ``*.feature.rst`` or ``*.removal.rst`` fragments exist, the minor version is
bumped, otherwise the patch version is bumped. You can also pass ``major``, ``minor``, or ``patch`` explicitly.

Both methods produce identical results: a release commit and tag on ``main``. Pushing the tag triggers the `Release
workflow <https://github.com/pypa/virtualenv/actions/workflows/release.yaml>`_ which builds the sdist, wheel, and
zipapp, publishes to PyPI via trusted publisher, creates a `GitHub Release
<https://github.com/pypa/virtualenv/releases>`_ with the zipapp and SBOMs attached, and updates `get-virtualenv
<https://github.com/pypa/get-virtualenv>`_. A failed publish needs the recovery procedure below.

**Via GitHub Actions (recommended)**

1. Go to the `Pre-release workflow <https://github.com/pypa/virtualenv/actions/workflows/pre-release.yaml>`_ on GitHub.
2. Click **Run workflow** and select the bump type (``auto``, ``major``, ``minor``, or ``patch``).

**Locally**

.. code-block:: console

    tox r -e release

Pass ``--version <bump>`` to override the default ``auto`` behavior (e.g. ``--version minor``).

Recovering a partial publication
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A failure after the PyPI upload can leave a published package without its GitHub release or bootstrap update. Keep the
release commit and tag: users may have installed that version, and PyPI `does not allow filename reuse
<https://pypi.org/help/#file-name-reuse>`_. Resetting the tip of ``main`` can also remove an unrelated commit that a
maintainer merged during publication.

Before retrying, inspect the failed job, the files on PyPI, the GitHub release assets and
``get-virtualenv/public/version.txt``. Compare their hashes with the artifacts from the failed workflow run. Preserve
those artifacts and logs. A timeout does not prove that an upload failed.

Complete missing publication steps with the original verified artifacts. Do not rerun the full publish job after PyPI
accepted its upload; the duplicate upload can fail before reaching the remaining destinations. If the artifacts need a
change, publish a new version and consider yanking the broken release. Use a normal reviewed commit for any bootstrap
correction, without force-pushing either repository. Follow ``.github/INCIDENT_RESPONSE.md`` if there is evidence of
tampering or compromised credentials.

The release workflow verifies the published wheel, sdist and zipapp after publication. It checks the PyPI attestations
and compares the distributions with the build artifacts, verifies the zipapp's release workflow, tag and commit, checks
that the ``virtualenv.cdx.json`` and ``virtualenv.spdx.json`` release assets match the wheel and the attested SBOMs,
then creates an environment from each distribution. This job has no publishing credentials. A verification failure does
not undo publication: inspect the mismatch or creation failure before retrying only the verification job. Do not rerun
publication to repair a verification failure.

**************
 Contributing
**************

Submitting pull requests
========================

Submit pull requests against the ``main`` branch, providing a good description of what you're doing and why. You must
have legal permission to distribute any code you contribute to virtualenv and it must be available under the MIT
License. Provide tests that cover your changes and run the tests locally first. virtualenv :ref:`supports
<compatibility-requirements>` multiple Python versions and operating systems. Any pull request must consider and work on
all these platforms.

Pull Requests should be small to facilitate review. Keep them self-contained, and limited in scope. `Studies have shown
<https://www.kessler.de/prd/smartbear/BestPracticesForPeerCodeReview.pdf>`_ that review quality falls off as patch size
grows. Sometimes this will result in many small PRs to land a single large feature. In particular, pull requests must
not be treated as "feature branches", with ongoing development work happening within the PR. Instead, the feature should
be broken up into smaller, independent parts which can be reviewed and merged individually.

Additionally, avoid including "cosmetic" changes to code that is unrelated to your change, as these make reviewing the
PR more difficult. Examples include re-flowing text in comments or documentation, or addition or removal of blank lines
or whitespace within lines. Such changes can be made separately, as a "formatting cleanup" PR, if needed.

AI-assisted contributions
=========================

You may use AI tools (code assistants, chat models, agents) to help write a contribution, under these conditions:

- You are the author. Read, understand and test everything you submit; you are responsible for it as if you had typed it
  yourself, including its licensing.
- Keep a human in the loop. Do not open pull requests or issues, or post review comments, that you have not read. Fully
  automated submissions are closed without review.
- Do not paste in code whose license is unknown or incompatible with the MIT License, whatever produced it.

Maintainers may use AI tools to help triage and review. A review comment posted under a maintainer's name has been read
and endorsed by that maintainer.

Licensing policy
================

virtualenv is distributed under the MIT License, and everything in the repository must be compatible with it:

- Contributions are accepted under the MIT License only; you must have the right to license what you submit.
- Runtime dependencies must use a permissive license: MIT, BSD-2-Clause, BSD-3-Clause, Apache-2.0, PSF-2.0, ISC or
  Unlicense. The Unlicense entry covers ``filelock`` 3.19.1 and older, which virtualenv installs on Python 3.9 and
  bundles in the zipapp. Copyleft licenses (GPL, LGPL, AGPL, MPL) are not acceptable for runtime dependencies.
  Development-only tools carry no such restriction.
- ``.github/workflows/dependency-review.yaml`` enforces this list on every pull request and fails when a change adds a
  runtime dependency under another license, or one with a known vulnerability. Its ``allow-licenses`` input and the list
  above must match.
- The wheels embedded under ``src/virtualenv/seed/wheels/embed`` (``pip``, ``setuptools``) keep their own MIT licenses
  and are redistributed unchanged.
- Adding a runtime dependency or bumping an embedded wheel is a maintainer decision; checking the license of the new
  version is part of that review.
- ``hatch_build.py`` writes a `CycloneDX <https://cyclonedx.org/>`_ SBOM into every wheel at
  ``.dist-info/sboms/virtualenv.cdx.json``. It reads the ``BUNDLE_SUPPORT``/``BUNDLE_SHA256`` tables that back the
  embedded wheels above, so a wheel bump updates it with no extra step. ``tasks/cyclonedx_to_spdx.py`` renders that
  document as SPDX 2.3 with the standard library alone. ``tox r -e readme`` builds a wheel and validates its SBOM and
  the SPDX rendering; the release workflow runs ``tox r -e spdx`` to write ``virtualenv.spdx.json`` from
  ``virtualenv.cdx.json`` and check it with ``pyspdxtools``. Both envs run on Python 3.14 because ``spdx-tools`` fails
  to import on 3.15.
- ``tasks/zipapp_sbom.py`` describes a built ``virtualenv.pyz`` from the archive itself: virtualenv, the embedded
  wheels, and each bundled dependency with the Python versions that load it, down to a SHA-256 per file. It reuses the
  helpers in ``hatch_build.py``, writes ``virtualenv.pyz.cdx.json`` next to the zipapp and adds the same file to the
  archive root. ``tox r -e zipapp`` builds the zipapp, runs the script, and has ``tasks/validate_sbom.py`` check that
  the SBOM lists every file in the archive with its hash.

:doc:`reference/release-artifacts` describes every file, SBOM and attestation a release publishes, and
:doc:`how-to/verify-release` shows users how to check them.

Automated testing
=================

All pull requests and merges to 'main' branch are tested using `GitHub Actions <https://docs.github.com/en/actions>`_
(configured by ``.github/workflows/check.yaml`` file at the root of the repository). You can find the status and results
to the CI runs for your PR on GitHub's Web UI for the pull request. You can also find links to the CI services' pages
for the specific builds in the form of "Details" links, in case the CI run fails and you wish to view the output.

To trigger CI to run again for a pull request, you can close and open the pull request or submit another change to the
pull request. If needed, project maintainers can manually trigger a restart of a job/build.

NEWS entries
============

The ``changelog.rst`` file is managed using :pypi:`towncrier` and all non trivial changes must be accompanied by a news
entry. To add an entry to the news file, first you need to have created an issue describing the change you want to make.
A Pull Request itself *may* function as such, but it is preferred to have a dedicated issue (for example, in case the PR
ends up rejected due to code quality reasons).

Once you have an issue or pull request, you take the number and you create a file inside of the ``docs/changelog``
directory named after that issue number with an extension of:

- ``feature.rst``,
- ``bugfix.rst``,
- ``doc.rst``,
- ``deprecation.rst``,
- ``removal.rst``.

Thus if your issue or PR number is ``1234`` and this change is fixing a bug, then you would create a file
``docs/changelog/1234.bugfix.rst``. PRs can span multiple categories by creating multiple files (for instance, if you
added a feature and deprecated/removed the old feature at the same time, you would create
``docs/changelog/1234.bugfix.rst`` and ``docs/changelog/1234.removal.rst``). Likewise if a PR touches multiple
issues/PRs you may create a file for each of them with the same contents and :pypi:`towncrier` will deduplicate them.

Contents of a NEWS entry
------------------------

The contents of this file are reStructuredText formatted text that will be used as the content of the news file entry.
You do not need to reference the issue or PR numbers here as towncrier will automatically add a reference to all of the
affected issues when rendering the news file.

In order to maintain a consistent style in the ``changelog.rst`` file, it is preferred to keep the news entry to the
point, in sentence case, shorter than 120 characters and in an imperative tone -- an entry should complete the sentence
``This change will …``. In rare cases, where one line is not enough, use a summary line in an imperative tone followed
by a blank line separating it from a description of the feature/change in one or more paragraphs, each wrapped at 120
characters. Remember that a news entry is meant for end users and should only contain details relevant to an end user.

Choosing the type of NEWS entry
-------------------------------

A trivial change is anything that does not warrant an entry in the news file. Some examples are: code refactors that
don't change anything as far as the public is concerned, typo fixes, white space modification, etc. To mark a PR as
trivial a contributor simply needs to add a randomly named, empty file to the ``news/`` directory with the extension of
``.trivial``.

Becoming a maintainer
=====================

If you want to become an official maintainer, start by helping out. As a first step, we welcome you to triage issues on
virtualenv's issue tracker. virtualenv maintainers provide triage abilities to contributors once they have been around
for some time and contributed positively to the project. This is optional and highly recommended for becoming a
virtualenv maintainer. Later, when you think you're ready, get in touch with one of the maintainers and they will
initiate a vote among the existing maintainers.

.. note::

    Upon becoming a maintainer, a person should be given access to various virtualenv-related tooling across multiple
    platforms. These are noted here for future reference by the maintainers:

    - GitHub Push Access
    - PyPI Publishing Access
    - CI Administration capabilities
    - ReadTheDocs Administration capabilities

Maintainer access
-----------------

Current and backup maintainers turn on two-factor authentication for GitHub and PyPI, with a security key or passkey
where the service supports one. We review access once a year and whenever a maintainer steps back. When someone steps
back, we remove their GitHub push access, PyPI publishing access, CI administration and ReadTheDocs administration, and
rotate every secret they could read. New commit access still goes through the maintainer vote described above.

.. _current-maintainers:

Current maintainers
-------------------

- :user:`Bernát Gábor <gaborbernat>`
- :user:`Rahul Devikar <rahuldevikar>`, who covers when Bernát is unavailable

Backup maintainer
-----------------

- :user:`Paul Moore <pfmoore>`, who steps in if both current maintainers are away

Previous maintainers
--------------------

- :user:`Ian Bicking <ianb>`
- :user:`Donald Stufft <dstufft>`

*********
 Roadmap
*********

This roadmap covers October 2026 to September 2027; Bernát Gábor last updated it on 2026-09-22. It lists work that
follows from a published policy or waits on an outside decision, and it gives no release dates. We leave out work that
an open pull request delivers without waiting on anyone else.

What we plan to do
==================

- Add CPython 3.16 and drop CPython 3.9 under the :ref:`support policy <compatibility-requirements>`. CPython 3.9
  reached end of life in October 2025, so the drop can happen from May 2027; it also retires the ``_virtualenv.pth``
  distutils hook, which only 3.9 environments still receive (:issue:`3181`).
- Keep releasing on the pip and setuptools cadence that :ref:`release` describes.
- Merge :pull:`3204` (:PEP:`832`) and :pull:`3193` (:PEP:`838`) once those PEPs reach Accepted status.

What we do not plan to do
=========================

- Backport fixes to older release lines; see `supported versions
  <https://github.com/pypa/virtualenv/blob/main/.github/SECURITY.md#supported-versions>`_.
- Break the command line, the Python API or the plugin API, per the backwards-compatible release policy in the same
  section.
- Bring back Python versions that the :ref:`support policy <compatibility-requirements>` has dropped.
- Write files outside the environment it creates, such as a project-level ``.gitignore`` (:issue:`3237`).
- Install, resolve or lock project dependencies. virtualenv creates and seeds the environment; pip, uv and similar tools
  manage what goes into it.
