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

[bug] [regression] conan 1.26.0 breaks python requirements with custom classes #7196

Closed
DoDoENT opened this issue Jun 15, 2020 · 5 comments
Closed
Assignees
Milestone

Comments

@DoDoENT
Copy link
Contributor

DoDoENT commented Jun 15, 2020

Consider this example: conan-issue.zip

It contains two conanfiles, a base conan file, which contains a base for conan file and custom extension of conans.CMake class, which allows some customizations of the CMake helper (better described in issue #3099), and normal conanfile that python_requires the base.

With Conan 1.25.2, this works as expected:

cd base
conan export ./conanfile.py user/testing
cd ..
conan create ./conanfile user/testing

With conan 1.26.0 the first conan export yields following error:

ERROR: Error loading conanfile at '/Users/dodo/Desktop/conan-issue/base/conanfile.py': Unable to load conanfile in /Users/dodo/Desktop/conan-issue/base/conanfile.py
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/dodo/Desktop/conan-issue/base/conanfile.py", line 5, in <module>
    class CMake(conans.CMake):
TypeError: function() argument 1 must be code, not str

Even if I export the base with conan 1.25.2 and then attempt to use derived with conan 1.26.0 I still get a crash:

ERROR: Error loading conanfile at '/Users/dodo/Desktop/conan-issue/conanfile.py': Error loading conanfile at '/Users/dodo/.conan/data/base/1.0.0/user/testing/export/conanfile.py': Unable to load conanfile in /Users/dodo/.conan/data/base/1.0.0/user/testing/export/conanfile.py
KeyError: base/1.0.0@user/testing

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/conans/client/loader.py", line 352, in _parse_conanfile
    loaded = imp.load_source(module_id, conan_file_path)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/dodo/.conan/data/base/1.0.0/user/testing/export/conanfile.py", line 5, in <module>
    class CMake(conans.CMake):
TypeError: function() argument 1 must be code, not str
@memsharded
Copy link
Member

This is not because of python_requires, but because of inheriting from conans.CMake, as we changed the interface for the new "toolchain" feature. Proposing a new name in #7198 to avoid the issue, though we might want to consider other alternatives, as metaclasses.

@rddesmond
Copy link

rddesmond commented Jun 15, 2020

Beat me to the story! The workaround I took was

# In 1.26.0, conans.CMake became a factory so we need to pick the class it returns
try:
    from conans.client.build.cmake import CMakeBuildHelper as CMake
except ImportError:
    from conans import CMake

@memsharded
Copy link
Member

Thanks for the hint @rddesmond
Don't hesitate to report these issues before implementing workarounds, when new versions introduce regressions, we are willing to revert them and provide other alternatives, but we need to know that we are breaking :)

@rddesmond
Copy link

Thanks, @memsharded, great work on conan! s@DoDoENT beat me to writing the story (I swear I'm not shy -- I added a different one on Friday), and I found the workaround I posted while triaging.

@memsharded
Copy link
Member

Fixed by #7200, will be released soon in 1.26.1 patch release.

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

No branches or pull requests

3 participants