Skip to content

Does Poetry support recursive extras? #3369

Closed

Description

@alexifm
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Issue

Does Poetry support recursive (for lack of a better term, it's early) extras best exemplified by this pyproject.toml snippet?

[tool.poetry.dependencies]
attrs = "~19.3"
pandas = "~1.1"
# optional
quandl = { version = "~3.5.2", optional = true }
matplotlib = { version = "~3.3.0", optional = true }
networkx = { version = "~2.4.0", optional = true }
scikit-learn = { version = "~0.22.0", optional = true }

[tool.poetry.extras]
quandl = ["quandl"]
viz = ["matplotlib", "networkx"]
ml = ["viz", "scikit-learn"]
all = ["ml", "quandl"]

Activity

  1. sinoroc commented on Nov 16, 2020

    @sinoroc

    I don't think so. Did you try it? What was the result?

  2. alexifm commented on Nov 16, 2020

    @alexifm
    Author

    Did not work. Can you suggest a location in the codebase to look for where I could potentially add this contribution if it's considered desirable? (I have yet to reliably figure out the poetry codebase)

  3. alexifm commented on Nov 16, 2020

    @alexifm
    Author

    Seems like it could be here?

    def get_extra_package_names(

    Specifically modify this list creation to look up packages if the name is an extra:

    extra_package_names = [

  4. n8sty commented on Nov 16, 2020

    @n8sty
    Contributor

    This might be too pedantic of a concern but you should make sure to guard against situations where an extra and a package could have the same name. In your example file, whatever algorithm you implement would need to know that the quandl referenced in the all section is different than the "quandl" referenced in the quandl extras line.

    I'm not sure the increased ease of nesting optional dependencies is worth the potential brittleness of solving for the above.

  5. alexifm commented on Nov 16, 2020

    @alexifm
    Author

    @n8sty Yes, that is something I avoid but unfortunately didn't pay close attention to in that example.

    As for an implementation, I think the simplest thing would be to just fail and have the error suggest picking a different name that doesn't create a conflict.

    Another thing is that it seems like poetry-core is where package building is handled and it's much less clear to me how it resolves the packages in an extras definition than this function I identified earlier.

    ETA: Looks like this is where poetry-core could handle the recursive extras:
    https://github.com/python-poetry/poetry-core/blob/71f35e82188b85ea690735f8ee554b9f5a74486e/poetry/core/factory.py#L96-L109

  6. sinoroc commented on Nov 17, 2020

    @sinoroc

    Personally I am not convinced there is a need for such a feature with such a notation. Seems to be adding more confusion. You may want to give the UX a second look

    See if it would make sense in the context of the dependencies groups feature (planned for v1.2).


    If I were to change extras in order to avoid repetition for dependencies that are in multiple extras (in a way this is what you are trying to solve, right?), this is what I would aim for, but I think the dependencies groups feature already covers this (I have not read the full discussion on this, so I might be wrong):

    libraryA = { "*", in_extras = [ "alpha", "bravo" ] }
    ilbraryB = { "*", in_extras = [ "alpha" ] }
    
  7. finswimmer commented on Nov 18, 2020

    @finswimmer
    Member

    Is this something that is defined in any PEP? If so, poetry should support it. If not, then probably the corresponding wheel/sdist will not be interpreted correct by other tools and poetry should not support it as well.

  8. sinoroc commented on Nov 19, 2020

    @sinoroc

    @finswimmer I think they want enhancements to the notation in pyproject.toml, that would avoid some repetition of dependencies in that file. And poetry should take care to expand the notation to make it standard-conform in the distribution's metadata.

  9. sinoroc commented on Nov 25, 2020

    @sinoroc

    For comparison, this is how it can be done with setuptools setup.cfg: https://stackoverflow.com/a/61610341/

  10. alexifm commented on Dec 2, 2020

    @alexifm
    Author

    @sinoroc I'm okay with dropping this in favor of the groups approach mentioned for the upcoming release. Not worth it to support two approaches, even if it's not that far off what setuptools allows.

  11. smheidrich commented on Mar 11, 2023

    @smheidrich
    Contributor

    Probably worth pointing out that since the last comment here, recent versions of setuptools+Pip have started supporting recursive extras specified without any hacks (i.e. not like in that StackOverflow answer), by simply having dependencies on the current package itself with [extra1,extra2,...] appended.

    As far as I can tell that wouldn't work with how extras and dependencies are currently specified in Poetry, as dependencies can only be listed once and so there is no way to have e.g. extra A depend on currentpackage[X, Y] and extra B depend on currentpackage[Z]. So that's a shame.

    And by the way, I don't see how groups solve this issue at all - they are only meant for development of the package itself, aren't they? Whereas extras are user-facing. Reopen?

  12. github-actions commented on Feb 29, 2024

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  13. locked as resolved and limited conversation to collaborators on Feb 29, 2024
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions