MCPcopy Create free account
hub / github.com/cztomczak/cefpython / copy_and_fix_pyx_files

Function copy_and_fix_pyx_files

tools/build.py:609–703  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

607
608
609def copy_and_fix_pyx_files():
610 print("[build.py] Copy and fix pyx files")
611 # First, it copies all .pyx files from upper directory to setup/.
612 # Then, fixes repeating of "include" statements in pyx files.
613
614 # Only the mainfile needs to have "include" statements,
615 # but we're using PyCharm and to get rid of "unresolved references"
616 # and other errors displayed in pycharm we are adding "include"
617 # statements in all of the pyx files.
618
619 # I'm not 100% sure how includes work in Cython, but I suspect that
620 # a few includes of the same file will include the same content more
621 # than once, it should work, but function and variable definitions are
622 # duplicated, it is some kind of overhead and it could lead to some
623 # problems in the future, better to fix it now.
624
625 # It also checks cdef & cpdef functions whether they are not missing
626 # "except *", it is required to add it when returning non-python type.
627
628 os.chdir(BUILD_CEFPYTHON)
629 print("\n")
630 mainfile_original = "cefpython.pyx"
631 mainfile_newname = "cefpython_py{pyver}.pyx".format(pyver=PYVERSION)
632
633 pyxfiles = glob.glob("../../src/*.pyx")
634 if not len(pyxfiles):
635 print("[build.py] ERROR: no .pyx files found in root")
636 sys.exit(1)
637 pyxfiles = [f for f in pyxfiles if f.find(mainfile_original) == -1]
638 # Now, pyxfiles contains all pyx files except mainfile_original
639 # (cefpython.pyx), we do not fix includes in mainfile.
640
641 pyxfiles2 = glob.glob("../../src/handlers/*.pyx")
642 if not len(pyxfiles2):
643 print("[build.py] ERROR: no .pyx files found in handlers/")
644 sys.exit(1)
645
646 pyxfiles = pyxfiles + pyxfiles2
647
648 # Remove old pyx files
649 oldpyxfiles = glob.glob("./*.pyx")
650 print("[build.py] Clean pyx files in build_cefpython/")
651 for pyxfile in oldpyxfiles:
652 if os.path.exists(pyxfile):
653 os.remove(pyxfile)
654
655 # Copying pyxfiles and reading its contents.
656 print("[build.py] Copy pyx files to build_cefpython/")
657
658 # Copy cefpython.pyx and fix includes in cefpython.pyx, eg.:
659 # include "handlers/focus_handler.pyx" becomes include "focus_handler.pyx"
660 shutil.copy("../../src/%s" % mainfile_original, "./%s" % mainfile_newname)
661 with open("./%s" % mainfile_newname, "rb") as fo:
662 content = fo.read().decode("utf-8")
663 (content, subs) = re.subn(u"^include \"handlers/",
664 u"include \"",
665 content,
666 flags=re.MULTILINE)

Callers 1

mainFunction · 0.85

Calls 4

except_all_missingFunction · 0.85
findMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected