1
1
#!/usr/bin/env python
2
+ # flake8: noqa
2
3
import os
3
4
from distutils import log
4
5
from distutils .core import Command
11
12
12
13
def check_output (* args , ** kwargs ):
13
14
from subprocess import Popen
15
+
14
16
proc = Popen (* args , ** kwargs )
15
17
output , _ = proc .communicate ()
16
18
rv = proc .poll ()
17
19
assert rv == 0 , output
18
20
19
21
20
22
class build_regexes (Command ):
21
- description = ' build supporting regular expressions from uap-core'
23
+ description = " build supporting regular expressions from uap-core"
22
24
user_options = [
23
- ('work-path=' , 'w' ,
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
+ ("work-path=" , "w" , "The working directory for source files. Defaults to ." ),
26
+ ("build-lib=" , "b" , "directory for script runtime modules" ),
27
+ (
28
+ "inplace" ,
29
+ "i" ,
30
+ "ignore build-lib and put compiled javascript files into the source "
31
+ + "directory alongside your pure Python modules" ,
32
+ ),
33
+ (
34
+ "force" ,
35
+ "f" ,
36
+ "Force rebuilding of static content. Defaults to rebuilding on version "
37
+ "change detection." ,
38
+ ),
33
39
]
34
- boolean_options = [' force' ]
40
+ boolean_options = [" force" ]
35
41
36
42
def initialize_options (self ):
37
43
self .build_lib = None
@@ -40,174 +46,178 @@ def initialize_options(self):
40
46
self .inplace = None
41
47
42
48
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' )
49
+ install = self .distribution .get_command_obj (" install" )
50
+ sdist = self .distribution .get_command_obj (" sdist" )
51
+ build_ext = self .distribution .get_command_obj (" build_ext" )
46
52
47
53
if self .inplace is None :
48
- self .inplace = (build_ext .inplace or install .finalized
49
- or sdist .finalized ) and 1 or 0
54
+ self .inplace = (
55
+ (build_ext .inplace or install .finalized or sdist .finalized ) and 1 or 0
56
+ )
50
57
51
58
if self .inplace :
52
- self .build_lib = '.'
59
+ self .build_lib = "."
53
60
else :
54
- self .set_undefined_options ('build' ,
55
- ('build_lib' , 'build_lib' ))
61
+ self .set_undefined_options ("build" , ("build_lib" , "build_lib" ))
56
62
if self .work_path is None :
57
63
self .work_path = os .path .realpath (os .path .join (os .path .dirname (__file__ )))
58
64
59
65
def run (self ):
60
66
work_path = self .work_path
61
- if not os .path .exists (os .path .join (work_path , ' .git' )):
67
+ if not os .path .exists (os .path .join (work_path , " .git" )):
62
68
return
63
69
64
- log .info (' initializing git submodules' )
65
- check_output ([' git' , ' submodule' , ' init' ], cwd = work_path )
66
- check_output ([' git' , ' submodule' , ' update' ], cwd = work_path )
70
+ log .info (" initializing git submodules" )
71
+ check_output ([" git" , " submodule" , " init" ], cwd = work_path )
72
+ check_output ([" git" , " submodule" , " update" ], cwd = work_path )
67
73
68
- yaml_src = os .path .join (work_path , ' uap-core' , ' regexes.yaml' )
74
+ yaml_src = os .path .join (work_path , " uap-core" , " regexes.yaml" )
69
75
if not os .path .exists (yaml_src ):
70
76
raise RuntimeError (
71
- 'Unable to find regexes.yaml, should be at %r' % yaml_src )
77
+ "Unable to find regexes.yaml, should be at %r" % yaml_src
78
+ )
72
79
73
80
def force_bytes (text ):
74
81
if text is None :
75
82
return text
76
- return text .encode (' utf8' )
83
+ return text .encode (" utf8" )
77
84
78
85
import yaml
79
- py_dest = os .path .join (self .build_lib , 'ua_parser' , '_regexes.py' )
80
86
81
- log .info ('compiling regexes.yaml -> _regexes.py' )
82
- with open (yaml_src , 'rb' ) as fp :
87
+ py_dest = os .path .join (self .build_lib , "ua_parser" , "_regexes.py" )
88
+
89
+ log .info ("compiling regexes.yaml -> _regexes.py" )
90
+ with open (yaml_src , "rb" ) as fp :
83
91
regexes = yaml .safe_load (fp )
84
- with open (py_dest , 'wb' ) as fp :
85
- fp .write (b'# -*- coding: utf-8 -*-\n ' )
86
- fp .write (b'############################################\n ' )
87
- fp .write (b'# NOTICE: This file is autogenerated from #\n ' )
88
- fp .write (b'# regexes.yaml. Do not edit by hand, #\n ' )
89
- fp .write (b'# instead, re-run `setup.py build_regexes` #\n ' )
90
- fp .write (b'############################################\n ' )
91
- fp .write (b'\n ' )
92
- fp .write (b'from __future__ import absolute_import, unicode_literals\n ' )
93
- fp .write (b'from .user_agent_parser import (\n ' )
94
- fp .write (b' UserAgentParser, DeviceParser, OSParser,\n ' )
95
- fp .write (b')\n ' )
96
- fp .write (b'\n ' )
97
- fp .write (b'__all__ = (\n ' )
98
- fp .write (b' \' USER_AGENT_PARSERS\' , \' DEVICE_PARSERS\' , \' OS_PARSERS\' ,\n ' )
99
- fp .write (b')\n ' )
100
- fp .write (b'\n ' )
101
- fp .write (b'USER_AGENT_PARSERS = [\n ' )
102
- for device_parser in regexes ['user_agent_parsers' ]:
103
- fp .write (b' UserAgentParser(\n ' )
104
- fp .write (force_bytes (' %r,\n ' % device_parser ['regex' ]))
105
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('family_replacement' )))
106
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('v1_replacement' )))
107
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('v2_replacement' )))
108
- fp .write (b' ),\n ' )
109
- fp .write (b']\n ' )
110
- fp .write (b'\n ' )
111
- fp .write (b'DEVICE_PARSERS = [\n ' )
112
- for device_parser in regexes ['device_parsers' ]:
113
- fp .write (b' DeviceParser(\n ' )
114
- fp .write (force_bytes (' %r,\n ' % device_parser ['regex' ]))
115
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('regex_flag' )))
116
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('device_replacement' )))
117
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('brand_replacement' )))
118
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('model_replacement' )))
119
- fp .write (b' ),\n ' )
120
- fp .write (b']\n ' )
121
- fp .write (b'\n ' )
122
- fp .write (b'OS_PARSERS = [\n ' )
123
- for device_parser in regexes ['os_parsers' ]:
124
- fp .write (b' OSParser(\n ' )
125
- fp .write (force_bytes (' %r,\n ' % device_parser ['regex' ]))
126
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('os_replacement' )))
127
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('os_v1_replacement' )))
128
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('os_v2_replacement' )))
129
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('os_v3_replacement' )))
130
- fp .write (force_bytes (' %r,\n ' % device_parser .get ('os_v4_replacement' )))
131
- fp .write (b' ),\n ' )
132
- fp .write (b']\n ' )
92
+ with open (py_dest , "wb" ) as fp :
93
+ # fmt: off
94
+ fp .write (b"# -*- coding: utf-8 -*-\n " )
95
+ fp .write (b"############################################\n " )
96
+ fp .write (b"# NOTICE: This file is autogenerated from #\n " )
97
+ fp .write (b"# regexes.yaml. Do not edit by hand, #\n " )
98
+ fp .write (b"# instead, re-run `setup.py build_regexes` #\n " )
99
+ fp .write (b"############################################\n " )
100
+ fp .write (b"\n " )
101
+ fp .write (b"from __future__ import absolute_import, unicode_literals\n " )
102
+ fp .write (b"from .user_agent_parser import (\n " )
103
+ fp .write (b" UserAgentParser, DeviceParser, OSParser,\n " )
104
+ fp .write (b")\n " )
105
+ fp .write (b"\n " )
106
+ fp .write (b"__all__ = (\n " )
107
+ fp .write (b" 'USER_AGENT_PARSERS', 'DEVICE_PARSERS', 'OS_PARSERS',\n " )
108
+ fp .write (b")\n " )
109
+ fp .write (b"\n " )
110
+ fp .write (b"USER_AGENT_PARSERS = [\n " )
111
+ for device_parser in regexes ["user_agent_parsers" ]:
112
+ fp .write (b" UserAgentParser(\n " )
113
+ fp .write (force_bytes (" %r,\n " % device_parser ["regex" ]))
114
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("family_replacement" )))
115
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("v1_replacement" )))
116
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("v2_replacement" )))
117
+ fp .write (b" ),\n " )
118
+ fp .write (b"]\n " )
119
+ fp .write (b"\n " )
120
+ fp .write (b"DEVICE_PARSERS = [\n " )
121
+ for device_parser in regexes ["device_parsers" ]:
122
+ fp .write (b" DeviceParser(\n " )
123
+ fp .write (force_bytes (" %r,\n " % device_parser ["regex" ]))
124
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("regex_flag" )))
125
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("device_replacement" )))
126
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("brand_replacement" )))
127
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("model_replacement" )))
128
+ fp .write (b" ),\n " )
129
+ fp .write (b"]\n " )
130
+ fp .write (b"\n " )
131
+ fp .write (b"OS_PARSERS = [\n " )
132
+ for device_parser in regexes ["os_parsers" ]:
133
+ fp .write (b" OSParser(\n " )
134
+ fp .write (force_bytes (" %r,\n " % device_parser ["regex" ]))
135
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("os_replacement" )))
136
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("os_v1_replacement" )))
137
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("os_v2_replacement" )))
138
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("os_v3_replacement" )))
139
+ fp .write (force_bytes (" %r,\n " % device_parser .get ("os_v4_replacement" )))
140
+ fp .write (b" ),\n " )
141
+ fp .write (b"]\n " )
142
+ # fmt: on
133
143
134
144
self .update_manifest ()
135
145
136
146
def update_manifest (self ):
137
- sdist = self .distribution .get_command_obj (' sdist' )
147
+ sdist = self .distribution .get_command_obj (" sdist" )
138
148
if not sdist .finalized :
139
149
return
140
150
141
- sdist .filelist .files .append (' ua_parser/_regexes.py' )
151
+ sdist .filelist .files .append (" ua_parser/_regexes.py" )
142
152
143
153
144
154
class develop (_develop ):
145
155
def run (self ):
146
- self .run_command (' build_regexes' )
156
+ self .run_command (" build_regexes" )
147
157
_develop .run (self )
148
158
149
159
150
160
class install (_install ):
151
161
def run (self ):
152
- self .run_command (' build_regexes' )
162
+ self .run_command (" build_regexes" )
153
163
_install .run (self )
154
164
155
165
156
166
class build (_build ):
157
167
def run (self ):
158
- self .run_command (' build_regexes' )
168
+ self .run_command (" build_regexes" )
159
169
_build .run (self )
160
170
161
171
162
172
class sdist (_sdist ):
163
- sub_commands = _sdist .sub_commands + [(' build_regexes' , None )]
173
+ sub_commands = _sdist .sub_commands + [(" build_regexes" , None )]
164
174
165
175
166
176
cmdclass = {
167
- ' sdist' : sdist ,
168
- ' develop' : develop ,
169
- ' build' : build ,
170
- ' install' : install ,
171
- ' build_regexes' : build_regexes ,
177
+ " sdist" : sdist ,
178
+ " develop" : develop ,
179
+ " build" : build ,
180
+ " install" : install ,
181
+ " build_regexes" : build_regexes ,
172
182
}
173
183
174
184
175
185
setup (
176
- name = ' ua-parser' ,
177
- version = ' 0.8.0' ,
186
+ name = " ua-parser" ,
187
+ version = " 0.8.0" ,
178
188
description = "Python port of Browserscope's user agent parser" ,
179
- author = ' PBS' ,
180
-
181
- packages = [' ua_parser' ],
182
- package_dir = {'' : '.' },
183
- license = ' Apache 2.0' ,
189
+ author = " PBS" ,
190
+
191
+ packages = [" ua_parser" ],
192
+ package_dir = {"" : "." },
193
+ license = " Apache 2.0" ,
184
194
zip_safe = False ,
185
- url = ' https://github.com/ua-parser/uap-python' ,
195
+ url = " https://github.com/ua-parser/uap-python" ,
186
196
include_package_data = True ,
187
- setup_requires = [' pyyaml' ],
197
+ setup_requires = [" pyyaml" ],
188
198
install_requires = [],
189
199
cmdclass = cmdclass ,
190
200
classifiers = [
191
- ' Development Status :: 4 - Beta' ,
192
- ' Environment :: Web Environment' ,
193
- ' Intended Audience :: Developers' ,
194
- ' Operating System :: OS Independent' ,
195
- ' License :: OSI Approved :: Apache Software License' ,
196
- ' Programming Language :: Python' ,
197
- ' Topic :: Internet :: WWW/HTTP' ,
198
- ' Topic :: Software Development :: Libraries :: Python Modules' ,
199
- ' Programming Language :: Python' ,
200
- ' Programming Language :: Python :: 2' ,
201
- ' Programming Language :: Python :: 2.6' ,
202
- ' Programming Language :: Python :: 2.7' ,
203
- ' Programming Language :: Python :: 3' ,
204
- ' Programming Language :: Python :: 3.3' ,
205
- ' Programming Language :: Python :: 3.4' ,
206
- ' Programming Language :: Python :: 3.5' ,
207
- ' Programming Language :: Python :: 3.6' ,
208
- ' Programming Language :: Python :: 3.7' ,
209
- ' Programming Language :: Python :: 3.8' ,
210
- ' Programming Language :: Python :: Implementation :: CPython' ,
211
- ' Programming Language :: Python :: Implementation :: PyPy' ,
201
+ " Development Status :: 4 - Beta" ,
202
+ " Environment :: Web Environment" ,
203
+ " Intended Audience :: Developers" ,
204
+ " Operating System :: OS Independent" ,
205
+ " License :: OSI Approved :: Apache Software License" ,
206
+ " Programming Language :: Python" ,
207
+ " Topic :: Internet :: WWW/HTTP" ,
208
+ " Topic :: Software Development :: Libraries :: Python Modules" ,
209
+ " Programming Language :: Python" ,
210
+ " Programming Language :: Python :: 2" ,
211
+ " Programming Language :: Python :: 2.6" ,
212
+ " Programming Language :: Python :: 2.7" ,
213
+ " Programming Language :: Python :: 3" ,
214
+ " Programming Language :: Python :: 3.3" ,
215
+ " Programming Language :: Python :: 3.4" ,
216
+ " Programming Language :: Python :: 3.5" ,
217
+ " Programming Language :: Python :: 3.6" ,
218
+ " Programming Language :: Python :: 3.7" ,
219
+ " Programming Language :: Python :: 3.8" ,
220
+ " Programming Language :: Python :: Implementation :: CPython" ,
221
+ " Programming Language :: Python :: Implementation :: PyPy" ,
212
222
],
213
223
)
0 commit comments