# Buggy code
def _parse_conanfile(conan_file_path):
    """From a given path, obtain the in memory python import module"""

    if not os.path.exists(conan_file_path):
        raise NotFoundException("%s not found!" % conan_file_path)

    module_id = str(uuid.uuid1())
    current_dir = os.path.dirname(conan_file_path)
    sys.path.insert(0, current_dir)
    try:
        old_modules = list(sys.modules.keys())
        with chdir(current_dir):
            sys.dont_write_bytecode = True
            loaded = imp.load_source(module_id, conan_file_path)
            sys.dont_write_bytecode = False

        # These lines are necessary, otherwise local conanfile imports with same name
        # collide, but no error, and overwrite other packages imports!!
        added_modules = set(sys.modules).difference(old_modules)
        for added in added_modules:
            module = sys.modules[added]
            if module:
                try:
                    try:
                        # Most modules will have __file__ != None
                        folder = os.path.dirname(module.__file__)
                    except (AttributeError, TypeError):
                        # But __file__ might not exist or equal None
                        # Like some builtins and Namespace packages py3
                        folder = module.__path__._path[0]
                except AttributeError:  # In case the module.__path__ doesn't exist
                    pass
                else:
                    if folder.startswith(current_dir):
                        module = sys.modules.pop(added)
                        sys.modules["%s.%s" % (module_id, added)] = module
    except Exception:
        import traceback

        trace = traceback.format_exc().split("\n")
        raise ConanException(
            "Unable to load conanfile in %s\n%s"
            % (conan_file_path, "\n".join(trace[3:]))
        )
    finally:
        sys.path.pop(0)

    return loaded, module_id


# Traceback (ValueError)
conan inspect . -a options
zlib/1.2.8@conan/stable: Not found in local cache, looking in remotes...
zlib/1.2.8@conan/stable: Trying with 'kk'...
zlib/1.2.8@conan/stable: Trying with 'rr'...
zlib/1.2.8@conan/stable: Trying with 'bincrafters'...
zlib/1.2.8@conan/stable: Trying with 'arti'...
zlib/1.2.8@conan/stable: Trying with 'virtual'...
zlib/1.2.8@conan/stable: Trying with 'c3i_PR-1_9fe37beb14d6c6ecfcec3127ea197805dcdda695'...
zlib/1.2.8@conan/stable: Trying with 'c3i_PR-1_20437a99db62349f366d19e8a571b7f1c5c1eafa'...
zlib/1.2.8@conan/stable: Trying with 'c3i_PR-1_a9da64e0861fb0a7fc7f2448a47f7ce97fda8a73'...
ERROR: Unable to load conanfile in /tmp/kk/conanfile.py
ValueError: not enough values to unpack (expected 7, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/luism/workspace/conan_sources/conans/client/conan_api.py", line 285, in inspect
ref = ConanFileReference.loads(path)
File "/home/luism/workspace/conan_sources/conans/model/ref.py", line 114, in loads
"OpenCV/1.0.6@user/stable" % text)
conans.errors.ConanException: Wrong package recipe reference .
Write something like OpenCV/1.0.6@user/stable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/luism/workspace/conan_sources/conans/client/loader.py", line 45, in load_class
return self.cached_conanfiles[conanfile_path]
KeyError: '/tmp/kk/conanfile.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/luism/workspace/conan_sources/conans/client/graph/python_requires.py", line 33, in _look_for_require
python_require = self._cached_requires[require]
KeyError: 'zlib/1.2.8@conan/stable'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/luism/workspace/conan_sources/conans/client/loader.py", line 254, in _parse_conanfile
loaded = imp.load_source(module_id, conan_file_path)
File "/home/luism/.virtualenvs/conan_use/lib/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/kk/conanfile.py", line 3, in <module>
kk = python_requires("zlib/1.2.8@conan/stable")
File "/home/luism/workspace/conan_sources/conans/client/graph/python_requires.py", line 58, in __call__
python_req = self._look_for_require(require)
File "/home/luism/workspace/conan_sources/conans/client/graph/python_requires.py", line 41, in _look_for_require
recorder=ActionRecorder())
File "/home/luism/workspace/conan_sources/conans/client/graph/proxy.py", line 33, in get_recipe
result = self._get_recipe(ref, check_updates, update, remote_name, recorder)
File "/home/luism/workspace/conan_sources/conans/client/graph/proxy.py", line 49, in _get_recipe
remote, new_ref = self._download_recipe(ref, output, remote_name, recorder)
File "/home/luism/workspace/conan_sources/conans/client/graph/proxy.py", line 155, in _download_recipe
raise NotFoundException(msg)
conans.errors.NotFoundException: Unable to find 'zlib/1.2.8@conan/stable' in remotes

# Fixed code
def _parse_conanfile(conan_file_path):
    """From a given path, obtain the in memory python import module"""

    if not os.path.exists(conan_file_path):
        raise NotFoundException("%s not found!" % conan_file_path)

    module_id = str(uuid.uuid1())
    current_dir = os.path.dirname(conan_file_path)
    sys.path.insert(0, current_dir)
    try:
        old_modules = list(sys.modules.keys())
        with chdir(current_dir):
            sys.dont_write_bytecode = True
            loaded = imp.load_source(module_id, conan_file_path)
            sys.dont_write_bytecode = False

        # These lines are necessary, otherwise local conanfile imports with same name
        # collide, but no error, and overwrite other packages imports!!
        added_modules = set(sys.modules).difference(old_modules)
        for added in added_modules:
            module = sys.modules[added]
            if module:
                try:
                    try:
                        # Most modules will have __file__ != None
                        folder = os.path.dirname(module.__file__)
                    except (AttributeError, TypeError):
                        # But __file__ might not exist or equal None
                        # Like some builtins and Namespace packages py3
                        folder = module.__path__._path[0]
                except AttributeError:  # In case the module.__path__ doesn't exist
                    pass
                else:
                    if folder.startswith(current_dir):
                        module = sys.modules.pop(added)
                        sys.modules["%s.%s" % (module_id, added)] = module
    except ConanException:
        raise
    except Exception:
        import traceback

        trace = traceback.format_exc().split("\n")
        raise ConanException(
            "Unable to load conanfile in %s\n%s"
            % (conan_file_path, "\n".join(trace[3:]))
        )
    finally:
        sys.path.pop(0)

    return loaded, module_id