From ffef921be312157147d3b825a8e92d80e50a9e86 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Mon, 31 Mar 2025 22:18:14 -0400 Subject: [PATCH] python: Concat generated files in generator.py --- CMakeLists.txt | 5 ----- python/.gitignore | 1 - python/Makefile.am | 7 ++----- python/generator.py | 15 +++++++++++++-- python/meson.build | 12 +----------- python/setup.py.in | 14 -------------- 6 files changed, 16 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 820dcf30..63563252 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -525,11 +525,6 @@ if(LIBXML2_WITH_PYTHON) ${CMAKE_CURRENT_SOURCE_DIR}/python/generator.py ${CMAKE_CURRENT_BINARY_DIR} ) - file(READ python/libxml.py LIBXML_PY) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML_PY}") - file(READ ${CMAKE_CURRENT_BINARY_DIR}/libxml2class.py LIBXML2CLASS_PY) - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML2CLASS_PY}") - configure_file(${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in libxml2.py COPYONLY) add_library( LibXml2Mod SHARED libxml2-py.c diff --git a/python/.gitignore b/python/.gitignore index b68d6ea9..811e0bd2 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -3,7 +3,6 @@ /libxml2-py.c /libxml2-py.h /libxml2.py -/libxml2class.py /libxml2class.txt /setup.py /tests/tmp.xml diff --git a/python/Makefile.am b/python/Makefile.am index 76018a9e..da57a990 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -32,8 +32,8 @@ python_PYTHON = drv_libxml2.py nodist_python_PYTHON = libxml2.py API_DESC = $(top_srcdir)/doc/libxml2-api.xml $(srcdir)/libxml2-python-api.xml -GENERATED = libxml2class.py libxml2class.txt $(BUILT_SOURCES) -CLEANFILES = libxml2.py $(GENERATED) +GENERATED = libxml2.py libxml2class.txt $(BUILT_SOURCES) +CLEANFILES = $(GENERATED) all-local: libxml2.py @@ -43,9 +43,6 @@ $(GENERATED): $(srcdir)/generator.py $(API_DESC) # libxml.c #includes libxml2-export.c libxml.$(OBJEXT): libxml2-export.c -libxml2.py: $(srcdir)/libxml.py libxml2class.py - cat $(srcdir)/libxml.py `test -f libxml2class.py || echo $(srcdir)/`libxml2class.py > $@ - clean-local: rm -rf __pycache__ *.pyc diff --git a/python/generator.py b/python/generator.py index 0647e67a..a09e9cba 100755 --- a/python/generator.py +++ b/python/generator.py @@ -1091,9 +1091,20 @@ def buildWrappers(): func = nameFixup(name, "None", file, file) info = (0, func, name, ret, args, file) function_classes['None'].append(info) - - classes = open(os.path.join(dstPref, "libxml2class.py"), "w") + + libxml_content = "" + try: + with open(os.path.join(srcPref, "libxml.py"), "r") as libxml_file: + libxml_content = libxml_file.read() + except IOError as msg: + print("Error reading libxml.py:", msg) + sys.exit(1) + + classes = open(os.path.join(dstPref, "libxml2.py"), "w") txt = open(os.path.join(dstPref, "libxml2class.txt"), "w") + + classes.write(libxml_content) + txt.write(" Generated Classes for libxml2-python\n\n") txt.write("#\n# Global functions of the module\n#\n\n") diff --git a/python/meson.build b/python/meson.build index 4ae0b0fa..f7622654 100644 --- a/python/meson.build +++ b/python/meson.build @@ -16,7 +16,7 @@ if py.found() == true 'libxml2-py.h', 'libxml2-export.c', 'libxml2-py.c', - 'libxml2class.py', + 'libxml2.py', 'libxml2class.txt', ], command: [py, '@INPUT@', meson.current_build_dir()], @@ -25,16 +25,6 @@ if py.found() == true sources : [pygenerated[0]], ) - libxml2_py = custom_target( - 'libxml2.py', - input: [files('libxml.py'), pygenerated[3]], - output: 'libxml2.py', - command: [find_program('cat'), '@INPUT@'], - capture: true, - install: true, - install_dir: py.get_install_dir(), - ) - libxml2mod_src = [ files('libxml.c', 'types.c'), pygenerated[2], diff --git a/python/setup.py.in b/python/setup.py.in index 4cd550d9..4402cbe2 100755 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -116,20 +116,6 @@ if missing("libxml2-py.c") or missing("libxml2.py"): print(sys.exc_info()[0], sys.exc_info()[1]) sys.exit(1) - head = open("libxml.py", "r") - generated = open("libxml2class.py", "r") - result = open("libxml2.py", "w") - for line in head.readlines(): - if WITHDLLS: - result.write(altImport(line)) - else: - result.write(line) - for line in generated.readlines(): - result.write(line) - head.close() - generated.close() - result.close() - with_xslt=0 if missing("libxslt-py.c") or missing("libxslt.py"): if missing("xsltgenerator.py") or missing("libxslt-api.xml"):