[FR] Add a .gitignore file to egg-info, dist-info, dist and build directories
What's the problem this feature will solve?
Presently, git users tend to configure their repositories to ignore generated files from setuptools. This is easy enough (and expressive enough) to do for people who know what they are doing. For novice users though, it is very easy to commit these generated files into a repository (due to ignorance or by accident).
Describe the solution you'd like
I propose that we change the default such that generated directories (build, dist, *.dist-info and *.egg-info) are ignored. This is not a re-hash of #2455 and https://github.com/pypa/setuptools/pull/1497#issuecomment-423323011) - I am proposing that we generate files in build/.gitignore (and the other directories in question) containing *.
There may be expert corner-cases where people actually want to commit these files. In that case, they would need to remove the .gitignore file manually.
This proposal does not contradict https://github.com/pypa/setuptools/pull/4453, where developers are recommended to put common (across multiple projects) .gitignore specific configuration into a common place (not every project). To quote @jaraco's very good article:
[The]
.gitignorefor a project should specify elements unique to that project and not elements peculiar to the language or system or user.
My proposal supports that position further - there will be less incentive for projects to add *.egg-info / *.dist-info into their project's .gitignore, and there is no work needed on the part of a developer to configure their git to handle Python/setuptools like projects.
This also aligns well with the approach taken in https://github.com/python/cpython/issues/83417.
Alternative Solutions
No response
Additional context
Some notes:
- We could now remove some of the guidance in https://github.com/pypa/setuptools/pull/4201/files related to
.gitignore.
Code of Conduct
- [X] I agree to follow the PSF Code of Conduct
I'd be willing to do this, if accepted.
If the core devs are happy with this approach to only tackle git, I suppose it is also good for setuptools!
I would be happy with this change but I would like to see if @jaraco has any thoughts on this.
Meson has also done this for absolutely ages and we haven't gotten a single complaint, but have gotten lots of grateful users. (It is especially useful in the case of meson since it is routine for people to have multiple build directories rather than just build/ but even without that factor it's very useful.)
This sounds reasonable to me. As pelson points out, this approach moves the concern more close to the relevant location in a systematic way.
I'm a little uncomfortable with the idea of embedding behaviors specific to a tool (git), acknowledging that it is a dominant de facto standard. It does seem more appropriate to teach more specialized tools about the more general ones than the other way around (e.g. teach setuptools about git instead of teaching git about setuptools).
I have no objections.
I am not sure that this is the best approach, but I got it to work by just adding a .gitignore writer:
diff --git a/pyproject.toml b/pyproject.toml
index a9febdbe8..eb503b600 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -194,6 +194,7 @@ PKG-INFO = "setuptools.command.egg_info:write_pkg_info"
"namespace_packages.txt" = "setuptools.command.egg_info:overwrite_arg"
"top_level.txt" = "setuptools.command.egg_info:write_toplevel_names"
"dependency_links.txt" = "setuptools.command.egg_info:overwrite_arg"
+".gitignore" = "setuptools.command.egg_info:write_gitignore"
[tool.setuptools]
include-package-data = true
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index f77631168..f075ce264 100644
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -706,6 +706,10 @@ def write_entries(cmd, basename, filename) -> None:
cmd.write_or_delete_file('entry points', filename, defn, True)
+def write_gitignore(cmd, basename, filename) -> None:
+ cmd.write_file('.gitignore', filename, "*")
+
+
def _egg_basename(egg_name, egg_version, py_version=None, platform=None):
"""Compute filename of the output egg. Private API."""
name = _normalization.filename_component(egg_name)
I would've created a PR, but I couldn't get the tests to run, and I assume I broke some of them. @pelson am I on the right track with this?
Edit: This is not a good approach (or at least, not a complete one), it only takes care of the .egg-info directory, and does nothing for the others.
Also, about the whole "this is only relevant to git" thing - I believe it's reasonable to assume everyone who has an .egg-info directory in their source tree excludes it somehow. You are not supposed to commit this directory anyway.
Having the .gitignore there might be irrelevant for the (however small) group of users that don't use git, but it won't change their experience at all.