File: build_ext.py

package info (click to toggle)
scikit-build 0.18.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,792 kB
  • sloc: python: 5,258; cpp: 284; makefile: 171; f90: 12; sh: 7
file content (40 lines) | stat: -rw-r--r-- 1,852 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""This module defines custom implementation of ``build_ext`` setuptools command."""

from __future__ import annotations

import os

from distutils.file_util import copy_file
from setuptools.command.build_ext import build_ext as _build_ext

from ..constants import CMAKE_INSTALL_DIR
from . import set_build_base_mixin


class build_ext(set_build_base_mixin, _build_ext):
    """Custom implementation of ``build_ext`` setuptools command."""

    def copy_extensions_to_source(self) -> None:
        """This function is only-called when doing inplace build.

        It is customized to ensure the extensions compiled using distutils
        are copied back to the source tree instead of the :func:`skbuild.constants.CMAKE_INSTALL_DIR()`.
        """
        build_py = self.get_finalized_command("build_py")
        for ext in self.extensions:
            fullname: str = self.get_ext_fullname(ext.name)
            filename: str = self.get_ext_filename(fullname)  # type: ignore[no-untyped-call]
            modpath = fullname.split(".")
            package = ".".join(modpath[:-1])
            package_dir = build_py.get_package_dir(package)  # type: ignore[attr-defined]
            # skbuild: strip install dir for inplace build
            package_dir = package_dir[len(CMAKE_INSTALL_DIR()) + 1 :]
            dest_filename = os.path.join(package_dir, os.path.basename(filename))
            src_filename = os.path.join(self.build_lib, filename)

            # Always copy, even if source is older than destination, to ensure
            # that the right extensions for the current Python/platform are
            # used.
            copy_file(src_filename, dest_filename, verbose=self.verbose, dry_run=self.dry_run)  # type: ignore[attr-defined]
            if ext._needs_stub:
                self.write_stub(package_dir or os.curdir, ext, True)