File: hatch_build.py

package info (click to toggle)
ipykernel 7.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,128 kB
  • sloc: python: 9,700; makefile: 165; sh: 8
file content (36 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download
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
"""A custom hatch build hook for ipykernel."""

import shutil
import sys
from pathlib import Path

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class CustomHook(BuildHookInterface):
    """The IPykernel build hook."""

    def initialize(self, version, build_data):
        """Initialize the hook."""
        here = Path(__file__).parent.resolve()
        sys.path.insert(0, str(here))
        from ipykernel.kernelspec import make_ipkernel_cmd, write_kernel_spec

        overrides = {}

        # When building a standard wheel, the executable specified in the kernelspec is simply 'python'.
        if version == "standard":
            overrides["metadata"] = dict(debugger=True)
            argv = make_ipkernel_cmd(executable="python")

        # When installing an editable wheel, the full `sys.executable` can be used.
        else:
            argv = make_ipkernel_cmd()

        overrides["argv"] = argv

        dest = Path(here) / "data_kernelspec"
        if Path(dest).exists():
            shutil.rmtree(dest)

        write_kernel_spec(dest, overrides=overrides)