Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 28, 2024

Conversation

carlsmedstad
Copy link
Contributor

@carlsmedstad carlsmedstad commented Feb 13, 2024

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
Copy link
Contributor

(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
Copy link
Contributor Author

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

@dougthor42
Copy link

dougthor42 commented Mar 18, 2024

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

Not needed - update the destination instance instead.

@dougthor42
Copy link

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
Copy link

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
Copy link
Contributor Author

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

@Secrus
Copy link
Member

Secrus commented Aug 21, 2024

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

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
@carlsmedstad
Copy link
Contributor Author

@Secrus Thank you! Rebase done.

@carlsmedstad
Copy link
Contributor Author

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

@Secrus Secrus changed the title Add --force option that overwrites existing files Add --overwrite-existing option that overwrites existing files Aug 28, 2024
@Secrus Secrus merged commit 0b003fa into pypa:main Aug 28, 2024
21 checks passed
@carlsmedstad carlsmedstad deleted the implement-force-option branch August 29, 2024 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --force option
4 participants