Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for adding .gitignore file for Python projects? [closed]

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).

So far, I have...

*.pyc *.pyo 

...for the compiled objects and...

build/ dist/ 

...for the setuptools output.

What are some best practices for .gitignore files, and where can I go for more about these best practices?

like image 941
ewall Avatar asked Sep 15 '10 15:09

ewall


People also ask

Where should Gitignore file be placed?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

Should Gitignore files be committed?

gitignore file must be edited and committed by hand when you have new files that you wish to ignore. . gitignore files contain patterns that are matched against file names in your repository to determine whether or not they should be ignored.

What do I put in Gitignore for Python?

You should put in . gitignore all files and patterns that are generated by the build system of your project, or any file that it might output while running. With this, it makes sure that nobody is committing compiled Python files.

Should .gitignore be ignored?

The . gitignore file's purpose is to prevent everyone who collaborates on a project from accidentally commiting some common files in a project, such as generated cache files. Therefore you should not ignore .


2 Answers

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/ 
like image 79
seanrose Avatar answered Oct 17 '22 01:10

seanrose


When using buildout I have following in .gitignore (along with *.pyo and *.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 .svn in since we use several SCM-s where I work.

like image 22
Davor Lucic Avatar answered Oct 17 '22 02:10

Davor Lucic