5

I'm developing a package which has a few optional dependencies and 'extras'.

Goal: I want the following two things to work:

  1. Execute my post-install code
  2. Allow for 'extras' installation

Status: Currently I have been able to:

  1. Use python setup.py install or python setup.py develop to execute post-install code; using the method here https://stackoverflow.com/a/36902139/8473819

  2. Use pip install PACKAGE[extra] to properly install/manage extras or different package configurations.

In my research I have not found a feature of python setup.py to allow 'extras' nor a pip install feature to allow my post-install code to execute. *changed, see update

Notes:

Using pip 9.0.1, python 3.6

My post-install is simple, it just gets some information about available resources, creates a file, and prints some feedback using print().

Question: Have I missed some features, or is there not a way to cleanly accomplish both actions with just one of the install methods?

Update:

The pip install method does in fact execute my post-install code (prints are piped somewhere, only visible using -vvv arg). Another problem is that (unless installed with -e) it uses a temporary build directory like C:\Users\USER\AppData\Local\Temp\pip-ix4d6hv3-build then cleans it up, instead of building in the local directory. In this case, the my file creation either does not work, I have been unable to locate where the file is created, or it is cleaned up by pip (I tried --no-clean with same results).

Reference for others:

If installing from a local directory (not a tar/whl/etc. file), the package will be copied to a temporary directory see ^update^. Then a setuptools.command.egg_info subclass in setup.py will be executed before setuptools.command.install or setuptools.command.develop (passed in cmdclass arg).

Tim
  • 168
  • 8
  • 3
    1. There's no way to detect `extras` in `setup.py` because they are not passed to it - the extras are parsed and handled by `pip`/`easy_install` and are not passed any further. 2. The `install` command is not executed by `pip`, so you post-install code will not be executed either. In fact, `pip` does not use or ship the `setup.py` at all, since there is no place for it in the wheel format specification. – hoefling Feb 20 '18 at 08:21
  • Pip still uses setup() inside setup.py though, to obtain package information. So does pip ignore the 'cmdclass' argument entirely or just the 'install'/'develop' where post-install functions are placed? Note My package is not on pypi, I pip install from local. – Tim Feb 20 '18 at 19:19

0 Answers0