pip-tools icon indicating copy to clipboard operation
pip-tools copied to clipboard

Extra requirements are lost in pip-compile comments

Open sawatsky opened this issue 2 years ago • 5 comments

I have a requirements.txt file with the following:

my-package[extra]~=1.0
my-sub-package~=1.1

When I run python -m piptools compile, the extra requirement [extra] gets lost in the list of via requirements under my-sub-package:

my-package[extra]==1.0.0
    # via -r requirements.txt
my-sub-package==1.1.1
    # via
    #   -r requirements.txt
    #   my-package

I need the extra requirements to remain in the comments. We're parsing the output file of pip-compile that's breaking because the [extra] requirement is gone from the comments.

sawatsky avatar Feb 08 '22 17:02 sawatsky

Let's say there are two subpackages, package A is always required by the top level package, and package B is only required when [EXTRA] is specified.

Should the annotations for both of these subpackages include the [EXTRA], or only for package B?

AndydeCleyre avatar Feb 08 '22 18:02 AndydeCleyre

I'm inclined to think that pip-compile should strip all extras in compiled requirements.txt. See explanation by @FlorentJeannot in https://github.com/jazzband/pip-tools/pull/1453#discussion_r671595549. Of course this requires some discussion.

atugushev avatar Feb 20 '22 07:02 atugushev

@atugushev I think we could have something like that in the requirements.txt:

my-package==1.0.0
    # via -r requirements.txt
my-sub-package==1.1.1
    # via
    #   -r requirements.txt
    #   my-package[extra]

Meaning: we strip all extras, but we keep them in the comments for clarity if someone wants to review where the package comes from. What do you think? @sawatsky would my example above meet your needs?

FlorentJeannot avatar Feb 20 '22 10:02 FlorentJeannot

what if my-sub-package is required by my-package, my-package[extra1], and my-package[extra2] in sub-dependencies? Then it would be:

my-sub-package==1.1.1
    # via
    #   -r requirements.txt
    #   my-package
    #   my-package[extra1]
    #   my-package[extra2]

or like this (but here we need to merge extras somehow):

my-sub-package==1.1.1
    # via
    #   -r requirements.txt
    #   my-package
    #   my-package[extra1,extra2]

I'd still prefer to strip all extras:

my-sub-package==1.1.1
    # via
    #   -r requirements.txt
    #   my-package

atugushev avatar Feb 20 '22 10:02 atugushev

Good point, I agree with you then.

FlorentJeannot avatar Feb 20 '22 10:02 FlorentJeannot