Passed
Push — develop ( a0fd1f...041457 )
by
unknown
01:45
created

build_hook   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A BuildHook.compile_message_catalog() 0 13 1
A BuildHook.build_frontend() 0 7 1
A BuildHook.initialize() 0 6 1
1
import subprocess
2
from pathlib import Path
3
4
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
5
6
7
class BuildHook(BuildHookInterface):
8
    def initialize(self, version: str, build_data) -> None:
9
        """Execute compilations when building the wheel."""
10
        super().initialize(version, build_data)
11
12
        self.build_frontend()
13
        self.compile_message_catalog()
14
15
    def compile_message_catalog(self):
16
        root_dir = Path(__file__).parent
17
        subprocess.run(
18
            [
19
                'pybabel',
20
                'compile',
21
                '--directory',
22
                'atramhasis/locale',
23
                '--domain',
24
                'atramhasis',
25
            ],
26
            cwd=root_dir,
27
            check=True,
28
        )
29
30
    def build_frontend(self):
31
        root_dir = Path(__file__).parent
32
        static = root_dir / 'atramhasis' / 'static'
33
        static_admin = static / 'admin'
34
        subprocess.run(['npm', 'install'], cwd=static, check=True)
35
        subprocess.run(['npm', 'install'], cwd=static_admin, check=True)
36
        subprocess.run(['grunt', '-v', 'build'], cwd=static_admin, check=True)
37