GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [venv] Adding a .gitignore file to virtual environments · Issue #83417 · python/cpython

[venv] Adding a .gitignore file to virtual environments #83417

New issue
Copy link
New issue
Copy link
Closed
#108125
Closed
[venv] Adding a .gitignore file to virtual environments#83417
#108125
Copy link
Labels
3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@brettcannon
brettcannon
opened on Jan 6, 2020
Issue body actions
BPO 39236
Nosy @brettcannon, @vsajip, @asottile, @tirkarthi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-01-06.19:45:05.714>
labels = ['type-feature', 'library', '3.9']
title = '[venv] Adding a .gitignore file to virtual environments'
updated_at = <Date 2020-01-07.16:32:50.101>
user = 'https://github.com/brettcannon'

bugs.python.org fields:

activity = <Date 2020-01-07.16:32:50.101>
actor = 'vinay.sajip'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-01-06.19:45:05.714>
creator = 'brett.cannon'
dependencies = []
files = []
hgrepos = []
issue_num = 39236
keywords = []
message_count = 2.0
messages = ['359459', '359517']
nosy_count = 4.0
nosy_names = ['brett.cannon', 'vinay.sajip', 'Anthony Sottile', 'xtreak']
pr_nums = []
priority = 'low'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue39236'
versions = ['Python 3.9']

Linked PRs

  • GH-83417: Allow venv to add a .gitignore file to environments via a new scm_ignore_file parameter #108125
Reacted by Jakub Kuczys, Nikita Karamov, Petr Viktorin, Adam Johnson, Edgar Ramírez Mondragón, Ed Morley, Tushar Sadhwani, T-256 and Erlend E. Aasland
Reacted by Pierre Sassoulas and bersbersbers

Activity

Next
  1. brettcannon commented on Jan 6, 2020

    @brettcannon
    brettcannon
    on Jan 6, 2020
    MemberAuthor
    More actions

    In a discussion on Twitter, the idea of having venv lay down a .gitignore file in a newly created virtual environment that consisted of nothing but * came up (https://twitter.com/codewithanthony/status/1213680829530099713). The purpose would be to help prevent people from inadvertently committing their venv to git. It seems pytest does something similar for .pytest_cache (got one complaint but have chosen to keep it otherwise).

    To me this seems like a good enhancement. Since this would mostly benefit beginners then it should probably be an opt-out if we do it at all. Maybe make --no-ignore-file to opt out?

    FYI Mercurial does not support subdirectory hgignore files like git does, so this may be git-specific (for now): https://www.selenic.com/mercurial/hgignore.5.html.

  2. brettcannon
    added
    3.9 (EOL)end of lifeend of life
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    type-featureA feature request or enhancementA feature request or enhancement
    on Jan 6, 2020
  3. brettcannon
    changed the title [-]Adding a .gitignore file to virtual environments[/-] [+][venv] Adding a .gitignore file to virtual environments[/+] on Jan 6, 2020
  4. brettcannon
    changed the title [-]Adding a .gitignore file to virtual environments[/-] [+][venv] Adding a .gitignore file to virtual environments[/+] on Jan 6, 2020
  5. vsajip commented on Jan 7, 2020

    @vsajip
    vsajip
    on Jan 7, 2020
    Member
    More actions

    I'm -0.5 on this. Beginners will probably shoot themselves in the foot multiple ways using git (or any DVCS), in terms of checking things in they didn't mean to (e.g. build artifacts which are not in the venv). As they can easily undo this, I don't think we need to do this.

  6. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  7. brettcannon
    added 2 commits that reference this issue on Jun 15, 2022

    Add a `.gitignore` to the created virtual environment

    8ee6d3c

    Add a `.gitignore` to the created virtual environment (#32)

    2e2cca0
  8. ofek commented on Jul 13, 2023

    @ofek
    ofek
    on Jul 13, 2023
    SponsorContributor
    More actions

    I think this is a very good idea and not only would assist beginners but has come to be expected for tools that create directories that should not be version controlled.

  9. import-pandas-as-numpy commented on Jul 13, 2023

    @import-pandas-as-numpy
    import-pandas-as-numpy
    on Jul 13, 2023
    More actions

    Resurrecting this to add some thoughts.
    To introduce myself, I run a third-party anti-malware scanning service against the Python Package Index.
    We've observed a fairly long-standing trend of venv inclusion in source distributions.
    This is problematic for a few reasons:

    • Many of the commands in the virtual environment creation itself cause flags on our signature analysis schema. We've taken to 'whitelisting' virtual environment hashes on a per-file basis as we encounter them, but this is by no means evergreen. Whitespacing issues and minute differences in versioning have lead to a constant whack-a-mole of trying to maintain these hashes.
    • This often dramatically increases the package size of smaller files. As I suspect is a 'granted', the individuals most predisposed to unintentional inclusion of their virtual environments in their workflows are also the most likely to have heavily polluted virtual environments in the first place.
    • This creates a 'recursive checking' problem, where by we're also now checking every dependency of a particular package by virtue of enumerating the virtual environment. This might sound ideal, but as we scan all new and uploaded packages on the Python Package Index, these packages are "secure" in our eyes by virtue of simply existing in the first place.
    • Because we aggregate the signatures that a package might display, including the virtual environment substantially increases the propensity that a package may be verdicted as potentially malicious. To me, it stands to reason that if you include enough code, anything is going to flag as malware without human analysis.

    We would like to scan the package uploaded and make a determination on the code therein, less so the dependencies it uses. When we begin adding additional packages/libraries into the codebase, our whitelisting and other false-positive reducing techniques begin to degrade.

    We've seen malicious modifications to virtual environments in the past, where the included libraries are used to contain malicious code or libraries that otherwise would be prohibited from the Python Package Index (or, in some cases, were already removed from the Python Package Index for being malicious.)

    As PyPI shifts towards a third-party anti-malware solution, I think this would be extremely beneficial to revisit this conversation with that in mind.

  10. 6 remaining items

  11. ofek commented on Aug 10, 2023

    @ofek
    ofek
    on Aug 10, 2023
    SponsorContributor
    More actions

    Hatch also does this

  12. brettcannon commented on Aug 10, 2023

    @brettcannon
    brettcannon
    on Aug 10, 2023
    MemberAuthor
    More actions

    Apparently, .bzrignore supports the same syntax (if we want to bother with support Bazaar since it seems to no longer be supported).

  13. vsajip commented on Aug 11, 2023

    @vsajip
    vsajip
    on Aug 11, 2023
    Member
    More actions

    I'd say stick with .gitignore for now - I doubt there's enough demand for Bazaar support.

    Reacted by Hugo van Kemenade and Brett Cannon
  14. hugovk commented on Aug 11, 2023

    @hugovk
    hugovk
    on Aug 11, 2023
    Member
    More actions

    Agreed, let's start with only Git.

    Of the open source projects tracked by Open Hub, Bazaar accounts for ~0% (13,042 repos) compared to Git at 74% (1,079,642), and is the least popular of the five SCMs represented:

  15. merwok
    added
    3.13only security fixesonly security fixes
    and removed
    3.9 (EOL)end of lifeend of life
    on Aug 11, 2023
  16. adamchainz commented on Aug 13, 2023

    @adamchainz
    adamchainz
    on Aug 13, 2023
    SponsorContributor
    More actions

    Better data for what is used now - Stack Overflow survey 2022: https://survey.stackoverflow.co/2022/#section-version-control-version-control-systems . 82% Git, 1% SVN, <1% Mercurial.

    Reacted by Hugo van Kemenade and Brett Cannon
  17. brettcannon
    added a commit that references this issue on Aug 18, 2023

    pythonGH-83417: Allow `venv` add a `.gitignore` file to environments

    f889dc6
  18. brettcannon
    linked a pull request that will close this issueGH-83417: Allow `venv` to add a `.gitignore` file to environments via a new `scm_ignore_file` parameter #108125on Aug 18, 2023
  19. brettcannon commented on Aug 18, 2023

    @brettcannon
    brettcannon
    on Aug 18, 2023
    MemberAuthor
    More actions

    please loop me in on the PR.

    #108125

  20. brettcannon
    closed this as completedin #108125on Sep 15, 2023
  21. brettcannon
    added a commit that references this issue on Sep 15, 2023

    GH-83417: Allow `venv` to add a `.gitignore` file to environments via…

    e218e50
  22. csm10495
    added a commit that references this issue on Sep 28, 2023

    pythonGH-83417: Allow `venv` to add a `.gitignore` file to environmen…

    a4284f9
  23. bersbersbers commented on Oct 6, 2023

    @bersbersbers
    bersbersbers
    on Oct 6, 2023
    More actions

    For anyone wondering why this seems necessary, because they have a .gitignore file in their .venv already: vscode-python has been doing this on creation of an environment from the beginning (late 2022).

  24. brettcannon commented on Oct 6, 2023

    @brettcannon
    brettcannon
    on Oct 6, 2023
    MemberAuthor
    More actions

    vscode-python has been doing this on creation of an environment from the beginning (late 2022).

    To be specific, we have been adding a .gitignore file since we introduced our opinionated "Python: Create Environment" command. Our experience informed my decision to push for this here as we have had zero issues since introducing it in the VS Code extension.

    Reacted by bersbersbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.