1
+ """
2
+ Custom build backend for Lemur that handles static asset building.
3
+ This replaces the custom commands from the old setup.py.
4
+ """
5
+ import os
6
+ import subprocess
7
+ import logging
8
+ from setuptools import build_meta as _orig
9
+ from setuptools .build_meta import *
10
+
11
+
12
+ def build_wheel (wheel_directory , config_settings = None , metadata_directory = None ):
13
+ """Build wheel with static assets."""
14
+ _build_static ()
15
+ return _orig .build_wheel (wheel_directory , config_settings , metadata_directory )
16
+
17
+
18
+ def build_sdist (sdist_directory , config_settings = None ):
19
+ """Build source distribution with static assets."""
20
+ _build_static ()
21
+ return _orig .build_sdist (sdist_directory , config_settings )
22
+
23
+
24
+ def _build_static ():
25
+ """Build static assets using npm and gulp."""
26
+ root = os .path .dirname (os .path .abspath (__file__ ))
27
+
28
+ # Check if static assets already exist
29
+ if os .path .exists (os .path .join (root , 'lemur/static/dist' )):
30
+ logging .info ("Static assets already exist, skipping build" )
31
+ return
32
+
33
+ logging .info (f"Building static assets in { root } " )
34
+
35
+ try :
36
+ # Run npm install
37
+ logging .info ("Running npm install --quiet" )
38
+ subprocess .check_call (['npm' , 'install' , '--quiet' ], cwd = root )
39
+
40
+ # Run gulp build
41
+ logging .info ("Running gulp build" )
42
+ subprocess .check_call ([
43
+ os .path .join (root , 'node_modules' , '.bin' , 'gulp' ), 'build'
44
+ ], cwd = root )
45
+
46
+ # Run gulp package
47
+ logging .info ("Running gulp package" )
48
+ subprocess .check_call ([
49
+ os .path .join (root , 'node_modules' , '.bin' , 'gulp' ), 'package'
50
+ ], cwd = root )
51
+
52
+ except subprocess .CalledProcessError as e :
53
+ logging .warning (f"Unable to build static content: { e } " )
54
+ except Exception as e :
55
+ logging .warning (f"Unexpected error building static content: { e } " )
0 commit comments