9

I'm migrating from setup.py to pyproject.toml. The commands to install my package appear to be the same, but I can't find what the pyproject.toml command for cleaning up build artifacts is. What is the equivalent to python setup.py clean --all?

ringo
  • 978
  • 7
  • 16
  • 2
    Related discussion: https://discuss.python.org/t/custom-build-targets-for-cleanup-post-pep-518/13741 – sinoroc Jun 08 '22 at 11:40

2 Answers2

6

The distutils command clean is not needed for a pyproject.toml based build. Modern tools invoking PEP517/PEP518 hooks, such as build, create a temporary directory or a cache directory to store intermediate files while building, rather than littering the project directory with a build subdirectory.

Anyway, it was not really an exciting command in the first place and rm -rf build does the same job.

wim
  • 338,267
  • 99
  • 616
  • 750
  • 1
    This isn't true for me in practice, at least with the current way `setuptools` implements `pyproject.toml`. Right now, `build` is making a .egg-info directory inside of my existing /data directory and does not clean it up. – lmhamilt Jul 20 '22 at 20:00
  • @lmhamilt Which part is not true? The egg-info subdirectory holds the package metadata, it's not quite a temporary build artifact like a build subdirectory is. I recommend to add `*.egg-info` to your global gitignore patterns and _not_ clean this directory, because it is actually useful to have in some cases such as a metadata provider for editable installations. Note that `python setup.py clean --all` will not have removed the egg-info directory either. – wim Jul 20 '22 at 20:22
  • Okay, thank you for clarifying. I think I got a little turned around from [the discussion on a github issue about clean & .egg-info](https://github.com/pypa/setuptools/issues/1347). I know it's being put there because I have package data, but I guess I'm still not clear on what it's for since it's not in the binary or wheel that will actually be distributed. – lmhamilt Jul 20 '22 at 20:29
  • 1
    @lmhamilt The same info actually does go into the wheel, but it will be a .dist-info subdirectory with a slightly different structure (e.g. the PKG-INFO will be called METADATA). I believe the .dist-info subdirectory actually gets generated from the egg-info, although setuptools will probably change this to skip the egg and just generate dist-info directly at some stage in the future. – wim Jul 20 '22 at 20:40
5

I ran into this same issue when I was migrating. What wim answered seems to be mostly true.

If you do as the setuptools documentation says and use python -m build then the build directory will not be created, but a dist will.

However if you do pip install . a build directory will be left behind even if you are using a pyproject.toml file. This can cause issues if you change your package structure or rename files as sometimes the old version that is in the build directory will be installed instead of your current changes.

Personally I run pip install . && rm -rf build or pip install . && rmdir /s /q build for Windows. This could be expanded to remove any other unwanted artifacts.

informatik01
  • 16,038
  • 10
  • 74
  • 104
ptth222
  • 76
  • 1
  • 3