You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the python ConanAPI, which fails with the following error.
Steps to reproduce
from conan.api.conan_api import ConanAPI
from conans.model.recipe_ref import RecipeReference
conan = ConanAPI()
conan.local.inspect(conan.cache.export_path(RecipeReference.loads("zlib/1.2.13")), [], None)
I think the package reference doesn't matter, use one from your local cache.
Logs
Traceback (most recent call last):
File "/opt/venv/lib/python3.11/site-packages/conans/client/loader.py", line 313, in load_python_file
loaded = imp_util.module_from_spec(spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 570, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/venv/lib/python3.11/site-packages/conans/client/loader.py", line 55, in load_basic_module
module, conanfile = parse_conanfile(conanfile_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/conans/client/loader.py", line 288, in parse_conanfile
module, filename = load_python_file(conanfile_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/conans/client/loader.py", line 351, in load_python_file
raise ConanException("Unable to load conanfile in %s\n%s" % (conan_file_path,
conans.errors.ConanException: Unable to load conanfile in /home/user/.conan2/p/zlib15353192ba4c5/e
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 570, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/venv/lib/python3.11/site-packages/conan/api/subapi/local.py", line 109, in inspect
conanfile = app.loader.load_named(conanfile_path, name=None, version=None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/conans/client/loader.py", line 98, in load_named
conanfile, _ = self.load_basic_module(conanfile_path, graph_lock, remotes=remotes,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/conans/client/loader.py", line 79, in load_basic_module
raise ConanException("Error loading conanfile at '{}': {}".format(conanfile_path, e))
conans.errors.ConanException: Error loading conanfile at '/home/user/.conan2/p/zlib15353192ba4c5/e': Unable to load conanfile in /home/user/.conan2/p/zlib15353192ba4c5/e
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 570, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
The text was updated successfully, but these errors were encountered:
Hi @tbsuht thanks a lot for your question.
As you can see, the API is currently not extensively documented, and this is on purpose - it allows us to have a bit more leeway to stabilize the API until we are happy with it.
Having said that, checking how the CLI uses these methods is usually a good starting point. In this case, the inspect() method is used here. As you can see, this needs to be passed a path to a conanfile.py, while the export method you called returns a folder.
You would probably need to do something like this (Not tested, might not actually work/the syntax might be a bit off, and please do not use it as public documentation!)
thanks, that's working! Don't know whether it makes sense to improve the API to be able to also work with a path to a directory, so that calling get_conanfile_path is not necessary (is then done internally). And of course it shouldn't crash with an exception, but tell me that my path was not providing a conanfile. :)
Environment details
I'm trying to use the python ConanAPI, which fails with the following error.
Steps to reproduce
I think the package reference doesn't matter, use one from your local cache.
Logs
The text was updated successfully, but these errors were encountered: