-
-
Notifications
You must be signed in to change notification settings - Fork 32k
[venv] Adding a .gitignore file to virtual environments #83417
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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 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. |
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. |
The file contents is `*` so the whole directory is ignored. See python/cpython#83417 a discussion around this. Closes #31
The file contents is `*` so the whole directory is ignored. See python/cpython#83417 a discussion around this. Closes #31
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. |
Resurrecting this to add some thoughts.
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. |
I'm +1 on this change, it's a reasonable mitigation to a common mistake that is trivial to undo if you really do want to check your venv into your git repo. |
Another +1, basically what dstufft said, I help teach Python on Discord, and I have had to help many beginners delete their venv(s) from git, but I've never had anyone actually want to upload it. |
+1, I've seen packages on PyPI that have accidentally included the venv and the packager had no idea before I reported it. For comparison, some other tools' directories that include
And some common venv names are part of this Python template |
@vsajip has your mind changed at all on this topic? I also noticed that Nox inserts a While we wait to here from Vinay, are there any other ignore files we should be considering, i.e., Mercurial, Bazaar, or Subversion (I listed those specifically as they are supported by packaging standards)? Should there be some CLI flag to disable the creation of the ignore file(s)? |
Well, I originally said I was -0.5 on this, and that's still my view (learners/novices uploading to PyPI could make all kinds of mistakes, and I'm not sure we want to try and catch them all), but I don't object strongly to this change if you want to go ahead and do it - please loop me in on the PR. |
Maybe that is from the virtualenv package, which has been creating such files since v20.0.21 (2020-05-20):
Adding this to The full list of precedents that I know of: Coverage.py, Mypy, pytest, and virtualenv. (And pending on tox.) |
Hatch also does this |
Apparently, |
I'd say stick with |
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: ![]() |
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. |
Off by default via code but on by default via the CLI, the `.gitignore` file contains `*` which causes the entire directory to be ignored.
|
… a new `scm_ignore_file` parameter (GH-108125) This feature is off by default via code but on by default via the CLI. The `.gitignore` file contains `*` which causes the entire directory to be ignored. Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
…ts via a new `scm_ignore_file` parameter (pythonGH-108125) This feature is off by default via code but on by default via the CLI. The `.gitignore` file contains `*` which causes the entire directory to be ignored. Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
For anyone wondering why this seems necessary, because they have a |
To be specific, we have been adding a |
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:
bugs.python.org fields:
Linked PRs
venv
to add a.gitignore
file to environments via a newscm_ignore_file
parameter #108125The text was updated successfully, but these errors were encountered: