python / python/cpython

venv overwrites existing .gitignore

Abierto
#135,604 26 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

3.13 3.14 3.15 docs stdlib topic-venv
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug report

Bug description

I cloned a github project with an existing .gitignore file.
I created a new python venv inside the cloned project using python3 -m venv .venv .
After creating the new venv, I see that the .gitignore file has been modified.

diff --git a/.gitignore b/.gitignore
index d0258704..f514b74c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,2 @@
-.dev
-.idea/
-.hypothesis/
-__pycache__/
-db.sqlite3
-*.sw*
-*.pyc
-venv/
-.venv/
-environment_settings.py
-elm-stuff/
-.coverage
-media
-docker/.env
-node_modules
-package-lock.json
-.sass-cache
+# Created by venv; see https://docs.python.org/3/library/venv.html
+*

I found this documentation on the mentioned url added to the .gitignore file:

Changed in version 3.13: venv now creates a .gitignore file for Git by default.

Environment

  • Arch linux 6.14.9
  • Python 3.13.3

Expected behaviour

I would expect it to not overwrite an existing .gitignore file, so it only creates it if it isnt present already.

Update

Using python3 -m venv .venv works as expected, but I did python3 -m venv .venv . (trailing dot) which creates a folder with a new venv named .venv, but also creates a venv inside the existing folder ., and that's when it overwrites the .gitignore

Please let me know if I'm missing some details or you need further testing for triage the issue.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-139130

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce el comportamiento con python3 -m venv .venv . en un proyecto que ya contiene un .gitignore y compáralo con python3 -m venv .venv. Sigue el punto de entrada de python3 -m venv y verifica que la creación del entorno no reemplace un .gitignore existente; confirma el comportamiento en Python 3.13.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.