How can I make setuptools ignore subversion inventory?

When packaging a Python package with a that uses the setuptools:

from setuptools import setup

the source distribution created by:

python sdist

not only includes, as usual, the files specified in, but it also, gratuitously, includes all of the files that Subversion lists as being version controlled beneath the package directory. This is vastly annoying. Not only does it make it difficult to exercise any sort of explicit control over what files get distributed with my package, but it means that when I build my package following an "svn export" instead of an "svn checkout", the contents of my package might be quite different, since without the .svn metadata setuptools will make different choices about what to include.

My question: how can I turn off this terrible behavior, so that "setuptools" treats my project the same way whether I'm using Subversion, or version control it's never heard of, or a bare tree created with "svn export" that I've created at the end of my project to make sure it builds cleanly somewhere besides my working directory?

The best I have managed so far is an ugly monkey-patch:

from setuptools.command import sdist
del sdist.finders[:]

But this is Python, not the jungle, so of course I want a better solution that involves no monkeys at all. How can I tame setuptools, turn off its magic, and have it behave sensibly by looking at the visible, predictable rules in my instead?

Asked by: Abigail566 | Posted: 06-12-2021

Answer 1

I know you know much of this, Brandon, but I'll try to give as a complete answer as I can (although I'm no setuptools gury) for the benefit of others.

The problem here is that setuptools itself involves quite a lot of black magick, including using an entry point called setuptools.file_finders where you can add plugins to find files to include. I am, however, at a complete loss as to how REMOVE plugins from it...

  • Quick workaround: svn export your package to a temporary directory and run the from there. That means you have no svn, so the svn finder finds no files to include. :)

  • Longer workaround: Do you really need setuptools? Setuptools have a lot of features, so the answer is likely yes, but mainly those features are depdenencies (so your dependencies get installed by easy_install), namespace packages (, and entry points. Namespace packages can actually be created without setuptools as well. But if you use none of these you might actually get away with just using distutils.

  • Ugly workaround: The monkeypatch you gave to sdist in your question, which simply makes the plugin not have any finders, and exit quickly.

So as you see, this answer, although as complete as I can make it, is still embarrassingly incomplete. I can't actually answer your question, though I think the answer is "You can't".

Answered by: Sophia865 | Posted: 07-01-2022

Answer 2

Create a file with:

recursive-exclude .
# other commands go here
# to explicitly include whatever files you want

See for the syntax.

Answered by: Lenny905 | Posted: 07-01-2022

Answer 3

Simple solution, do not use setuptools for creating the source distribution, downgrade to distutils for that command:

from distutils.command.sdist import sdist
from setuptools import setup

    # ... all the usual setup arguments ...
    cmdclass = {'sdist': sdist},

Answered by: Edward473 | Posted: 07-01-2022

Answer 4

Probably the answer is in your Do you use find_packages? This function by default uses the VCS (e.g. subversion, hg, ...). If you don't like it, just write a different Python function which collects only the things you want.

Answered by: Hailey514 | Posted: 07-01-2022

Answer 5

I would argue that the default sdist behavior is correct. When you are building a source distribution, I would expect it to contain everything that is checked into Subversion. Of course it would be nice to be able to override it cleanly in special circumstances.

Compare sdist to bdist_egg; I bet only the files that are specified explicitly get included.

I did a simple test with three files, all in svn. Empty dummy.lkj and and with looking like this:

import setuptools
setuptools.setup(name='foobar', version='0.1', py_modules=['foobar'])

sdist creates a tarball that includes dummy.lkj. bdist_egg creates an egg that does not include dummy.lkj.

Answered by: Dexter280 | Posted: 07-01-2022

Answer 6

You probably want something like this:

from distutils.core import setup

def packages():
    import os

    packages = []

    for path, dirs, files in os.walk("yourprogram"):
        if ".svn" in dirs:

        if "" in files:
            packages.append(path.replace(os.sep, "."))

    return packages

    # name, version, description, etc...

    packages = packages(),

    # pacakge_data, data_files, etc...

Answered by: Caroline117 | Posted: 07-01-2022

Similar questions

setuptools - Accessing python egg's own metadata

I've produced a python egg using setuptools and would like to access it's metadata at runtime. I currently got working this: import pkg_resources dist = pkg_resources.get_distribution("my_project") print(dist.version) but this would probably work incorrectly if I had multiple versions of the same egg installed. And if I have both installed egg and development version, then running this cod...

setuptools - How to get the "python" submit information on freshmeat?

This can submit information about your software on pypi: python register But there is not a similar command for submitting information to freshmeat. How could I write a distutils.Command that would let me do the following? python freshmeat-submit

How do I set up Setuptools for Python 2.6 on Windows?

Is there any way to install Setuptools for Python 2.6 in Windows without having an exe installer? There isn't one built at the moment, and the maintainer of Setuptools has stated that it will probably be a while before he'll get to it. Does anyone know of a way to install it anyway?

python - Why does setuptools sometimes delete and then re-install the exact same egg?

I'm trying to install an egg on a computer where an identical egg already exists. Why does it remove the egg and then re-install it? I'm calling easy_install from a script with the options: ['-v', '-m', '-f', 'R:/OPTIONS/Stephen/python_eggs', 'mypkg==1.0_r2009_03_12'] While running the easy_install command this was observed: Searching for mypkg==1.0-r2009-03-12 Best match: ...

python - Excluding a top-level directory from a setuptools package

I'm trying to put a Python project into a tarball using setuptools. The problem is that setuptools doesn't appear to like the way that the source tree was originally setup (not by me, I must add). Everything that I actually want to distribute is in the top-level directory, rather than in a subdirectory like the setuptools docs talk about. The tree has a directory, tests, that I don't want to have in ...

setuptools - Explain Python entry points?

I've read the documentation on egg entry points in Pylons and on the Peak pages, and I still don't really understand. Could someone explain them to me?

python - What if setuptools isn't installed?

I'm just learning the art of writing a file for my project. I see there's lots of talk about setuptools, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if setuptools isn't installed? I understand it's not part of the standard library, so how can you assume the perso...

Python setuptools import error (Using NetBeans)

I tried to find a question that would answer to this question but wasn't succesful, so I made a new question. I'm trying to compile my old Python Tic Tac Toe game in NetBeans, but I get the error message ImportError: No module named setuptools In my actual code I haven't imported a module named setuptools. As much as I understand the compiler generates a file and tries to ...

setuptools - PIP install a Python Package without a file?

I'm trying to figure out how I can install a python package that doesn't have a file with pip. (package in question is Normally I would just checkout the code from the repo and symlink into my site-packages,...

python - Is there a method to find out if a package is to be installed with distutils instead of setuptools?

I can look inside I suppose to see if it's a distutils package. But in the process of familiarizing myself with python package management I have noticed that there seems to be more than one way to do it. So: How can I check an unzipped packages directory or to see how to build it? EDIT: When I say 'build' I mean is it going to use distutils or setuptools, or distribute. I am using build...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python