# Buggy code
def get_build_info(folder):
    toml_file = folder.join("pyproject.toml")

    # as per https://www.python.org/dev/peps/pep-0517/

    def abort(message):
        reporter.error("{} inside {}".format(message, toml_file))
        raise SystemExit(1)

    if not toml_file.exists():
        reporter.error("missing {}".format(toml_file))
        raise SystemExit(1)

    config_data = get_py_project_toml(toml_file)

    if "build-system" not in config_data:
        abort("build-system section missing")

    build_system = config_data["build-system"]

    if "requires" not in build_system:
        abort("missing requires key at build-system section")
    if "build-backend" not in build_system:
        abort("missing build-backend key at build-system section")

    requires = build_system["requires"]
    if not isinstance(requires, list) or not all(
        isinstance(i, six.text_type) for i in requires
    ):
        abort("requires key at build-system section must be a list of string")

    backend = build_system["build-backend"]
    if not isinstance(backend, six.text_type):
        abort("build-backend key at build-system section must be a string")

    args = backend.split(":")
    module = args[0]
    obj = args[1] if len(args) > 1 else ""

    backend_paths = build_system.get("backend-path", [])
    if not isinstance(backend_paths, list):
        abort("backend-path key at build-system section must be a list, if specified")
    backend_paths = [folder.join(p) for p in backend_paths]

    return BuildInfo(requires, module, obj, backend_paths)


# Traceback (ModuleNotFoundError)
.package start: get-build-requires /Users/nicolas/Workspaces/proj/.tox/.package
setting PATH=/Users/nicolas/Workspaces/proj/.tox/.package/bin:/Users/nicolas/.virtualenvs/proj-python3.8/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
[15159] /Users/nicolas/Workspaces/proj$ /Users/nicolas/Workspaces/proj/.tox/.package/bin/python /Users/nicolas/.virtualenvs/proj-python3.8/lib/python3.8/site-packages/tox/helper/build_requires.py build_package '' >.tox/.package/log/.package-0.log
ERROR: invocation failed (exit code 1), logfile: /Users/nicolas/Workspaces/proj/.tox/.package/log/.package-0.log
=================================================================================== log start ====================================================================================
Traceback (most recent call last):
File "/Users/nicolas/.virtualenvs/proj-python3.8/lib/python3.8/site-packages/tox/helper/build_requires.py", line 7, in <module>
backend = __import__(backend_spec, fromlist=["_trash"])
ModuleNotFoundError: No module named 'build_package'

# Fixed code
def get_build_info(folder):
    toml_file = folder.join("pyproject.toml")

    # as per https://www.python.org/dev/peps/pep-0517/

    def abort(message):
        reporter.error("{} inside {}".format(message, toml_file))
        raise SystemExit(1)

    if not toml_file.exists():
        reporter.error("missing {}".format(toml_file))
        raise SystemExit(1)

    config_data = get_py_project_toml(toml_file)

    if "build-system" not in config_data:
        abort("build-system section missing")

    build_system = config_data["build-system"]

    if "requires" not in build_system:
        abort("missing requires key at build-system section")
    if "build-backend" not in build_system:
        abort("missing build-backend key at build-system section")

    requires = build_system["requires"]
    if not isinstance(requires, list) or not all(
        isinstance(i, six.text_type) for i in requires
    ):
        abort("requires key at build-system section must be a list of string")

    backend = build_system["build-backend"]
    if not isinstance(backend, six.text_type):
        abort("build-backend key at build-system section must be a string")

    args = backend.split(":")
    module = args[0]
    obj = args[1] if len(args) > 1 else ""

    backend_paths = build_system.get("backend-path", [])
    if not isinstance(backend_paths, list):
        abort("backend-path key at build-system section must be a list, if specified")
    backend_paths = [folder.join(p) for p in backend_paths]

    normalized_folder = os.path.normcase(str(folder.realpath()))
    normalized_paths = (
        os.path.normcase(str(path.realpath())) for path in backend_paths
    )

    if not all(
        os.path.commonprefix((normalized_folder, path)) == normalized_folder
        for path in normalized_paths
    ):
        abort("backend-path must exist in the project root")

    return BuildInfo(requires, module, obj, backend_paths)