为 Python 项目添加 .gitignore 文件的最佳实践?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3719243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best practices for adding .gitignore file for Python projects?
提问by ewall
I'm trying to collect some of my default settings, and one thing I realized I don't have a standard for is .gitignore files. There's a great thread showing a good .gitignore for Visual Studio projects, but I don't see many recommendations for Python and related tools (PyGTK, Django).
我正在尝试收集我的一些默认设置,我意识到我没有标准的一件事是 .gitignore 文件。有一个很棒的线程为 Visual Studio 项目展示了一个很好的 .gitignore,但我没有看到很多关于 Python 和相关工具(PyGTK、Django)的建议。
So far, I have...
到目前为止,我已经...
*.pyc
*.pyo
...for the compiled objects and...
...对于编译对象和...
build/
dist/
...for the setuptools output.
...对于 setuptools 输出。
What are some best practices for .gitignore files, and where can I go for more about these best practices?
.gitignore 文件有哪些最佳实践,我可以从哪里获得有关这些最佳实践的更多信息?
采纳答案by Davor Lucic
When using buildoutI have following in .gitignore(along with *.pyoand *.pyc):
使用buildout 时,我有以下内容.gitignore(以及*.pyo和*.pyc):
.installed.cfg
bin
develop-eggs
dist
downloads
eggs
parts
src/*.egg-info
lib
lib64
Thanks to Jacob Kaplan-Moss
Also I tend to put .svnin since we use several SCM-s where I work.
我也倾向于投入.svn,因为我们在我工作的地方使用了几个 SCM-s。
回答by Bernhard Vallant
One question is if you also want to use git for the deploment of your projects. If so you probably would like to exclude your local sqlite file from the repository, same probably applies to file uploads (mostly in your media folder). (I'm talking about django now, since your question is also tagged with django)
一个问题是您是否还想使用 git 来部署您的项目。如果是这样,您可能希望从存储库中排除您的本地 sqlite 文件,同样可能适用于文件上传(主要在您的媒体文件夹中)。(我现在谈论的是 django,因为你的问题也被标记为 django)
回答by Ofri Raviv
local_settings.py, for django projects.
local_settings.py,用于 django 项目。
*~ for all projects.
*~ 适用于所有项目。
回答by jathanism
Here are some other files that may be left behind by setuptools:
以下是 setuptools 可能遗留的一些其他文件:
MANIFEST
*.egg-info
回答by seanrose
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/
回答by Ani Menon
Covers most of the general stuff -
涵盖了大部分一般内容 -
# 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/
Reference: python .gitignore

