-2

I have a very complex Python library that is used by several people/projects for different purposes.

The structure is basically the same as many Python libraries, but I would like to give the ability of a partial install.

project_name/
  |__ package
  |      |__ submodule1
  |      |       |__ __init__.py
  |      |__ submodule2
  |      |       |__ __init__.py
  |      |__ submodule3
  |      |       |__ __init__.py
  |      |__ submodule4
  |      |       |__ __init__.py
  |      |__ __init__.py
  |      |__ types.py
  |__ setup.cfg
  |__ setup.py

I would like to give people the ability to people to install everything, or what they really require, because they are not dependent.

I tried several options like:

  • Hacking packages=find_packages(*) by myself, but I would like something more official. It is not my intention to split into several Git repositories.

  • Customizing pip install by using the cmdclass with a custom install option, but, AFAIK, this is deprecated in pip now.

  • Intercepting somehow the extras_require to use it within packages and create something like pip install package[submodule1], but no luck either.

Any professional suggestion is welcome :)

2
  • Before I go about writing a longer answer, I just wanted to check and confirm that you have already looked at pip's bracket [] notation for the install function, and that it cannot be used for your use case? logan.tw/posts/2015/01/01/python-package-manager-pip Commented Aug 29 at 20:36
  • You need to create multiple "projects", that's it. There is no other way. -- You can make use of "namespace packages" and "optional dependencies" (aka "extras") to make things nicer. But if things have to be installed separately, then they have to be separate projects. Commented Aug 30 at 15:23

1 Answer 1

0

You can actually use extras_require in setup.py:

# setup.py
from setuptools import setup, find_packages

setup(
    name="project_name",
    version="0.1",
    packages=find_packages(),
    extras_require={
        "submodule1": [],
        "submodule2": [],
        "submodule3": [],
        "submodule4": [],
        "all": [],
    },
)

Reference

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @0ro2. I don't want to install the dependencies separately. I want to install the submodules dynamically. Because they are just standalone libraries.
Oh okay, then you should be able to just replace dependency1, dependency2, dependency3, ..., as well as the list for all with a blank list ([]).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.