pypa / build

A simple, correct Python build frontend
https://build.pypa.io
MIT License
738 stars 120 forks source link

Add option for cleaning outdir before using it #455

Open ssbarnea opened 2 years ago

ssbarnea commented 2 years ago

As many bugs can happen when dist/ output folder ends-up collecting artifacts from previous runs, it is extremely common to want to clean the folder before running build, so it will only contain the outcome of a single build command execution.

As cleaning a folder from shell is not really portable across all platforms people end-up using ugly python snippets before running build. Examples like https://github.com/ansible/ansible-lint/blob/main/tox.ini#L173-L181 are quite common.

In order to simplify use, I would like to propose adding an option to build that performs the cleaning, so users will not longer have to implement such workarounds. I would not mind even making the cleaning enabled by default but I guess it would be found dangerous as some might try to use . as output directory.

WDYT? Should I try to make pull-request for it?

layday commented 2 years ago

I don't think that build should be able to delete files or folders it might not have created itself. If the impetus for clearing dist out is that you're running twine dist/*, a better solution IMO would be https://github.com/pypa/build/issues/198. As for using tox as a task runner, the new tox release should make that easier with the introduction of the toxfile.

ssbarnea commented 2 years ago

I am talking about cleaning files created by build itself, on previous runs, not about leftovers from other tools. If the package version changes, new files are created and when using setuptools-scm, version would change on any commit.

Few years back I was considering writing a tox plugin that can clean some folders like dist/ on runs but the reality is that issue is not related to tox, it related to build itself, so it would be better to improve the tool and allow users to avoid this issue regardless if they use tox or another task runner.

On CI/CD cleaning is usually not a problem as you likely start from clean. Even so I do remember some cases where even on these we ended up with multiple artifacts (release pipelines that create additional release commits being such an example).

Regarding implementation, we could make the option to clean only file patterns that are matching the package name, file foo-*.{whl,tag.gz}.