]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind: respect CYTHON_BUILD_DIR for all Python bindings wip-pr-67045-kefu-6
authorKefu Chai <k.chai@proxmox.com>
Wed, 28 Jan 2026 02:43:50 +0000 (10:43 +0800)
committerKefu Chai <k.chai@proxmox.com>
Wed, 28 Jan 2026 03:03:33 +0000 (11:03 +0800)
Allow the *_processed.pyx files to be generated in a build directory
specified by the CYTHON_BUILD_DIR environment variable, instead of
always writing to the current working directory or source directory.

Changes for all bindings (rados, cephfs, rbd, rgw):
- Add cython_build_dir variable from environment
- Refactor Tempita processing to write output to build_dir
- Use os.path.relpath for the source path
- Pass cython_build_dir to cythonize() function

This ensures consistent behavior across all Python bindings and allows
for cleaner separation of source and build artifacts.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/pybind/cephfs/setup.py
src/pybind/rados/setup.py
src/pybind/rbd/setup.py
src/pybind/rgw/setup.py

index a44d4708faa1364be8a642db1e92d846d78ca626..a2f3b824788f4875b3cf0e3286c669c0386a708d 100755 (executable)
@@ -154,6 +154,7 @@ elif check_sanity():
                           include_path=include_path)
 else:
     sys.exit(1)
+cython_build_dir=os.environ.get("CYTHON_BUILD_DIR", None)
 
 cmdclass = {}
 try:
@@ -175,26 +176,18 @@ except ImportError:
         source = "cephfs.c"
 else:
     # Process Tempita template
-    source_pyx = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)),
-        "cephfs.pyx"
-    )
+    source_dir = os.path.dirname(os.path.abspath(__file__))
+    source_pyx = os.path.join(source_dir, "cephfs.pyx")
+    build_dir = cython_build_dir or source_dir
+    output_pyx = os.path.join(build_dir, "cephfs_processed.pyx")
 
-    # Read the template from source
     with open(source_pyx) as f:
         template_content = f.read()
-
-    # Process the template with cython_constants
     processed = Tempita.sub(template_content, **cython_constants)
-
-    # Write processed output to current working directory
-    # (which is the build directory when invoked by CMake)
-    output_pyx = "cephfs_processed.pyx"
-
     with open(output_pyx, 'w') as f:
         f.write(processed)
 
-    source = output_pyx
+    source = os.path.relpath(output_pyx, os.getcwd())
 
 # Disable cythonification if we're not really building anything
 if (len(sys.argv) >= 2 and
@@ -226,7 +219,7 @@ setup(
                 **ext_args
             )
         ],
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
+        build_dir=cython_build_dir,
         **cythonize_args
     ),
     classifiers=[
index ec345f9718cf402569d02fe70393447b599952dc..9c4bca6e68b11fc4da0aef7242c9cb36e2305602 100755 (executable)
@@ -146,6 +146,7 @@ elif check_sanity():
     cython_constants = dict(BUILD_DOC=False, UNAME_SYSNAME=platform.system())
 else:
     sys.exit(1)
+cython_build_dir=os.environ.get("CYTHON_BUILD_DIR", None)
 
 cmdclass = {}
 try:
@@ -167,26 +168,18 @@ except ImportError:
         source = "rados.c"
 else:
     # Process Tempita template
-    source_pyx = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)),
-        "rados.pyx"
-    )
+    source_dir = os.path.dirname(os.path.abspath(__file__))
+    source_pyx = os.path.join(source_dir, "rados.pyx")
+    build_dir = cython_build_dir or source_dir
+    output_pyx = os.path.join(build_dir, "rados_processed.pyx")
 
-    # Read the template from source
     with open(source_pyx) as f:
         template_content = f.read()
-
-    # Process the template with cython_constants
     processed = Tempita.sub(template_content, **cython_constants)
-
-    # Write processed output to current working directory
-    # (which is the build directory when invoked by CMake)
-    output_pyx = "rados_processed.pyx"
-
     with open(output_pyx, 'w') as f:
         f.write(processed)
 
-    source = output_pyx
+    source = os.path.relpath(output_pyx, os.getcwd())
 
 # Disable cythonification if we're not really building anything
 if (len(sys.argv) >= 2 and
@@ -218,7 +211,7 @@ setup(
             )
         ],
         compile_time_env=cython_constants,
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
+        build_dir=cython_build_dir,
     ),
     classifiers=[
         'Intended Audience :: Developers',
index b3a1ab4ca9cc91a8420f3cb559bb255da5a78ac5..f0dafec0a69610b8177c8b87d5dfb98edbc88819 100755 (executable)
@@ -152,6 +152,7 @@ elif check_sanity():
                           include_path=include_path)
 else:
     sys.exit(1)
+cython_build_dir=os.environ.get("CYTHON_BUILD_DIR", None)
 
 cmdclass = {}
 compiler_directives = {}
@@ -176,25 +177,19 @@ except ImportError:
         source = "rbd.c"
 else:
     # Process Tempita template
-    source_pyx = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)),
-        "rbd.pyx"
-    )
+    source_dir = os.path.dirname(os.path.abspath(__file__))
+    source_pyx = os.path.join(source_dir, "rbd.pyx")
+    build_dir = cython_build_dir or source_dir
+    output_pyx = os.path.join(build_dir, "rbd_processed.pyx")
 
-    # Read the template from source
     with open(source_pyx) as f:
         template_content = f.read()
-
-    # Process the template with cython_constants
     processed = Tempita.sub(template_content, **cython_constants)
-
-    # Write processed output to current working directory
-    # (which is the build directory when invoked by CMake)
-    source = "rbd_processed.pyx"
-
-    with open(source, 'w') as f:
+    with open(output_pyx, 'w') as f:
         f.write(processed)
 
+    source = os.path.relpath(output_pyx, os.getcwd())
+
 # Disable cythonification if we're not really building anything
 if (len(sys.argv) >= 2 and
         any(i in sys.argv[1:] for i in ('--help', 'clean', 'egg_info', '--version')
@@ -226,7 +221,7 @@ setup(
             )
         ],
         compiler_directives=compiler_directives,
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
+        build_dir=cython_build_dir,
         **cythonize_args
     ),
     classifiers=[
index 374167cbbca4978ac31d1fbb682620ecc29512c8..dd36c312c479e68c5ec382b4f0d1133233d2753c 100755 (executable)
@@ -155,6 +155,7 @@ elif check_sanity():
                           include_path=include_path)
 else:
     sys.exit(1)
+cython_build_dir=os.environ.get("CYTHON_BUILD_DIR", None)
 
 cmdclass = {}
 try:
@@ -176,26 +177,18 @@ except ImportError:
         source = "rgw.c"
 else:
     # Process Tempita template
-    source_pyx = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)),
-        "rgw.pyx"
-    )
+    source_dir = os.path.dirname(os.path.abspath(__file__))
+    source_pyx = os.path.join(source_dir, "rgw.pyx")
+    build_dir = cython_build_dir or source_dir
+    output_pyx = os.path.join(build_dir, "rgw_processed.pyx")
 
-    # Read the template from source
     with open(source_pyx) as f:
         template_content = f.read()
-
-    # Process the template with cython_constants
     processed = Tempita.sub(template_content, **cython_constants)
-
-    # Write processed output to current working directory
-    # (which is the build directory when invoked by CMake)
-    output_pyx = "rgw_processed.pyx"
-
     with open(output_pyx, 'w') as f:
         f.write(processed)
 
-    source = output_pyx
+    source = os.path.relpath(output_pyx, os.getcwd())
 
 # Disable cythonification if we're not really building anything
 if (len(sys.argv) >= 2 and
@@ -226,7 +219,7 @@ setup(
                 **ext_args
             )
         ],
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
+        build_dir=cython_build_dir,
         **cythonize_args
     ),
     classifiers=[