Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling of multiple deps and different extras #3878

Closed
wants to merge 1 commit into from

Conversation

david-caro
Copy link
Contributor

@david-caro david-caro commented Jul 27, 2016

Very simple handling of the case where you have multiple requirement
definitions that are the same, but differ on the extras, like:

mypgk[extra1]
mypgk[extra2]

will be merged into:

mypgk[extra1,extra2]

Signed-off-by: David Caro david@dcaro.es

@david-caro david-caro changed the title Add handling of multiple deps and different extras WIP Add handling of multiple deps and different extras Jul 27, 2016
@piotr-dobrogost
Copy link

Isn't this the same feature as in pull #3198?

@david-caro
Copy link
Contributor Author

looks the same, looking (it did not work for me locally though... so if it is, it might be broken)

@david-caro
Copy link
Contributor Author

it actually seems to be avoiding the duplicates, that is, ignoring the duplicated entry, instead of merging it into the existing one.

@david-caro
Copy link
Contributor Author

hmmm... might it be that the if condition is wrong there? it actually aggregates the new requirement extras and the existing one, but the if says:

             if (parent_req_name is None and existing_req and not
                    existing_req.constraint and
                    existing_req.extras == install_req.extras):

so it will never get in if the extras are different.

@david-caro
Copy link
Contributor Author

sorry... I'm wrong, that if is to throw the exception

@david-caro
Copy link
Contributor Author

david-caro commented Jul 27, 2016

hmm... so the merging of the extras only gets done if the existing_req.constraint is false, and the install_req.constraint is true:

https://github.com/pypa/pip/blob/master/pip/req/req_set.py#L272

                if not install_req.constraint and existing_req.constraint:
                    if (install_req.link and not (existing_req.link and
                       install_req.link.path == existing_req.link.path)):
                        self.reqs_to_cleanup.append(install_req)
                        raise InstallationError(
                            "Could not satisfy constraints for '%s': "
                            "installation from path or url cannot be "
                            "constrained to a version" % name)
                    # If we're now installing a constraint, mark the existing
                    # object for real installation.
                    existing_req.constraint = False
                    existing_req.extras = tuple(
                        sorted(set(existing_req.extras).union(
                               set(install_req.extras))))
                    logger.debug("Setting %s extras to: %s",
                                 existing_req, existing_req.extras)
                    # And now we need to scan this.
                    result = [existing_req]

Maybe that's the if that is not ok? Shouldn't it be that none of their .constraint is True? (I'll try to find out what the constraint actually means though).

@david-caro
Copy link
Contributor Author

david-caro commented Jul 27, 2016

A quick'n'dirty test just changing the if condition seems to work ok, will investigate but any info is really appreciated 😉

@david-caro david-caro force-pushed the merge_multiple_extras branch from ee5dd85 to c7fcdfe Compare July 29, 2016 09:15
david-caro added a commit to david-caro/invenio-workflows that referenced this pull request Jul 29, 2016
* Removes all the usage of extras for database related requirements
  and uses just the basic invenio-db module, to workaround a
  limitation of pip that is not yet solved, see
  pypa/pip#3878 for more info

Signed-off-by: David Caro <david@dcaro.es>
@david-caro david-caro force-pushed the merge_multiple_extras branch 3 times, most recently from 8889b55 to 4898100 Compare July 29, 2016 18:44
@david-caro
Copy link
Contributor Author

I think this is ready, added also a test for the special case.

@david-caro david-caro changed the title WIP Add handling of multiple deps and different extras Add handling of multiple deps and different extras Jul 29, 2016
david-caro added a commit to david-caro/invenio-workflows that referenced this pull request Aug 2, 2016
* Removes all the usage of extras for database related requirements
  and uses just the basic invenio-db module, to workaround a
  limitation of pip that is not yet solved, see
  pypa/pip#3878 for more info

Signed-off-by: David Caro <david@dcaro.es>
@david-caro
Copy link
Contributor Author

ping?

2 similar comments
@david-caro
Copy link
Contributor Author

ping?

@david-caro
Copy link
Contributor Author

ping?

kaplun pushed a commit to kaplun/invenio-workflows that referenced this pull request Oct 20, 2016
* Removes all the usage of extras for database related requirements
  and uses just the basic invenio-db module, to workaround a
  limitation of pip that is not yet solved, see
  pypa/pip#3878 for more info

Signed-off-by: David Caro <david@dcaro.es>
david-caro added a commit to david-caro/invenio-workflows that referenced this pull request Oct 20, 2016
* Removes all the usage of extras for database related requirements
  and uses just the basic invenio-db module, to workaround a
  limitation of pip that is not yet solved, see
  pypa/pip#3878 for more info

Signed-off-by: David Caro <david@dcaro.es>
@xavfernandez
Copy link
Member

This seems clean enough but this would (if I'm not mistakenà merge a pkg[extra1]<1 and a pkg[extra2]>=2 into a pkg[extra1,extra2]<1 (or >=2 depending on the resolution order).

This would not be much worth than pip's current behavior though.
Any opinion @pypa/pip-committers ?

@david-caro
Copy link
Contributor Author

david-caro commented Oct 27, 2016

This pr already solves the issue of not doing the requirements merge at all, that already allows us to not have to run pip twice on deployment. Si I think that this already improves the current behavior.

Imo the handling of the versioning there might deserve another pull request.

@david-caro
Copy link
Contributor Author

ping?

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Sep 1, 2017
@@ -0,0 +1 @@
/LocalExtras.egg-info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this?

packages=find_packages(),
extras_require={ 'shrubbery': ['LocalExtras[baz]']},
install_requires=['LocalExtras[bar]'],
dependency_links=[DEP_URL]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just add simple as a dependency and use script.pip_install_local in the test, using the package names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reused the already existing LocalExtras package. So, to change that, here would be:

# No need for path_to_url, HERE, DEP_PATH or DEP_URL

setup(
    ...
    install_requires=['simple', 'LocalExtras[Bar]'],
    ...
)

And then in the test something like:

result = script.pip_local_install('--no-index', '-f', data.find_links, to_install + '[shrubbery]')

?

(it's been quite a long time, so my memory is a bit rusty)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Off the top of my head, the test would be:

result = script.pip_local_install(to_install + '[shrubbery]')

@@ -286,6 +286,14 @@ def add_requirement(self, install_req, parent_req_name=None):
existing_req, existing_req.extras)
# And now we need to scan this.
result = [existing_req]
elif not install_req.constraint:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if you could rebase this; there's a few questions I wanna ask but I'll wait for a response from you before asking them.

@pradyunsg
Copy link
Member

Hi @david-caro!

Sorry for the lack of a response for all this while; pip's very short on developer time.

If you could rebase or merge master in this PR and add a news file, that'd be nice. :)

@david-caro david-caro force-pushed the merge_multiple_extras branch from 4898100 to 150f0d5 Compare November 5, 2017 18:23
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Nov 5, 2017
@david-caro david-caro force-pushed the merge_multiple_extras branch from 150f0d5 to b5d22fd Compare November 5, 2017 18:41
@david-caro
Copy link
Contributor Author

I've rebased over latest master, it seems to fail on travis for different reasons though, any help is appreciated (will try to check closer, but might take me some time).

@pradyunsg
Copy link
Member

@david-caro I think I broke the master CI build with merge of #4739. Sorry! :|

I've a fix for the faulty test in #4841.

NEWS.rst Outdated
@@ -18,6 +18,7 @@
- Fix a crash on non ASCII characters from `lsb_release`. (#4062)
- Fix an SyntaxError in an unused module of a vendored dependency. (#4059)
- Fix UNC paths on Windows. (#4064)
- Improve extras dependency handling (#3878)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had a change in process; so instead of modifying NEWS.rst, you'd want to add a file in news/ directory. More about that here: https://pip.pypa.io/en/latest/development/#adding-a-news-entry

packages=find_packages(),
extras_require={ 'shrubbery': ['LocalExtras[baz]']},
install_requires=['LocalExtras[bar]'],
dependency_links=[DEP_URL]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Off the top of my head, the test would be:

result = script.pip_local_install(to_install + '[shrubbery]')

@pradyunsg
Copy link
Member

@david-caro The tests are fixed on master. :)

@pradyunsg pradyunsg added the C: extras Handling optional dependencies label Nov 11, 2017
@pradyunsg pradyunsg closed this Nov 11, 2017
@pradyunsg pradyunsg reopened this Nov 11, 2017
@david-caro david-caro force-pushed the merge_multiple_extras branch from b5d22fd to 119c038 Compare November 12, 2017 15:50
Very simple handling of the case where you have multiple requirement
definitions that are the same, but differ on the extras, like:

   mypgk[extra1]
   mypgk[extra2]

defined in the setup.py file, either as `install_requires` or
`extras_require`, now they will be merged into:

  mypgk[extra1,extra2]

Instead of ignoring the latest appearances.

Signed-off-by: David Caro <david@dcaro.es>
@david-caro david-caro force-pushed the merge_multiple_extras branch from 119c038 to 39a724c Compare November 12, 2017 16:22
@david-caro
Copy link
Contributor Author

Updated and now passing the tests too.

@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Mar 21, 2018
@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label May 11, 2018
@pradyunsg pradyunsg added the C: dependency resolution About choosing which dependencies to install label Feb 25, 2019
@pradyunsg
Copy link
Member

Gonna go ahead and close this due to lack of activity here.

@pradyunsg pradyunsg closed this Feb 25, 2019
@lock
Copy link

lock bot commented May 28, 2019

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

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label May 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 28, 2019
@pradyunsg pradyunsg removed the S: needs triage Issues/PRs that need to be triaged label Feb 21, 2020
@pradyunsg pradyunsg removed the needs rebase or merge PR has conflicts with current master label Apr 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation C: dependency resolution About choosing which dependencies to install C: extras Handling optional dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants