pypa / installer

A low-level library for installing from a Python wheel distribution.
https://installer.readthedocs.io/
MIT License
123 stars 51 forks source link

Add --overwrite-existing option that overwrites existing files #216

Closed carlsmedstad closed 1 week ago

carlsmedstad commented 6 months ago

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

jvolkman commented 6 months ago

(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?

carlsmedstad commented 6 months ago

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

dougthor42 commented 5 months ago

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

Not needed - update the destination instance instead.

dougthor42 commented 5 months ago

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 commented 5 months ago

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

carlsmedstad commented 5 months ago

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

Secrus commented 2 weeks ago

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

carlsmedstad commented 2 weeks ago

@Secrus Thank you! Rebase done.

carlsmedstad commented 2 weeks ago

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