# Buggy code
def main():
    """CLI entry point"""
    args = parse_args()
    cppname = "libopenage"
    cppdir = Path(cppname).absolute()
    out_cppdir = Path(args.output_dir) / cppname

    if args.verbose:
        hdr_count = len(args.all_files)
        plural = "s" if hdr_count > 1 else ""

        print(
            "extracting pxd information from {} header{}...".format(hdr_count, plural)
        )

    for filename in args.all_files:
        filename = Path(filename).resolve()
        if cppdir not in filename.parents:
            print("pxdgen source file is not in " + cppdir + ": " + filename)
            sys.exit(1)

        # join out_cppdir with relative path from cppdir
        pxdfile_relpath = filename.with_suffix(".pxd").relative_to(cppdir)
        pxdfile = out_cppdir / pxdfile_relpath

        if args.verbose:
            print("creating '{}' for '{}':".format(pxdfile, filename))

        generator = PXDGenerator(filename)

        result = generator.generate(
            pxdfile, ignore_timestamps=args.ignore_timestamps, print_warnings=True
        )

        if args.verbose and not result:
            print("nothing done.")

        # create empty __init__.py in all parent directories.
        # Cython requires this; else it won't find the .pxd files.
        for dirname in pxdfile_relpath.parents:
            template = out_cppdir / dirname / "__init__"
            for extension in ("py", "pxd"):
                initfile = template.with_suffix("." + extension)
                if not initfile.exists():
                    print(
                        "\x1b[36mpxdgen: create package index %s\x1b[0m"
                        % (initfile.relative_to(CWD))
                    )

                    initfile.touch()


# Traceback (ValueError)
% make pxdgen VERBOSE=1
/usr/bin/cmake -S/tmp/portage/games-strategy/openage-9999/work/openage-9999 -B/tmp/portage/games-strategy/openage-9999/work/openage-9999_build --check-build-system CMakeFiles/Makefile.cmake 0
make -f CMakeFiles/Makefile2 pxdgen
make[1]: Entering directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
/usr/bin/cmake -S/tmp/portage/games-strategy/openage-9999/work/openage-9999 -B/tmp/portage/games-strategy/openage-9999/work/openage-9999_build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /tmp/portage/games-strategy/openage-9999/work/openage-9999_build/CMakeFiles 1
make -f CMakeFiles/Makefile2 CMakeFiles/pxdgen.dir/all
make[2]: Entering directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
make -f CMakeFiles/pxdgen.dir/build.make CMakeFiles/pxdgen.dir/depend
make[3]: Entering directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
cd /tmp/portage/games-strategy/openage-9999/work/openage-9999_build &amp;&amp; /usr/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/portage/games-strategy/openage-9999/work/openage-9999 /tmp/portage/games-strategy/openage-9999/work/openage-9999 /tmp/portage/games-strategy/openage-9999/work/openage-9999_build /tmp/portage/games-strategy/openage-9999/work/openage-9999_build /tmp/portage/games-strategy/openage-9999/work/openage-9999_build/CMakeFiles/pxdgen.dir/DependInfo.cmake --color=
make[3]: Leaving directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
make -f CMakeFiles/pxdgen.dir/build.make CMakeFiles/pxdgen.dir/build
make[3]: Entering directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
[100%] pxdgen: generating .pxd files from headers
cd /tmp/portage/games-strategy/openage-9999/work/openage-9999 &amp;&amp; /usr/bin/python3.6 -m buildsystem.pxdgen --file-list /tmp/portage/games-strategy/openage-9999/work/openage-9999_build/py/pxdgen_sources --output-dir /tmp/portage/games-strategy/openage-9999/work/openage-9999_build
Traceback (most recent call last):
File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/portage/games-strategy/openage-9999/work/openage-9999/buildsystem/pxdgen.py", line 479, in <module>
main()
File "/tmp/portage/games-strategy/openage-9999/work/openage-9999/buildsystem/pxdgen.py", line 473, in main
initfile.relative_to(CWD)))
File "/usr/lib64/python3.6/pathlib.py", line 874, in relative_to
.format(str(self), str(formatted)))
ValueError: '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build/libopenage/__init__.py' does not start with '/tmp/portage/games-strategy/openage-9999/work/openage-9999'
make[3]: *** [CMakeFiles/pxdgen.dir/build.make:94: py/pxdgen_timefile] Error 1
make[3]: Leaving directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
make[2]: *** [CMakeFiles/Makefile2:1198: CMakeFiles/pxdgen.dir/all] Error 2
make[2]: Leaving directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
make[1]: *** [CMakeFiles/Makefile2:1209: CMakeFiles/pxdgen.dir/rule] Error 2
make[1]: Leaving directory '/tmp/portage/games-strategy/openage-9999/work/openage-9999_build'
make: *** [Makefile:652: pxdgen] Error 2

# Fixed code
def main():
    """CLI entry point"""
    args = parse_args()
    cppname = "libopenage"
    cppdir = Path(cppname).absolute()
    out_cppdir = Path(args.output_dir) / cppname

    if args.verbose:
        hdr_count = len(args.all_files)
        plural = "s" if hdr_count > 1 else ""

        print(
            "extracting pxd information from {} header{}...".format(hdr_count, plural)
        )

    for filename in args.all_files:
        filename = Path(filename).resolve()
        if cppdir not in filename.parents:
            print("pxdgen source file is not in " + cppdir + ": " + filename)
            sys.exit(1)

        # join out_cppdir with relative path from cppdir
        pxdfile_relpath = filename.with_suffix(".pxd").relative_to(cppdir)
        pxdfile = out_cppdir / pxdfile_relpath

        if args.verbose:
            print("creating '{}' for '{}':".format(pxdfile, filename))

        generator = PXDGenerator(filename)

        result = generator.generate(
            pxdfile, ignore_timestamps=args.ignore_timestamps, print_warnings=True
        )

        if args.verbose and not result:
            print("nothing done.")

        # create empty __init__.py in all parent directories.
        # Cython requires this; else it won't find the .pxd files.
        for dirname in pxdfile_relpath.parents:
            template = out_cppdir / dirname / "__init__"
            for extension in ("py", "pxd"):
                initfile = template.with_suffix("." + extension)
                if not initfile.exists():
                    print(
                        "\x1b[36mpxdgen: create package index %s\x1b[0m"
                        % (initfile.relative_to(args.output_dir))
                    )

                    initfile.touch()