为Python项目添加.gitignore文件的最佳实践? [关闭]

问题描述 投票:151回答:6

我正在尝试收集一些我的默认设置,有一件事我意识到我没有标准的.gitignore文件。有一个很好的线程显示good .gitignore for Visual Studio projects,但我没有看到很多关于Python和相关工具的建议(PyGTK,Django)。

到目前为止,我有......

*.pyc
*.pyo

...对于编译对象和......

build/
dist/

...用于setuptools输出。

.gitignore文件的最佳实践是什么?我可以在哪里获得有关这些最佳实践的更多信息?

python django git pygtk gitignore
6个回答
49
投票

当使用buildout时,我跟随.gitignore(以及*.pyo*.pyc):

.installed.cfg
bin
develop-eggs
dist
downloads
eggs
parts
src/*.egg-info
lib
lib64

感谢Jacob Kaplan-Moss

此外,我倾向于将.svn放入,因为我们使用了几个SCM-s。


239
投票

Github has a great boilerplate .gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/

15
投票

local_settings.py,为django项目。

*〜适用于所有项目。


6
投票

一个问题是,如果您还想使用git来实现项目的开发。如果是这样,您可能希望从存储库中排除本地sqlite文件,同样可能适用于文件上载(主要在您的媒体文件夹中)。 (我现在在谈论django,因为你的问题也用django标记)


4
投票

以下是setuptools可能遗留的一些其他文件:

MANIFEST
*.egg-info

4
投票

涵盖了大多数一般的东西 -

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

参考:python .gitignore

© www.soinside.com 2019 - 2024. All rights reserved.