Skip to content

Map optional extras to the source modules allowed to import them #1663

Description

@akul-ameya

Optional extras under [project.optional-dependencies] are currently treated as regular dependencies. That means this is invisible to deptry:

[project]
dependencies = ["httpx"]

[project.optional-dependencies]
snowflake = ["snowflake-connector-python"]

mypackage/core.py

import snowflake.connector

Users who install mypackage without [snowflake] then fail at import time. Treating the extra as a dev group (optional_dependencies_dev_groups) is the wrong fix, because mypackage/snowflake.py is allowed to import snowflake.connector when the extra is installed. That import does not need to be ImportError-guarded.

A mapping from extra name to first-party modules would catch both "base imports an extra-only package" and "the postgres extra imports a snowflake-only package".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions