Skip to content

python_requires fails when remote is in CONAN_REMOTES but not added to conan #331

Closed
@madebr

Description

@madebr

This happens on CI.

When using a python_requires in a recipe that is available on a remote but not in the local cache,
the ConanMultiPackager constructor throws because while loading the conanfile class, the remotes in CONAN_REMOTES is not yet added to the remotes of conan.

reproducer:

YOURUSERNAME=... #madebr
YOURREMOTEURL=... #https://api.bintray.com/conan/madebr/maarten
YOURPASSWORD=... #0123456789abcdef01234567890

mkdir /tmp/cpt_test
cd /tmp/cpt_test
mkdir pkg_base && cd pkg_base
cat >conanfile.py <<EOF
from conans import ConanFile
class PkgBase(ConanFile):
    name = "pkg_base"
    version = "1.2"
EOF

cd /tmp/cpt_test
cat >conanfile.py  <<EOF
from conans import python_requires

base = python_requires("pkg_base/1.2@testremote/testing")

class Pkg(base.PkgBase):
    name = "pkg"
EOF

cat >build.py <<EOF
from conan.packager import ConanMultiPackager
builder = ConanMultiPackager()
builder.add_common_builds()
builder.run()
EOF

conan remote add -f testremote $YOURREMOTEURL
conan export pkg_base pkg_base/1.2@testremote/testing
conan user -r testremote -p "$YOURPASSWORD" "$YOURUSERNAME"
conan upload pkg_base/1.2@testremote/testing -r testremote
conan remote remove testremote
conan remove pkg_base -f

CONAN_PASSWORD=$YOURPASSWORD CONAN_USERNAME=$YOURUSERNAME CONAN_REMOTES=$YOURREMOTEURL@True@testremote python3 build.py

The output of this last command is:

$ CONAN_PASSWORD=$YOURPASSWORD CONAN_USERNAME=$YOURUSERNAME CONAN_REMOTES=$YOURREMOTEURL@True@testremote python3 build.py

****************************************************************************************************

   ____ ____ _____    __   ____                          ____            _                      _____           _      __  
  / ___|  _ \_   _|  / /  / ___|___  _ __   __ _ _ __   |  _ \ __ _  ___| | ____ _  __ _  ___  |_   _|__   ___ | |___  \ \ 
 | |   | |_) || |   | |  | |   / _ \| '_ \ / _` | '_ \  | |_) / _` |/ __| |/ / _` |/ _` |/ _ \   | |/ _ \ / _ \| / __|  | |
 | |___|  __/ | |   | |  | |__| (_) | | | | (_| | | | | |  __/ (_| | (__|   < (_| | (_| |  __/   | | (_) | (_) | \__ \  | |
  \____|_|    |_|   | |   \____\___/|_| |_|\__,_|_| |_| |_|   \__,_|\___|_|\_\__,_|\__, |\___|   |_|\___/ \___/|_|___/  | |
                     \_\                                                           |___/                               /_/ 

Version: 0.23.0fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

 >> Branch detected
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
pkg_base/1.2@testremote/testing: Not found in local cache, looking in remotes...
pkg_base/1.2@testremote/testing: Trying with 'conan-center'...
pkg_base/1.2@testremote/testing: Trying with 'bincrafters'...
Traceback (most recent call last):
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/loader.py", line 45, in load_class
    return self.cached_conanfiles[conanfile_path]
KeyError: '/tmp/cpt_test/conanfile.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/python_requires.py", line 33, in _look_for_require
    python_require = self._cached_requires[require]
KeyError: 'pkg_base/1.2@testremote/testing'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/loader.py", line 254, in _parse_conanfile
    loaded = imp.load_source(module_id, conan_file_path)
  File "/usr/lib64/python3.6/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/cpt_test/conanfile.py", line 3, in <module>
    base = python_requires("pkg_base/1.2@testremote/testing")
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/python_requires.py", line 58, in __call__
    python_req = self._look_for_require(require)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/python_requires.py", line 41, in _look_for_require
    recorder=ActionRecorder())
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/proxy.py", line 34, in get_recipe
    result = self._get_recipe(ref, check_updates, update, remote_name, recorder)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/proxy.py", line 50, in _get_recipe
    remote, new_ref = self._download_recipe(ref, output, remote_name, recorder)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/proxy.py", line 157, in _download_recipe
    raise NotFoundException(msg)
conans.errors.NotFoundException: Unable to find 'pkg_base/1.2@testremote/testing' in remotes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "build.py", line 2, in <module>
    builder = ConanMultiPackager()
  File "/home/maarten/.local/lib/python3.6/site-packages/cpt/packager.py", line 177, in __init__
    conanfile = load_cf_class(os.path.join(self.cwd, "conanfile.py"), self.conan_api)
  File "/home/maarten/.local/lib/python3.6/site-packages/cpt/packager.py", line 32, in load_cf_class
    return conan_api._loader.load_class(path)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/loader.py", line 48, in load_class
    _, conanfile = parse_conanfile(conanfile_path, self._python_requires)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/loader.py", line 231, in parse_conanfile
    module, filename = _parse_conanfile(conanfile_path)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/loader.py", line 275, in _parse_conanfile
    '\n'.join(trace[3:])))
conans.errors.ConanException: Unable to load conanfile in /tmp/cpt_test/conanfile.py
KeyError: '/tmp/cpt_test/conanfile.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/python_requires.py", line 33, in _look_for_require
    python_require = self._cached_requires[require]
KeyError: 'pkg_base/1.2@testremote/testing'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/loader.py", line 254, in _parse_conanfile
    loaded = imp.load_source(module_id, conan_file_path)
  File "/usr/lib64/python3.6/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/cpt_test/conanfile.py", line 3, in <module>
    base = python_requires("pkg_base/1.2@testremote/testing")
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/python_requires.py", line 58, in __call__
    python_req = self._look_for_require(require)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/python_requires.py", line 41, in _look_for_require
    recorder=ActionRecorder())
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/proxy.py", line 34, in get_recipe
    result = self._get_recipe(ref, check_updates, update, remote_name, recorder)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/proxy.py", line 50, in _get_recipe
    remote, new_ref = self._download_recipe(ref, output, remote_name, recorder)
  File "/home/maarten/.local/lib/python3.6/site-packages/conans/client/graph/proxy.py", line 157, in _download_recipe
    raise NotFoundException(msg)
conans.errors.NotFoundException: Unable to find 'pkg_base/1.2@testremote/testing' in remotes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions