File: hatch_build.py

package info (click to toggle)
ipyparallel 9.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,388 kB
  • sloc: python: 22,769; javascript: 267; makefile: 29; sh: 28
file content (37 lines) | stat: -rw-r--r-- 1,356 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
"""Custom build script for hatch backend"""

import glob
import os
import subprocess

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


class CustomHook(BuildHookInterface):
    def initialize(self, version, build_data):
        if self.target_name not in ["wheel", "sdist"]:
            return
        cmd = "build:prod" if version == "standard" else "build"
        osp = os.path
        here = osp.abspath(osp.dirname(__file__))
        lab_path = osp.join(here, 'ipyparallel', 'labextension')

        if os.environ.get("IPP_DISABLE_JS") == "1":
            print("Skipping js installation")
            return

        # this tells us if labextension is built at all, not if it's up-to-date
        labextension_built = glob.glob(osp.join(lab_path, "*"))
        needs_js = True
        if not osp.isdir(osp.join(here, ".git")):
            print("Installing from a dist, not a repo")
            # not in a repo, probably installing from sdist
            # could be git-archive, though!
            # skip rebuilding js if it's already present
            if labextension_built:
                print(f"Not regenerating labextension in {lab_path}")
                needs_js = False

        if needs_js:
            subprocess.check_call(['jlpm'], cwd=here)
            subprocess.check_call(['jlpm', 'run', cmd], cwd=here)