Skip to content

Include Optional Installs in Our Python Packages #6

@thorwhalen

Description

@thorwhalen

We should include optional installs in our Python packages to allow users to choose which dependencies they want to install based on their needs. This can be achieved by specifying the optional dependencies in the [options.extras_require] section of the setup.cfg file and providing a way for users to choose whether to install them or not.

One possible solution is to parse out comments from the setup.cfg file and inject them into a section of the README.md file that explains how to install the optional dependencies. For example, we could add a section called Optional Dependencies to the README.md file, which would contain the comments extracted from the setup.cfg file along with instructions on how to install them. This would allow users to choose which optional dependencies they want to install and follow the instructions accordingly.

Additionally, we could use the parsed-out comments to include in the final printout of the setup.py file to notify the user of those options that weren't included in the install. This would provide users with a clear understanding of which optional dependencies were not installed and allow them to take action if necessary.

Here's an example of how to specify optional dependencies in the setup.cfg file:

[options]
packages = my_package
install_requires =
    numpy
    pandas

[options.extras_require]
# Include this if you want to use plotting functionality
plotting =
    matplotlib
    seaborn
# Include this if you want to run our tests
testing =
    pytest

In this example, matplotlib and seaborn are listed as optional dependencies under the plotting key, while pytest is listed under the testing key. Users can choose to install these optional dependencies by running the following command:

pip install my_package[plotting,testing]

The setup.cfg can easily be parsed out (note that configparser doesn't do it for you though) to produce a dict akin to

optional_requirements_comments = {
    "plotting": "Include this if you want to use plotting functionality",
    "testing": "Include this if you want to run our tests"
}

This optional_requirements_comments can then be used to make and inject a snippet in README.md and/or add some information in the final install printout.

Was tempted to propose to include some input(...) from the user to chose whether to include optionals or not. But I think that's a bad idea. This would oblige a user to be present during installs, which can be problematic when a human is not present (example: using this stuff in microservices).

Pros/Cons?

chatGPT response:

Pros:

  • Flexibility: By including optional dependencies, we allow users to choose which dependencies they want to install based on their needs.
  • Clarity: By providing instructions on how to install the optional dependencies, we make it easier for users to install the dependencies correctly.
  • Transparency: By including a printout of the optional dependencies that were not installed, we provide users with a clear understanding of what's included in the package and what's not.

Cons:

  • Extra maintenance: There is an extra section to maintain in the README.md file, which could be a burden if the instructions change frequently.
  • Complexity: Including optional dependencies adds complexity to the package, which could make it more difficult to maintain and debug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions