From: Sun Yuechi Date: Mon, 13 Jul 2026 18:56:23 +0000 (-0700) Subject: pybind: write Tempita-processed pyx to the build directory X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d1ed18a7205481d5f1f5c24f2d8c8e937a4eec83;p=ceph.git pybind: write Tempita-processed pyx to the build directory 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 --- diff --git a/src/pybind/cephfs/setup.py b/src/pybind/cephfs/setup.py index d41d9d63a24..6e68579a252 100755 --- a/src/pybind/cephfs/setup.py +++ b/src/pybind/cephfs/setup.py @@ -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=[ diff --git a/src/pybind/rados/setup.py b/src/pybind/rados/setup.py index bf3802953ba..8e84e75d863 100755 --- a/src/pybind/rados/setup.py +++ b/src/pybind/rados/setup.py @@ -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', diff --git a/src/pybind/rbd/setup.py b/src/pybind/rbd/setup.py index 69cfa06a122..674f999735f 100755 --- a/src/pybind/rbd/setup.py +++ b/src/pybind/rbd/setup.py @@ -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=[ diff --git a/src/pybind/rgw/setup.py b/src/pybind/rgw/setup.py index 29b66243140..26ad7089712 100755 --- a/src/pybind/rgw/setup.py +++ b/src/pybind/rgw/setup.py @@ -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=[