Skip to content

feature: Improve dependency-cycle error to show the cycle - #11519

Merged
memsharded merged 3 commits into
conan-io:developfrom
paulharris:improve-dependency-cycle-message
Jun 28, 2022
Merged

memsharded merged 3 commits into
conan-io:developfrom
paulharris:improve-dependency-cycle-message

Conversation

@paulharris

@paulharris paulharris commented Jun 24, 2022

Copy link
Copy Markdown
Contributor

Changelog: Feature: Improve dependency-cycle error to show the cycle.
Docs: Omit


Original message isn't help when diagnosing problems with a recipe...
Now it will print out all the X->Y dependencies that remain after the
irrelevant components have been eliminated.

Within that list will be the problematic cycle.

For example, as a test I introduced a cycle into my prototype VTK recipe,

I added:
self.cpp_info.components["vtksys"].requires.append("CommonDataModel")

The cycle would be:
vtksys -> CommonDataModel -> CommonCore -> vtksys

The message was a bit more verbose than that, but enough to be helpful:

ERROR: There is a dependency loop in 'self.cpp_info.components' requires:
   CommonTransforms requires CommonMath
   CommonDataModel requires CommonCore
   CommonMath requires CommonCore
   CommonCore requires vtksys
   CommonTransforms requires CommonCore
   CommonCore requires kwiml
   CommonDataModel requires CommonMath
   vtksys requires CommonDataModel
   CommonDataModel requires CommonTransforms
   CommonMath requires kissfft
  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

Original message isn't help when diagnosing problems with a recipe...
Now it will print out all the X->Y dependencies that remain after the
irrelevant components have been eliminated.

Within that list will be the problematic cycle.

For example, as a test I introduced a cycle into my prototype VTK recipe,

I added:
self.cpp_info.components["vtksys"].requires.append("CommonDataModel")

The cycle would be:
vtksys -> CommonDataModel -> CommonCore -> vtksys

The message was a bit more verbose than that, but enough to be helpful:

ERROR: There is a dependency loop in 'self.cpp_info.components' requires:
   CommonTransforms requires CommonMath
   CommonDataModel requires CommonCore
   CommonMath requires CommonCore
   CommonCore requires vtksys
   CommonTransforms requires CommonCore
   CommonCore requires kwiml
   CommonDataModel requires CommonMath
   vtksys requires CommonDataModel
   CommonDataModel requires CommonTransforms
   CommonMath requires kissfft

@memsharded memsharded left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems a helpful addition of error message.
It would be necessary to add an integration test, please try to add it, or ask for help or guidance if you need it.

@paulharris

Copy link
Copy Markdown
Contributor Author

@memsharded I had a look, and while I could probably figure it out with time, I'm a low on time.

I'd want to test that it outputs an error message with an expected error.
Recipe file:

from conan import ConanFile

class TestcycleConan(ConanFile):
    name = "testcycle"
    version = "1.0"

    def package_info(self):
        self.cpp_info.components["c"].requires = ["b"]
        self.cpp_info.components["b"].requires = ["a"]
        self.cpp_info.components["a"].requires = ["c"] # cycle!

Error message (ignoring all the CCI hook errors I see):

conan create . 1.0@ccitest/cycle
...
ERROR: There is a dependency loop in 'self.cpp_info.components' requires:
   a requires c
   b requires a
   c requires b

How would I implement such a test?

@memsharded

Copy link
Copy Markdown
Member

Thanks, that is enough, I'll add the test for you.

@memsharded memsharded added this to the 1.50 milestone Jun 28, 2022
@memsharded
memsharded merged commit a498cf2 into conan-io:develop Jun 28, 2022
@memsharded

Copy link
Copy Markdown
Member

Thanks very much for your contribution!
It will be released next 1.50

@paulharris
paulharris deleted the improve-dependency-cycle-message branch June 29, 2022 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants