Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0ab043

Browse files
committed
Apply black everywhere else
1 parent 3aff3c4 commit d0ab043

File tree

4 files changed

+279
-230
lines changed

4 files changed

+279
-230
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ clean:
1515
dist \
1616
build \
1717
ua_parser/_regexes.py
18+
format:
19+
@black .
1820

1921
release: clean
2022
python setup.py sdist bdist_wheel
2123
twine upload -s dist/*
2224

23-
.PHONY: all test clean release
25+
.PHONY: all test clean format release

setup.py

Lines changed: 130 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# flake8: noqa
23
import os
34
from distutils import log
45
from distutils.core import Command
@@ -11,27 +12,32 @@
1112

1213
def check_output(*args, **kwargs):
1314
from subprocess import Popen
15+
1416
proc = Popen(*args, **kwargs)
1517
output, _ = proc.communicate()
1618
rv = proc.poll()
1719
assert rv == 0, output
1820

1921

2022
class build_regexes(Command):
21-
description = 'build supporting regular expressions from uap-core'
23+
description = "build supporting regular expressions from uap-core"
2224
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+
),
3339
]
34-
boolean_options = ['force']
40+
boolean_options = ["force"]
3541

3642
def initialize_options(self):
3743
self.build_lib = None
@@ -40,174 +46,178 @@ def initialize_options(self):
4046
self.inplace = None
4147

4248
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")
4652

4753
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+
)
5057

5158
if self.inplace:
52-
self.build_lib = '.'
59+
self.build_lib = "."
5360
else:
54-
self.set_undefined_options('build',
55-
('build_lib', 'build_lib'))
61+
self.set_undefined_options("build", ("build_lib", "build_lib"))
5662
if self.work_path is None:
5763
self.work_path = os.path.realpath(os.path.join(os.path.dirname(__file__)))
5864

5965
def run(self):
6066
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")):
6268
return
6369

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)
6773

68-
yaml_src = os.path.join(work_path, 'uap-core', 'regexes.yaml')
74+
yaml_src = os.path.join(work_path, "uap-core", "regexes.yaml")
6975
if not os.path.exists(yaml_src):
7076
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+
)
7279

7380
def force_bytes(text):
7481
if text is None:
7582
return text
76-
return text.encode('utf8')
83+
return text.encode("utf8")
7784

7885
import yaml
79-
py_dest = os.path.join(self.build_lib, 'ua_parser', '_regexes.py')
8086

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:
8391
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
133143

134144
self.update_manifest()
135145

136146
def update_manifest(self):
137-
sdist = self.distribution.get_command_obj('sdist')
147+
sdist = self.distribution.get_command_obj("sdist")
138148
if not sdist.finalized:
139149
return
140150

141-
sdist.filelist.files.append('ua_parser/_regexes.py')
151+
sdist.filelist.files.append("ua_parser/_regexes.py")
142152

143153

144154
class develop(_develop):
145155
def run(self):
146-
self.run_command('build_regexes')
156+
self.run_command("build_regexes")
147157
_develop.run(self)
148158

149159

150160
class install(_install):
151161
def run(self):
152-
self.run_command('build_regexes')
162+
self.run_command("build_regexes")
153163
_install.run(self)
154164

155165

156166
class build(_build):
157167
def run(self):
158-
self.run_command('build_regexes')
168+
self.run_command("build_regexes")
159169
_build.run(self)
160170

161171

162172
class sdist(_sdist):
163-
sub_commands = _sdist.sub_commands + [('build_regexes', None)]
173+
sub_commands = _sdist.sub_commands + [("build_regexes", None)]
164174

165175

166176
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,
172182
}
173183

174184

175185
setup(
176-
name='ua-parser',
177-
version='0.8.0',
186+
name="ua-parser",
187+
version="0.8.0",
178188
description="Python port of Browserscope's user agent parser",
179-
author='PBS',
180-
author_email='[email protected]',
181-
packages=['ua_parser'],
182-
package_dir={'': '.'},
183-
license='Apache 2.0',
189+
author="PBS",
190+
author_email="[email protected]",
191+
packages=["ua_parser"],
192+
package_dir={"": "."},
193+
license="Apache 2.0",
184194
zip_safe=False,
185-
url='https://github.com/ua-parser/uap-python',
195+
url="https://github.com/ua-parser/uap-python",
186196
include_package_data=True,
187-
setup_requires=['pyyaml'],
197+
setup_requires=["pyyaml"],
188198
install_requires=[],
189199
cmdclass=cmdclass,
190200
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",
212222
],
213223
)

tox.ini

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27, py36, py37, py38, docs, py27-flake8, py36-flake8
2+
envlist = py27, py36, py37, py38, docs, py27-flake8, py36-flake8, py36-black
33

44
[testenv]
55
deps =
@@ -25,6 +25,11 @@ basepython = python3.6
2525
deps = flake8
2626
commands = flake8 {posargs}
2727

28+
[testenv:py36-black]
29+
basepython = python3.6
30+
deps = black
31+
commands = black .
32+
2833
[flake8]
29-
max_line_length = 120
34+
max_line_length = 88
3035
exclude = .git,.tox,dist,docs,_regexes.py,*_test.py,.eggs

0 commit comments

Comments
 (0)