@@ -21,13 +21,38 @@ class build_regexes(Command):
21
21
description = 'build supporting regular expressions from uap-core'
22
22
user_options = [
23
23
('work-path=' , 'w' ,
24
- 'The working directory for source files. Defaults to .' ),
24
+ "The working directory for source files. Defaults to ." ),
25
+ ('build-lib=' , 'b' ,
26
+ "directory for script runtime modules" ),
27
+ ('inplace' , 'i' ,
28
+ "ignore build-lib and put compiled javascript files into the source " +
29
+ "directory alongside your pure Python modules" ),
30
+ ('force' , 'f' ,
31
+ "Force rebuilding of static content. Defaults to rebuilding on version "
32
+ "change detection." ),
25
33
]
34
+ boolean_options = ['force' ]
26
35
27
36
def initialize_options (self ):
37
+ self .build_lib = None
38
+ self .force = None
28
39
self .work_path = None
40
+ self .inplace = None
29
41
30
42
def finalize_options (self ):
43
+ install = self .distribution .get_command_obj ('install' )
44
+ sdist = self .distribution .get_command_obj ('sdist' )
45
+ build_ext = self .distribution .get_command_obj ('build_ext' )
46
+
47
+ if self .inplace is None :
48
+ self .inplace = (build_ext .inplace or install .finalized
49
+ or sdist .finalized ) and 1 or 0
50
+
51
+ if self .inplace :
52
+ self .build_lib = '.'
53
+ else :
54
+ self .set_undefined_options ('build' ,
55
+ ('build_lib' , 'build_lib' ))
31
56
if self .work_path is None :
32
57
self .work_path = os .path .realpath (os .path .join (os .path .dirname (__file__ )))
33
58
@@ -51,7 +76,7 @@ def force_bytes(text):
51
76
return text .encode ('utf8' )
52
77
53
78
import yaml
54
- py_dest = os .path .join (work_path , 'ua_parser' , '_regexes.py' )
79
+ py_dest = os .path .join (self . build_lib , 'ua_parser' , '_regexes.py' )
55
80
56
81
log .info ('compiling regexes.yaml -> _regexes.py' )
57
82
with open (yaml_src , 'rb' ) as fp :
@@ -106,6 +131,15 @@ def force_bytes(text):
106
131
fp .write (b']\n ' )
107
132
fp .write (b'\n ' )
108
133
134
+ self .update_manifest ()
135
+
136
+ def update_manifest (self ):
137
+ sdist = self .distribution .get_command_obj ('sdist' )
138
+ if not sdist .finalized :
139
+ return
140
+
141
+ sdist .filelist .files .append ('ua_parser/_regexes.py' )
142
+
109
143
110
144
class develop (_develop ):
111
145
def run (self ):
@@ -119,13 +153,20 @@ def run(self):
119
153
_install .run (self )
120
154
121
155
156
+ class build (_build ):
157
+ def run (self ):
158
+ self .run_command ('build_regexes' )
159
+ _build .run (self )
160
+
161
+
122
162
class sdist (_sdist ):
123
163
sub_commands = _sdist .sub_commands + [('build_regexes' , None )]
124
164
125
165
126
166
cmdclass = {
127
- 'develop' : develop ,
128
167
'sdist' : sdist ,
168
+ 'develop' : develop ,
169
+ 'build' : build ,
129
170
'install' : install ,
130
171
'build_regexes' : build_regexes ,
131
172
}
0 commit comments