]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: write Tempita-processed pyx to the build directory 70168/head
authorSun Yuechi <sunyuechi@iscas.ac.cn>
Mon, 13 Jul 2026 18:56:23 +0000 (11:56 -0700)
committerSun Yuechi <sunyuechi@iscas.ac.cn>
Tue, 14 Jul 2026 05:34:33 +0000 (22:34 -0700)
distutils_add_cython_module() runs setup.py with WORKING_DIRECTORY set
to the source directory, so every build leaks
{rados,cephfs,rbd,rgw}_processed.pyx into the source tree as untracked
files. Write the file to CYTHON_BUILD_DIR (already exported by that
CMake function) when set, keeping the cwd fallback for standalone
invocations.

The .pyx no longer sits next to the bindings' .pxd files, so add each
binding's source directory to include_path. Drop the build_dir
argument: it has no effect on absolute source paths.

Signed-off-by: Sun Yuechi <sunyuechi@iscas.ac.cn>
src/pybind/cephfs/setup.py
src/pybind/rados/setup.py
src/pybind/rbd/setup.py
src/pybind/rgw/setup.py

index d41d9d63a245f85a7e24d2cd0e5bad5f07498d48..6e68579a25213f362231a279ebfcee6ef48ed5b9 100755 (executable)
@@ -149,7 +149,14 @@ if 'BUILD_DOC' in os.environ or 'READTHEDOCS' in os.environ:
 elif check_sanity():
     ext_args = get_python_flags(['cephfs'])
     cython_constants = dict(BUILD_DOC=False)
-    include_path = [os.path.join(os.path.dirname(__file__), "..", "rados")]
+    # The processed .pyx is written to CYTHON_BUILD_DIR, away from the
+    # binding's own c_*.pxd, so add this source directory to include_path
+    # for cimports to resolve.
+    source_dir = os.path.dirname(os.path.abspath(__file__))
+    include_path = [
+        source_dir,
+        os.path.join(source_dir, "..", "rados"),
+    ]
     cythonize_args = dict(include_path=include_path)
 else:
     sys.exit(1)
@@ -186,9 +193,11 @@ else:
     # 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"
+    # Write the processed output to the build directory when invoked by
+    # CMake, which exports CYTHON_BUILD_DIR but runs setup.py from the
+    # source directory; fall back to the current working directory.
+    build_dir = os.environ.get("CYTHON_BUILD_DIR", os.getcwd())
+    output_pyx = os.path.join(build_dir, "cephfs_processed.pyx")
 
     with open(output_pyx, 'w') as f:
         f.write(processed)
@@ -225,7 +234,6 @@ setup(
                 **ext_args
             )
         ],
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
         **cythonize_args
     ),
     classifiers=[
index bf3802953baaa2f23c36ca88d27c846c8250edd5..8e84e75d8638731083c0597bb0541277e8a08b9c 100755 (executable)
@@ -140,9 +140,15 @@ def check_sanity():
 if 'BUILD_DOC' in os.environ or 'READTHEDOCS' in os.environ:
     ext_args = dict(extra_compile_args=['-DBUILD_DOC'])
     cython_constants = dict(BUILD_DOC=True)
+    cythonize_args = dict()
 elif check_sanity():
     ext_args = get_python_flags(['rados'])
     cython_constants = dict(BUILD_DOC=False)
+    # The processed .pyx is written to CYTHON_BUILD_DIR, away from the
+    # binding's own c_*.pxd, so add this source directory to include_path
+    # for cimports to resolve.
+    include_path = [os.path.dirname(os.path.abspath(__file__))]
+    cythonize_args = dict(include_path=include_path)
 else:
     sys.exit(1)
 
@@ -178,9 +184,11 @@ else:
     # 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"
+    # Write the processed output to the build directory when invoked by
+    # CMake, which exports CYTHON_BUILD_DIR but runs setup.py from the
+    # source directory; fall back to the current working directory.
+    build_dir = os.environ.get("CYTHON_BUILD_DIR", os.getcwd())
+    output_pyx = os.path.join(build_dir, "rados_processed.pyx")
 
     with open(output_pyx, 'w') as f:
         f.write(processed)
@@ -216,7 +224,7 @@ setup(
                 **ext_args
             )
         ],
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
+        **cythonize_args
     ),
     classifiers=[
         'Intended Audience :: Developers',
index 69cfa06a122dbcdff19219c1479302f0fb4b3278..674f999735f5dfcc17059d06e06db9674fd69b8a 100755 (executable)
@@ -147,7 +147,14 @@ if 'BUILD_DOC' in os.environ or 'READTHEDOCS' in os.environ:
 elif check_sanity():
     ext_args = get_python_flags(['rados', 'rbd'])
     cython_constants = dict(BUILD_DOC=False)
-    include_path = [os.path.join(os.path.dirname(__file__), "..", "rados")]
+    # The processed .pyx is written to CYTHON_BUILD_DIR, away from the
+    # binding's own c_*.pxd, so add this source directory to include_path
+    # for cimports to resolve.
+    source_dir = os.path.dirname(os.path.abspath(__file__))
+    include_path = [
+        source_dir,
+        os.path.join(source_dir, "..", "rados"),
+    ]
     cythonize_args = dict(include_path=include_path)
 else:
     sys.exit(1)
@@ -185,9 +192,11 @@ else:
     # 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"
+    # Write the processed output to the build directory when invoked by
+    # CMake, which exports CYTHON_BUILD_DIR but runs setup.py from the
+    # source directory; fall back to the current working directory.
+    build_dir = os.environ.get("CYTHON_BUILD_DIR", os.getcwd())
+    source = os.path.join(build_dir, "rbd_processed.pyx")
 
     with open(source, 'w') as f:
         f.write(processed)
@@ -222,7 +231,6 @@ setup(
                 **ext_args
             )
         ],
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
         **cythonize_args
     ),
     classifiers=[
index 29b662431409837f8c6213bfbc0398d8baf42b10..26ad7089712afc426e85f7dda9e285b1658519ad 100755 (executable)
@@ -149,7 +149,14 @@ if 'BUILD_DOC' in os.environ or 'READTHEDOCS' in os.environ:
 elif check_sanity():
     ext_args = get_python_flags(['rados', 'rgw'])
     cython_constants = dict(BUILD_DOC=False)
-    include_path = [os.path.join(os.path.dirname(__file__), "..", "rados")]
+    # The processed .pyx is written to CYTHON_BUILD_DIR, away from the
+    # binding's own c_*.pxd, so add this source directory to include_path
+    # for cimports to resolve.
+    source_dir = os.path.dirname(os.path.abspath(__file__))
+    include_path = [
+        source_dir,
+        os.path.join(source_dir, "..", "rados"),
+    ]
     cythonize_args = dict(include_path=include_path)
 else:
     sys.exit(1)
@@ -186,9 +193,11 @@ else:
     # 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"
+    # Write the processed output to the build directory when invoked by
+    # CMake, which exports CYTHON_BUILD_DIR but runs setup.py from the
+    # source directory; fall back to the current working directory.
+    build_dir = os.environ.get("CYTHON_BUILD_DIR", os.getcwd())
+    output_pyx = os.path.join(build_dir, "rgw_processed.pyx")
 
     with open(output_pyx, 'w') as f:
         f.write(processed)
@@ -224,7 +233,6 @@ setup(
                 **ext_args
             )
         ],
-        build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
         **cythonize_args
     ),
     classifiers=[