class_docstr: Custom `build_ext` command to include CUDA C source files.
class_docstr_tok: ["Custom","`","build_ext","`","command","to","include","CUDA","C","source","files","."]
code: def _cythonize(self, nthreads: int) -> None:
      # Defer importing Cython as it may be installed via setup_requires if
      # the user does not have Cython installed.
      import Cython.Build
  
      ctx = cupy_builder.get_context()
      compiler_directives = {
          "linetrace": ctx.linetrace,
          "profile": ctx.profile,
          # Embed signatures for Sphinx documentation.
          "embedsignature": True,
      }
  
      # Compile-time constants to be used in Cython code
      compile_time_env: Dict[str, Any] = {}
  
      # Enable CUDA Python.
      # TODO: add `cuda` to `setup_requires` only when this flag is set
      use_cuda_python = ctx.use_cuda_python
      compile_time_env["CUPY_USE_CUDA_PYTHON"] = use_cuda_python
      if use_cuda_python:
          print("Using CUDA Python")
  
      compile_time_env["CUPY_CUFFT_STATIC"] = False
      compile_time_env["CUPY_CYTHON_VERSION"] = Cython.__version__
      if ctx.use_stub:  # on RTD
          compile_time_env["CUPY_CUDA_VERSION"] = 0
          compile_time_env["CUPY_HIP_VERSION"] = 0
      elif ctx.use_hip:  # on ROCm/HIP
          compile_time_env["CUPY_CUDA_VERSION"] = 0
          compile_time_env["CUPY_HIP_VERSION"] = build.get_hip_version()
      else:  # on CUDA
          compile_time_env["CUPY_CUDA_VERSION"] = ctx.features[
              "cuda"
          ].get_version()
          compile_time_env["CUPY_HIP_VERSION"] = 0
  
      print(
          "Compile-time constants: "
          + json.dumps(compile_time_env, indent=4)
      )
  
      if sys.platform == "win32":
          # Disable multiprocessing on Windows (spawn)
          nthreads = 0
  
      Cython.Build.cythonize(
          self.extensions,
          verbose=True,
          nthreads=nthreads,
          language_level=3,
          compiler_directives=compiler_directives,
          annotate=ctx.annotate,
          compile_time_env=compile_time_env,
      )
  
imports: import json
  import os
  import os.path
  import subprocess
  import sys
  from typing import Any, Dict, List, Tuple
  import setuptools
  import setuptools.command.build_ext
  import cupy_builder
  import cupy_builder.install_build
  from cupy_builder._context import Context
  from cupy_builder._compiler import DeviceCompilerUnix, DeviceCompilerWin32
label_desc: Use image node_id 1 for calling the custom_build_ext obj's underlying member method code with example usage: obj._cythonize(nthreads) without return types