pythonpackagedelete-filepypipyproject.toml

Uninstall package with non-python files that weren't in distribution


I have a python app that has been deposited on pypi as described here. The app runs an external software (blast+) and generates non-python files (various database and txt files, and an xml file that is fed back into the app). Currently, my directory structure (when installed with pip into an environment called env) is:

lib/site-packages/app/file1.py...

after running this becomes:

lib/site-packages/app/file1.py...xml_file.xml, db_file.txt, db_file.pdb ...

When I pip uninstall app:

Found existing installation: app 1.1a0
Uninstalling app-1.1a0:
  Would remove:
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app-1.1a0.dist-info\*
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\*
    c:\users\username\appdata\local\anaconda3\envs\app_env\scripts\app.exe
  Would not remove (might be manually added):
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins.txt
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins_db.pdb
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins_db.phr
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins_db.pin
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins_db.pot
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins_db.psq
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins_db.ptf
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\all_proteins_db.pto
    c:\users\username\appdata\local\anaconda3\envs\app_env\lib\site-packages\app\results.xml

This isn't a massive deal I think, as the files are rewritten every run and if you install my app again it just regenerates the original folder. But I'd rather not have unecessery files cluttering the place up and potentially scaring new users with the would not remove message. Is there a way to specify that the package will generate the files and they should be deleted if the package is (perhaps in pyproject.toml)?

(If not, I could make the user specify a local dir to write the files too, rather than just setting that as the dir holding the python script associated with making the fies, which is what I do now - but I'd rather keep the user interface as simple as possible.)


Solution

  • The typical way to make sure that files are cleaned up by pip is to have the package contain empty placeholder files (with your desired filenames) in it's installation directory.

    As needed, you then overwrite these files at runtime. When it comes time to uninstall, pip will remove files based on their name, not contents.