installer icon indicating copy to clipboard operation
installer copied to clipboard

Add --force option that overwrites existing files

Open carlsmedstad opened this issue 1 year ago • 6 comments

Took a stab at implementing what I suggested in #215.

Implement the --force option that, if supplied, will make installer overwrite any already existing package files instead of failing. With this flag, installer can be used in an idempotent manner, i.e. the same command can be executed multiple times with the same result:

python -m installer --force --destdir=tmp dist/*.whl
python -m installer --force --destdir=tmp dist/*.whl
python -m installer --force --destdir=tmp dist/*.whl

One other candidate for the option name I have in mind is --overwrite which I think is more mechanically descriptive, but it might be less ubiquitous, as tools like mv and cp use -f/--force.

Resolves #215

carlsmedstad avatar Feb 13 '24 20:02 carlsmedstad

(I originally made this comment on the attached issue, but meant to make it here)

--force is a pretty generic name. There are other causes of installation failures - such as problems with the RECORD file - that won't be ignored by --force. Maybe rename to something more specific like --overwrite-existing?

jvolkman avatar Feb 15 '24 21:02 jvolkman

That's a much better name, thanks. Changed it in 829b4839aaacefa53ae64411b953bba34f22276c.

carlsmedstad avatar Feb 16 '24 08:02 carlsmedstad

~~Could this be added as an arg to install as well?~~

Not needed - update the destination instance instead.

dougthor42 avatar Mar 18 '24 18:03 dougthor42

Oh nevermind, I see that I'll be able to set it on the dest.

destination = SchemeDictionaryDestination(..., overwrite_existing=True)
installer.install(
    source=wheel_source,
    destination=destination,
    additional_metadata={"INSTALLER": "me"},
    overwrite_existing=True,  # New
)

Sorry for the noise!

dougthor42 avatar Mar 18 '24 18:03 dougthor42

Is there anything that I can do to help get this merged? I'm looking forward to being able to use this in https://github.com/bazelbuild/rules_python

dougthor42 avatar Mar 20 '24 02:03 dougthor42

Echoing @dougthor42, is there anything I can do to have this merged and eventually released? Thanks!

carlsmedstad avatar Mar 30 '24 14:03 carlsmedstad

@carlsmedstad please rebase your changes and ping me once it's ready and I will review

Secrus avatar Aug 21 '24 09:08 Secrus

@Secrus Thank you! Rebase done.

carlsmedstad avatar Aug 22 '24 09:08 carlsmedstad

Let me know if you'd like me to squash the commits.

carlsmedstad avatar Aug 22 '24 09:08 carlsmedstad