setuptools: setup.py leaves build, dist, .egg-info etc + even clean doesn't remove them
By default, setup.py leaves build, dist, ${project_name}.egg-info directories in a projects directory.
I’m not convinced these need to be here these days, certainly feels messy to have these.
Putting all this output into one directory would be some improvement. But maybe there’s a better solution ?
python setup.py clean
doesn’t even delete these without adding hacks.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 60
- Comments: 17
Commits related to this issue
- Setuptools creates a dist directory Unfortunately setuptools creates a superfluous 'dist' directory that isn't removed with clean... https://github.com/pypa/setuptools/issues/1347 Working around ... — committed to torproject/stem by atagar 4 years ago
- Clean up after setuptools Setuptools 'clean' command doesn't work... https://github.com/pypa/setuptools/issues/1347 Cleaning up after the turds it creates when we run our tests. — committed to torproject/stem by atagar 4 years ago
- [PACKAGING] Mitigates cache issues by cleaning previous Setuptools build > See related : pypa/setuptools#1347 — committed to HorlogeSkynet/archey4 by deleted user 3 years ago
- Fix `error: unrecognized arguments` Clean up `dist` directory before starting the build. This is in order to prevent `error: unrecognized arguments` at `python -m install` time, which would occur if ... — committed to archlinux/aur by claui a year ago
Rather than trying to clean up files from the source directory, would it be better to be able to do out-of-source package builds? Something like this:
cd /tmp/build && python /path/to/setup.py
. That way those generated files never touch the source directory in the first place.@maphew I suggest that it be added as functionality (it doesn’t work that way currently), then documented as a best practice. It shouldn’t break the way it’s done now.
Trying to make a nice workaround for this stuff, I couldn’t manage with changing workdir - it fails with line “error: package directory ‘my_root_package’ does not exist”. In my case I just build a source distribution with no data files, extensions etc, just plain python archive. I found a workaround for this issue - having workdir at repo root as usual, use command:
python setup.py egg_info --egg-base tmp/build sdist --dist-dir tmp/dist
How it works:
Not really convenient solution, but it does not require any extra code.
I completely agree. I find it very strange that there is no option to select a different output folder AND that the clean command does not really remove the generated artifacts.
I think a out-of-source build and proper clean should be natively supported by setuptools, as per previous comments.
Like others who’ve commented here, I have had to resort to a custom clean command to remove the dist directory.
It would be good if this could be fixed in setuptools. A user would reasonably expect that
python setup.py clean --all
would clean all directories. However, I haven’t come across a situation where I want a partial clean so I’m not sure there is much point in a--all
flag: clean should just clean everything.I’ve got setupext-janitor working and issued a PR to the base master https://github.com/dave-shawley/setupext-janitor/pull/14
Other solutions I’ve found which have been refined a stage above “here’s what’s worked for me” code snippets here and on stack overflow:
https://github.com/dave-shawley/setupext-janitor - looks to be clean, well featured and documented. Hasn’t been touched in awhile and there’s a couple easy win PR’s open. Might not take much to dust off and press into service though.
https://scikit-build.readthedocs.io/en/latest/_modules/skbuild/command/clean.html - part of a big community so should be more tested. Has the advantage being easy to read and understand the essential bit. Looks harder to drop into any old project though.
If you find an easy-to-use built-in solution, it would be great to post it here as well: https://stackoverflow.com/questions/64952572/output-directories-for-python-setup-py-sdist-bdist-wheel Thanks!