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

时间:2010-09-15 15:32:42

标签: python django git pygtk gitignore

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

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

*.pyc
*.pyo

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

build/
dist/

...用于setuptools输出。

.gitignore文件有哪些最佳做法,哪些方面可以了解有关这些最佳做法的更多信息?

6 个答案:

答案 0 :(得分:232)

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/

答案 1 :(得分:48)

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

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

感谢Jacob Kaplan-Moss

此外,我倾向于将.svn放入,因为我们在工作的地方使用了几个SCM。

答案 2 :(得分:15)

local_settings.py,对于django项目。

*〜适用于所有项目。

答案 3 :(得分:6)

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

答案 4 :(得分:4)

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

MANIFEST
*.egg-info

答案 5 :(得分: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