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 `--force` option #215

Closed carlsmedstad closed 1 week ago

carlsmedstad commented 6 months ago

Feature request for a new option, --force, that will disregard and overwrite already existing files when installing a package.

I'd be happy to submit a PR for this, unless there is something I haven't considered and this is a bad idea.

Context

I maintain a number of Python projects in the Arch User Repository (AUR) and for projects that require tests to run on an installed package I use the following pattern:

build() {
  cd "$_archive"

  python -m build --wheel --no-isolation
}

check() {
  cd "$_archive"

  rm -rf tmp_install
  python -m installer --destdir=tmp_install dist/*.whl

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  export PYTHONPATH="$PWD/tmp_install/$site_packages"
  pytest
}

I.e. to install the package to a temporary location and add that to PYTHONPATH before running the tests.

The rm invocation is necessary when the directory is not clean and the package has already been installed in the tmp_install directory. However, this invocation could be made redundant by installer having the option to --force the install and disregard/overwrite any existing package files.