How to install a python package into a subdirectory with setuptools?

Viewed 183

I'm trying to make a 3rd party project installable via pip. The source repo is currently laid out like this

/plugins
/python
  /foo
    __init__.py

The foo package is the one that needs to be importable. The project wasn't initially designed to be pip-installable, so it expects the plugins directory to be installed with the same relative depth as the source repo (2 levels up)

I added a setup.py that will install foo, but it just gets installed into Lib/site-packages as Lib/site-packages/foo. Unfortunately, I have no way to install plugins to Lib/plugins to maintain the same relative plugins directory location, and even if I could, I don't think I would want to install to a general location like that.

I'd prefer to install the package and plugins into a subdirectory inside Lib/site-packages, so that it looks something like this

/Lib
  /site-packages
    /foo-prefix-dir
      /plugins
      /python
        /foo
          __init__.py

The /foo-prefix-dir/python directory is what would get added to PYTHONPATH, probably using a .pth file, so that foo is still importable with the correct relative relation to the plugins directory.

Is there any way to distribute a python package this way?

0 Answers
Related