conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.27k stars 981 forks source link

[bug] Crash when putting package in editable mode with empty conan cache #14411

Closed DoDoENT closed 1 year ago

DoDoENT commented 1 year ago

Environment details

Steps to reproduce

The workaround is to install at least recipes for all dependencies. The actual binaries are not needed. After that, the package can be put into editable mode.

For the rationale of how I discovered that: it happened on my CI job, where I need to put a package into editable mode in order to cross-build it, as discussed here.

Logs

$ conan editable add .
Traceback (most recent call last):
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conan/cli/cli.py", line 272, in main
    cli.run(args)
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conan/cli/cli.py", line 172, in run
    command.run(self._conan_api, args[0][1:])
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conan/cli/command.py", line 141, in run
    sub.run(conan_api, parser, *args)
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conan/cli/command.py", line 155, in run
    info = self._method(conan_api, parent_parser, self._parser, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conan/cli/commands/editable.py", line 29, in editable_add
    ref = conan_api.local.editable_add(args.path, args.name, args.version, args.user, args.channel,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conan/api/subapi/local.py", line 48, in editable_add
    conanfile = app.loader.load_named(path, name, version, user, channel)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dodo/Desktop/conan2-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 "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conans/client/loader.py", line 60, in load_basic_module
    self._pyreq_loader.load_py_requires(conanfile, self, graph_lock, remotes,
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conans/client/graph/python_requires.py", line 68, in load_py_requires
    py_requires = self._resolve_py_requires(py_requires_refs, graph_lock, loader, remotes,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conans/client/graph/python_requires.py", line 86, in _resolve_py_requires
    resolved_ref = self._resolve_ref(requirement, graph_lock, remotes, update)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conans/client/graph/python_requires.py", line 105, in _resolve_ref
    self._range_resolver.resolve(requirement, "py_require", remotes, update)
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conans/client/graph/range_resolver.py", line 34, in resolve
    remote_resolved_ref = self._resolve_remote(search_ref, version_range, remotes, update)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dodo/Desktop/conan2-venv/lib/python3.11/site-packages/conans/client/graph/range_resolver.py", line 75, in _resolve_remote
    for remote in remotes:
TypeError: 'NoneType' object is not iterable

ERROR: 'NoneType' object is not iterable
memsharded commented 1 year ago

Thanks for the report @DoDoENT

Indeed every crash is a bug by definition. I am proposing https://github.com/conan-io/conan/pull/14413 to allow remotes usage to automatically resolve missing python_requires

DoDoENT commented 1 year ago

I tried installing your branch, and it indeed works:

$ conan editable add .
conanfile_utils/0.1.0@nenad/testing: Not found in local cache, looking in remotes...
conanfile_utils/0.1.0@nenad/testing: Checking remote: mbtemp
conanfile_utils/0.1.0@nenad/testing: Downloaded recipe revision 22e39d9779ab95f144c79a6c34b21146
Reference 'ml_models_image_capture/1.0.0' in editable mode

However, what's weird is that conan editable --help does not list new --remote and --no-remote flags:

$ conan editable --help
usage: conan editable [-h] [-v [V]] {add,list,remove} ...

Allow working with a package that resides in user folder.

positional arguments:
  {add,list,remove}  sub-command help
    add              Define the given <path> location as the package <reference>, so when this package is required, it is used from this <path> location instead of the cache.
    list             List all the packages in editable mode.
    remove           Remove the "editable" mode for this reference.

options:
  -h, --help         show this help message and exit
  -v [V]             Level of detail of the output. Valid options from less verbose to more verbose: -vquiet, -verror, -vwarning, -vnotice, -vstatus, -v or -vverbose, -vv or -vdebug, -vvv or -vtrace

nor

$ conan editable add --help
usage: conan editable add [-h] [-v [V]] [--name NAME] [--version VERSION] [--user USER] [--channel CHANNEL] [-of OUTPUT_FOLDER] path

Define the given <path> location as the package <reference>, so when this package is required, it is used from this <path> location instead of the cache.

positional arguments:
  path                  Path to the package folder in the user workspace

options:
  -h, --help            show this help message and exit
  -v [V]                Level of detail of the output. Valid options from less verbose to more verbose: -vquiet, -verror, -vwarning, -vnotice, -vstatus, -v or -vverbose, -vv or -vdebug, -vvv or -vtrace
  --name NAME           Provide a package name if not specified in conanfile
  --version VERSION     Provide a package version if not specified in conanfile
  --user USER           Provide a user if not specified in conanfile
  --channel CHANNEL     Provide a channel if not specified in conanfile
  -of OUTPUT_FOLDER, --output-folder OUTPUT_FOLDER
                        The root output folder for generated and build files

Could it be that due to not having -dev tag, some python files were mixed with my previous conan 2.0.9 installation? But, this time I made sure to delete conan completely from the venv before installing it from your branch.

memsharded commented 1 year ago

Sorry, the bump to specify "-dev" was still not done, I have just done it in https://github.com/conan-io/conan/commit/0ad3bd744524bcbdb7d508536e94eb549d6a938b, I hope it helps to avoid future issues