Skip to content

Commit fe7007b

Browse files
authored
Merge pull request #56 from maxmind/greg/black
Format with black instead of yapf
2 parents 3a52bbc + 922f243 commit fe7007b

File tree

13 files changed

+620
-586
lines changed

13 files changed

+620
-586
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[MESSAGES CONTROL]
2-
disable=R0201,R0205,W0105
2+
disable=C0330,R0201,R0205,W0105
33

44
[BASIC]
55

.travis-yapf.sh renamed to .travis-black.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
22

3-
diff=$(yapf -rd maxminddb tests)
3+
set -eux
4+
5+
diff=$(black --check .)
46

57
if [[ $? != 0 ]]; then
6-
echo "yapf failed to run."
8+
echo "black failed to run."
79
echo "$diff"
810
exit $?
911
elif [[ $diff ]]; then

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ before_install:
3131
- sudo ldconfig
3232
- cd ..
3333
- pip install coverage coveralls
34-
- if [[ $RUN_LINTER ]]; then pip install pylint yapf; fi
34+
- if [[ $RUN_LINTER ]]; then pip install pylint black; fi
3535
- |
3636
if [[ $RUN_SNYK && $SNYK_TOKEN ]]; then
3737
sudo apt-get install -y nodejs;
@@ -43,7 +43,7 @@ script:
4343
- CFLAGS="-Werror -Wall -Wextra" coverage run --source maxminddb setup.py test
4444
- if [[ $RUN_SNYK && $SNYK_TOKEN ]]; then snyk test --org=maxmind --file=requirements.txt; fi
4545
- if [[ $RUN_LINTER ]]; then pylint --rcfile .pylintrc maxminddb/*.py; fi
46-
- if [[ $RUN_LINTER ]]; then ./.travis-yapf.sh; fi
46+
- if [[ $RUN_LINTER ]]; then ./.travis-black.sh; fi
4747

4848
after_success:
4949
- coveralls

docs/conf.py

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,45 @@
1515
import sys
1616
import os
1717

18-
sys.path.insert(0, os.path.abspath('..'))
18+
sys.path.insert(0, os.path.abspath(".."))
1919
import maxminddb
2020

2121
__version__ = maxminddb.__version__
2222

2323
# If extensions (or modules to document with autodoc) are in another directory,
2424
# add these directories to sys.path here. If the directory is relative to the
2525
# documentation root, use os.path.abspath to make it absolute, like shown here.
26-
sys.path.insert(0, os.path.abspath('..'))
26+
sys.path.insert(0, os.path.abspath(".."))
2727

2828
# -- General configuration -----------------------------------------------
2929

3030
# If your documentation needs a minimal Sphinx version, state it here.
31-
#needs_sphinx = '1.0'
31+
# needs_sphinx = '1.0'
3232

3333
# Add any Sphinx extension module names here, as strings. They can be extensions
3434
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
3535
extensions = [
36-
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
37-
'sphinx.ext.coverage'
36+
"sphinx.ext.autodoc",
37+
"sphinx.ext.doctest",
38+
"sphinx.ext.intersphinx",
39+
"sphinx.ext.coverage",
3840
]
3941

4042
# Add any paths that contain templates here, relative to this directory.
41-
templates_path = ['_templates']
43+
templates_path = ["_templates"]
4244

4345
# The suffix of source filenames.
44-
source_suffix = '.rst'
46+
source_suffix = ".rst"
4547

4648
# The encoding of source files.
47-
#source_encoding = 'utf-8-sig'
49+
# source_encoding = 'utf-8-sig'
4850

4951
# The master toctree document.
50-
master_doc = 'index'
52+
master_doc = "index"
5153

5254
# General information about the project.
53-
project = 'maxminddb'
54-
copyright = '2013-2019, MaxMind, Inc.'
55+
project = "maxminddb"
56+
copyright = "2013-2019, MaxMind, Inc."
5557

5658
# The version info for the project you're documenting, acts as replacement for
5759
# |version| and |release|, also used in various other places throughout the
@@ -64,185 +66,188 @@
6466

6567
# The language for content autogenerated by Sphinx. Refer to documentation
6668
# for a list of supported languages.
67-
#language = None
69+
# language = None
6870

6971
# There are two options for replacing |today|: either, you set today to some
7072
# non-false value, then it is used:
71-
#today = ''
73+
# today = ''
7274
# Else, today_fmt is used as the format for a strftime call.
73-
#today_fmt = '%B %d, %Y'
75+
# today_fmt = '%B %d, %Y'
7476

7577
# List of patterns, relative to source directory, that match files and
7678
# directories to ignore when looking for source files.
77-
exclude_patterns = ['_build']
79+
exclude_patterns = ["_build"]
7880

7981
# The reST default role (used for this markup: `text`) to use for all documents.
80-
#default_role = None
82+
# default_role = None
8183

8284
# If true, '()' will be appended to :func: etc. cross-reference text.
83-
#add_function_parentheses = True
85+
# add_function_parentheses = True
8486

8587
# If true, the current module name will be prepended to all description
8688
# unit titles (such as .. function::).
87-
#add_module_names = True
89+
# add_module_names = True
8890

8991
# If true, sectionauthor and moduleauthor directives will be shown in the
9092
# output. They are ignored by default.
91-
#show_authors = False
93+
# show_authors = False
9294

9395
# The name of the Pygments (syntax highlighting) style to use.
94-
pygments_style = 'sphinx'
96+
pygments_style = "sphinx"
9597

9698
# A list of ignored prefixes for module index sorting.
97-
#modindex_common_prefix = []
99+
# modindex_common_prefix = []
98100

99101
# -- Options for HTML output ---------------------------------------------
100102

101103
# The theme to use for HTML and HTML Help pages. See the documentation for
102104
# a list of builtin themes.
103-
html_theme = 'sphinxdoc'
105+
html_theme = "sphinxdoc"
104106

105107
# Theme options are theme-specific and customize the look and feel of a theme
106108
# further. For a list of options available for each theme, see the
107109
# documentation.
108-
#html_theme_options = {}
110+
# html_theme_options = {}
109111

110112
# Add any paths that contain custom themes here, relative to this directory.
111-
#html_theme_path = []
113+
# html_theme_path = []
112114

113115
# The name for this set of Sphinx documents. If None, it defaults to
114116
# "<project> v<release> documentation".
115-
#html_title = None
117+
# html_title = None
116118

117119
# A shorter title for the navigation bar. Default is the same as html_title.
118-
#html_short_title = None
120+
# html_short_title = None
119121

120122
# The name of an image file (relative to this directory) to place at the top
121123
# of the sidebar.
122-
#html_logo = None
124+
# html_logo = None
123125

124126
# The name of an image file (within the static path) to use as favicon of the
125127
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
126128
# pixels large.
127-
#html_favicon = None
129+
# html_favicon = None
128130

129131
# Add any paths that contain custom static files (such as style sheets) here,
130132
# relative to this directory. They are copied after the builtin static files,
131133
# so a file named "default.css" will overwrite the builtin "default.css".
132-
html_static_path = ['_static']
134+
html_static_path = ["_static"]
133135

134136
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
135137
# using the given strftime format.
136-
#html_last_updated_fmt = '%b %d, %Y'
138+
# html_last_updated_fmt = '%b %d, %Y'
137139

138140
# If true, SmartyPants will be used to convert quotes and dashes to
139141
# typographically correct entities.
140-
#html_use_smartypants = True
142+
# html_use_smartypants = True
141143

142144
# Custom sidebar templates, maps document names to template names.
143-
#html_sidebars = {}
145+
# html_sidebars = {}
144146

145147
# Additional templates that should be rendered to pages, maps page names to
146148
# template names.
147-
#html_additional_pages = {}
149+
# html_additional_pages = {}
148150

149151
# If false, no module index is generated.
150-
#html_domain_indices = True
152+
# html_domain_indices = True
151153

152154
# If false, no index is generated.
153-
#html_use_index = True
155+
# html_use_index = True
154156

155157
# If true, the index is split into individual pages for each letter.
156-
#html_split_index = False
158+
# html_split_index = False
157159

158160
# If true, links to the reST sources are added to the pages.
159-
#html_show_sourcelink = True
161+
# html_show_sourcelink = True
160162

161163
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
162-
#html_show_sphinx = True
164+
# html_show_sphinx = True
163165

164166
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
165-
#html_show_copyright = True
167+
# html_show_copyright = True
166168

167169
# If true, an OpenSearch description file will be output, and all pages will
168170
# contain a <link> tag referring to it. The value of this option must be the
169171
# base URL from which the finished HTML is served.
170-
#html_use_opensearch = ''
172+
# html_use_opensearch = ''
171173

172174
# This is the file name suffix for HTML files (e.g. ".xhtml").
173-
#html_file_suffix = None
175+
# html_file_suffix = None
174176

175177
# Output file base name for HTML help builder.
176-
htmlhelp_basename = 'maxminddbdoc'
178+
htmlhelp_basename = "maxminddbdoc"
177179

178180
# -- Options for LaTeX output --------------------------------------------
179181

180182
latex_elements = {
181183
# The paper size ('letterpaper' or 'a4paper').
182184
#'papersize': 'letterpaper',
183-
184185
# The font size ('10pt', '11pt' or '12pt').
185186
#'pointsize': '10pt',
186-
187187
# Additional stuff for the LaTeX preamble.
188188
#'preamble': '',
189189
}
190190

191191
# Grouping the document tree into LaTeX files. List of tuples
192192
# (source start file, target name, title, author, documentclass [howto/manual]).
193193
latex_documents = [
194-
('index', 'maxminddb.tex', 'maxminddb Documentation', 'Gregory Oschwald',
195-
'manual'),
194+
("index", "maxminddb.tex", "maxminddb Documentation", "Gregory Oschwald", "manual"),
196195
]
197196

198197
# The name of an image file (relative to this directory) to place at the top of
199198
# the title page.
200-
#latex_logo = None
199+
# latex_logo = None
201200

202201
# For "manual" documents, if this is true, then toplevel headings are parts,
203202
# not chapters.
204-
#latex_use_parts = False
203+
# latex_use_parts = False
205204

206205
# If true, show page references after internal links.
207-
#latex_show_pagerefs = False
206+
# latex_show_pagerefs = False
208207

209208
# If true, show URL addresses after external links.
210-
#latex_show_urls = False
209+
# latex_show_urls = False
211210

212211
# Documents to append as an appendix to all manuals.
213-
#latex_appendices = []
212+
# latex_appendices = []
214213

215214
# If false, no module index is generated.
216-
#latex_domain_indices = True
215+
# latex_domain_indices = True
217216

218217
# -- Options for manual page output --------------------------------------
219218

220219
# One entry per manual page. List of tuples
221220
# (source start file, name, description, authors, manual section).
222-
man_pages = [('index', 'maxminddb', 'maxminddb Documentation',
223-
['Gregory Oschwald'], 1)]
221+
man_pages = [("index", "maxminddb", "maxminddb Documentation", ["Gregory Oschwald"], 1)]
224222

225223
# If true, show URL addresses after external links.
226-
#man_show_urls = False
224+
# man_show_urls = False
227225

228226
# -- Options for Texinfo output ------------------------------------------
229227

230228
# Grouping the document tree into Texinfo files. List of tuples
231229
# (source start file, target name, title, author,
232230
# dir menu entry, description, category)
233231
texinfo_documents = [
234-
('index', 'maxminddb', 'maxminddb Documentation', 'Gregory Oschwald',
235-
'maxminddb', 'MaxMind DB Reader', 'Miscellaneous'),
232+
(
233+
"index",
234+
"maxminddb",
235+
"maxminddb Documentation",
236+
"Gregory Oschwald",
237+
"maxminddb",
238+
"MaxMind DB Reader",
239+
"Miscellaneous",
240+
),
236241
]
237242

238243
# Documents to append as an appendix to all manuals.
239-
#texinfo_appendices = []
244+
# texinfo_appendices = []
240245

241246
# If false, no module index is generated.
242-
#texinfo_domain_indices = True
247+
# texinfo_domain_indices = True
243248

244249
# How to display URL addresses: 'footnote', 'no', or 'inline'.
245-
#texinfo_show_urls = 'footnote'
250+
# texinfo_show_urls = 'footnote'
246251

247252
# Example configuration for intersphinx: refer to the Python standard library.
248-
intersphinx_mapping = {'http://docs.python.org/': None}
253+
intersphinx_mapping = {"http://docs.python.org/": None}

examples/benchmark.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@
1010
import struct
1111
import timeit
1212

13-
parser = argparse.ArgumentParser(description='Benchmark maxminddb.')
14-
parser.add_argument('--count',
15-
default=250000,
16-
type=int,
17-
help='number of lookups')
18-
parser.add_argument('--mode', default=0, type=int, help='reader mode to use')
19-
parser.add_argument('--file',
20-
default='GeoIP2-City.mmdb',
21-
help='path to mmdb file')
13+
parser = argparse.ArgumentParser(description="Benchmark maxminddb.")
14+
parser.add_argument("--count", default=250000, type=int, help="number of lookups")
15+
parser.add_argument("--mode", default=0, type=int, help="reader mode to use")
16+
parser.add_argument("--file", default="GeoIP2-City.mmdb", help="path to mmdb file")
2217

2318
args = parser.parse_args()
2419

@@ -27,12 +22,14 @@
2722

2823

2924
def lookup_ip_address():
30-
ip = socket.inet_ntoa(struct.pack('!L', random.getrandbits(32)))
25+
ip = socket.inet_ntoa(struct.pack("!L", random.getrandbits(32)))
3126
record = reader.get(str(ip))
3227

3328

34-
elapsed = timeit.timeit('lookup_ip_address()',
35-
setup='from __main__ import lookup_ip_address',
36-
number=args.count)
29+
elapsed = timeit.timeit(
30+
"lookup_ip_address()",
31+
setup="from __main__ import lookup_ip_address",
32+
number=args.count,
33+
)
3734

38-
print(args.count / elapsed, 'lookups per second')
35+
print(args.count / elapsed, "lookups per second")

0 commit comments

Comments
 (0)