Skip to content

Commit a10730a

Browse files
authored
Merge pull request #84 from maxmind/greg/black
Use black instead of yapf
2 parents 72ab006 + 2c91752 commit a10730a

17 files changed

Lines changed: 1040 additions & 919 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
set -eux
44

5-
diff=$(yapf -rd geoip2 tests)
5+
diff=$(black --check .)
66

77
if [[ $? != 0 ]]; then
8-
echo "yapf failed to run."
8+
echo "black failed to run."
99
echo "$diff"
1010
exit $?
1111
elif [[ $diff ]]; then

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ before_install:
3636
- "if [[ $RUN_SNYK && $SNYK_TOKEN ]]; then sudo apt-get install -y nodejs; npm install -g snyk; fi"
3737
install:
3838
- pip install -r requirements.txt
39-
# We require yapf 0.28.0 to work around https://github.com/google/yapf/issues/781
40-
# If that issue is resolved, we should remove the version constraint.
41-
- pip install requests_mock pylint coveralls yapf==0.28.0
39+
- pip install requests_mock coveralls
40+
- |
41+
if [[ $RUN_LINTER ]]; then
42+
pip install --upgrade pylint black
43+
fi
4244
- "if [[ $RUN_SNYK && $SNYK_TOKEN ]]; then snyk test --org=maxmind; fi"
4345
script:
4446
- coverage run --source=geoip2 setup.py test
4547
- "if [[ $RUN_LINTER ]]; then ./.travis-pylint.sh; fi"
46-
- "if [[ $RUN_LINTER ]]; then ./.travis-yapf.sh; fi"
48+
- "if [[ $RUN_LINTER ]]; then ./.travis-black.sh; fi"
4749
after_success:
4850
- coveralls
4951
- "if [[ $RUN_SNYK && $SNYK_TOKEN && $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then snyk monitor --org=maxmind --project-name=maxmind/GeoIP2-python; fi"

docs/conf.py

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,38 @@
1818
# If extensions (or modules to document with autodoc) are in another directory,
1919
# add these directories to sys.path here. If the directory is relative to the
2020
# documentation root, use os.path.abspath to make it absolute, like shown here.
21-
sys.path.insert(0, os.path.abspath('..'))
21+
sys.path.insert(0, os.path.abspath(".."))
2222
import geoip2
2323

2424
# -- General configuration -----------------------------------------------
2525

2626
# If your documentation needs a minimal Sphinx version, state it here.
27-
#needs_sphinx = '1.0'
27+
# needs_sphinx = '1.0'
2828

2929
# Add any Sphinx extension module names here, as strings. They can be extensions
3030
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
3131
extensions = [
32-
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
33-
'sphinx.ext.coverage'
32+
"sphinx.ext.autodoc",
33+
"sphinx.ext.doctest",
34+
"sphinx.ext.intersphinx",
35+
"sphinx.ext.coverage",
3436
]
3537

3638
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
39+
templates_path = ["_templates"]
3840

3941
# The suffix of source filenames.
40-
source_suffix = '.rst'
42+
source_suffix = ".rst"
4143

4244
# The encoding of source files.
43-
#source_encoding = 'utf-8-sig'
45+
# source_encoding = 'utf-8-sig'
4446

4547
# The master toctree document.
46-
master_doc = 'index'
48+
master_doc = "index"
4749

4850
# General information about the project.
49-
project = 'geoip2'
50-
copyright = '2013-2019, MaxMind, Inc.'
51+
project = "geoip2"
52+
copyright = "2013-2019, MaxMind, Inc."
5153

5254
# The version info for the project you're documenting, acts as replacement for
5355
# |version| and |release|, also used in various other places throughout the
@@ -60,185 +62,188 @@
6062

6163
# The language for content autogenerated by Sphinx. Refer to documentation
6264
# for a list of supported languages.
63-
#language = None
65+
# language = None
6466

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

7173
# List of patterns, relative to source directory, that match files and
7274
# directories to ignore when looking for source files.
73-
exclude_patterns = ['_build']
75+
exclude_patterns = ["_build"]
7476

7577
# The reST default role (used for this markup: `text`) to use for all documents.
76-
#default_role = None
78+
# default_role = None
7779

7880
# If true, '()' will be appended to :func: etc. cross-reference text.
79-
#add_function_parentheses = True
81+
# add_function_parentheses = True
8082

8183
# If true, the current module name will be prepended to all description
8284
# unit titles (such as .. function::).
83-
#add_module_names = True
85+
# add_module_names = True
8486

8587
# If true, sectionauthor and moduleauthor directives will be shown in the
8688
# output. They are ignored by default.
87-
#show_authors = False
89+
# show_authors = False
8890

8991
# The name of the Pygments (syntax highlighting) style to use.
90-
pygments_style = 'sphinx'
92+
pygments_style = "sphinx"
9193

9294
# A list of ignored prefixes for module index sorting.
93-
#modindex_common_prefix = []
95+
# modindex_common_prefix = []
9496

9597
# -- Options for HTML output ---------------------------------------------
9698

9799
# The theme to use for HTML and HTML Help pages. See the documentation for
98100
# a list of builtin themes.
99-
html_theme = 'sphinxdoc'
101+
html_theme = "sphinxdoc"
100102

101103
# Theme options are theme-specific and customize the look and feel of a theme
102104
# further. For a list of options available for each theme, see the
103105
# documentation.
104-
#html_theme_options = {}
106+
# html_theme_options = {}
105107

106108
# Add any paths that contain custom themes here, relative to this directory.
107-
#html_theme_path = []
109+
# html_theme_path = []
108110

109111
# The name for this set of Sphinx documents. If None, it defaults to
110112
# "<project> v<release> documentation".
111-
#html_title = None
113+
# html_title = None
112114

113115
# A shorter title for the navigation bar. Default is the same as html_title.
114-
#html_short_title = None
116+
# html_short_title = None
115117

116118
# The name of an image file (relative to this directory) to place at the top
117119
# of the sidebar.
118-
#html_logo = None
120+
# html_logo = None
119121

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

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

130132
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
131133
# using the given strftime format.
132-
#html_last_updated_fmt = '%b %d, %Y'
134+
# html_last_updated_fmt = '%b %d, %Y'
133135

134136
# If true, SmartyPants will be used to convert quotes and dashes to
135137
# typographically correct entities.
136-
#html_use_smartypants = True
138+
# html_use_smartypants = True
137139

138140
# Custom sidebar templates, maps document names to template names.
139-
#html_sidebars = {}
141+
# html_sidebars = {}
140142

141143
# Additional templates that should be rendered to pages, maps page names to
142144
# template names.
143-
#html_additional_pages = {}
145+
# html_additional_pages = {}
144146

145147
# If false, no module index is generated.
146-
#html_domain_indices = True
148+
# html_domain_indices = True
147149

148150
# If false, no index is generated.
149-
#html_use_index = True
151+
# html_use_index = True
150152

151153
# If true, the index is split into individual pages for each letter.
152-
#html_split_index = False
154+
# html_split_index = False
153155

154156
# If true, links to the reST sources are added to the pages.
155-
#html_show_sourcelink = True
157+
# html_show_sourcelink = True
156158

157159
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
158-
#html_show_sphinx = True
160+
# html_show_sphinx = True
159161

160162
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
161-
#html_show_copyright = True
163+
# html_show_copyright = True
162164

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

168170
# This is the file name suffix for HTML files (e.g. ".xhtml").
169-
#html_file_suffix = None
171+
# html_file_suffix = None
170172

171173
# Output file base name for HTML help builder.
172-
htmlhelp_basename = 'geoip2doc'
174+
htmlhelp_basename = "geoip2doc"
173175

174176
# -- Options for LaTeX output --------------------------------------------
175177

176178
latex_elements = {
177179
# The paper size ('letterpaper' or 'a4paper').
178180
#'papersize': 'letterpaper',
179-
180181
# The font size ('10pt', '11pt' or '12pt').
181182
#'pointsize': '10pt',
182-
183183
# Additional stuff for the LaTeX preamble.
184184
#'preamble': '',
185185
}
186186

187187
# Grouping the document tree into LaTeX files. List of tuples
188188
# (source start file, target name, title, author, documentclass [howto/manual]).
189189
latex_documents = [
190-
('index', 'geoip2.tex', 'geoip2 Documentation', 'Gregory Oschwald',
191-
'manual'),
190+
("index", "geoip2.tex", "geoip2 Documentation", "Gregory Oschwald", "manual"),
192191
]
193192

194193
# The name of an image file (relative to this directory) to place at the top of
195194
# the title page.
196-
#latex_logo = None
195+
# latex_logo = None
197196

198197
# For "manual" documents, if this is true, then toplevel headings are parts,
199198
# not chapters.
200-
#latex_use_parts = False
199+
# latex_use_parts = False
201200

202201
# If true, show page references after internal links.
203-
#latex_show_pagerefs = False
202+
# latex_show_pagerefs = False
204203

205204
# If true, show URL addresses after external links.
206-
#latex_show_urls = False
205+
# latex_show_urls = False
207206

208207
# Documents to append as an appendix to all manuals.
209-
#latex_appendices = []
208+
# latex_appendices = []
210209

211210
# If false, no module index is generated.
212-
#latex_domain_indices = True
211+
# latex_domain_indices = True
213212

214213
# -- Options for manual page output --------------------------------------
215214

216215
# One entry per manual page. List of tuples
217216
# (source start file, name, description, authors, manual section).
218-
man_pages = [('index', 'geoip2', 'geoip2 Documentation', ['Gregory Oschwald'],
219-
1)]
217+
man_pages = [("index", "geoip2", "geoip2 Documentation", ["Gregory Oschwald"], 1)]
220218

221219
# If true, show URL addresses after external links.
222-
#man_show_urls = False
220+
# man_show_urls = False
223221

224222
# -- Options for Texinfo output ------------------------------------------
225223

226224
# Grouping the document tree into Texinfo files. List of tuples
227225
# (source start file, target name, title, author,
228226
# dir menu entry, description, category)
229227
texinfo_documents = [
230-
('index', 'geoip2', 'geoip2 Documentation', 'Gregory Oschwald', 'geoip2',
231-
'One line description of project.', 'Miscellaneous'),
228+
(
229+
"index",
230+
"geoip2",
231+
"geoip2 Documentation",
232+
"Gregory Oschwald",
233+
"geoip2",
234+
"One line description of project.",
235+
"Miscellaneous",
236+
),
232237
]
233238

234239
# Documents to append as an appendix to all manuals.
235-
#texinfo_appendices = []
240+
# texinfo_appendices = []
236241

237242
# If false, no module index is generated.
238-
#texinfo_domain_indices = True
243+
# texinfo_domain_indices = True
239244

240245
# How to display URL addresses: 'footnote', 'no', or 'inline'.
241-
#texinfo_show_urls = 'footnote'
246+
# texinfo_show_urls = 'footnote'
242247

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

examples/benchmark.py

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

13-
parser = argparse.ArgumentParser(description='Benchmark maxminddb.')
14-
parser.add_argument(
15-
'--count', default=250000, type=int, help='number of lookups')
16-
parser.add_argument('--mode', default=0, type=int, help='reader mode to use')
17-
parser.add_argument(
18-
'--file', default='GeoIP2-City.mmdb', 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")
1917

2018
args = parser.parse_args()
2119

2220
reader = geoip2.database.Reader(args.file, mode=args.mode)
2321

2422

2523
def lookup_ip_address():
26-
ip = socket.inet_ntoa(struct.pack('!L', random.getrandbits(32)))
24+
ip = socket.inet_ntoa(struct.pack("!L", random.getrandbits(32)))
2725
try:
2826
record = reader.city(str(ip))
2927
except geoip2.errors.AddressNotFoundError:
3028
pass
3129

3230

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

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

geoip2/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint:disable=C0111
22

3-
__title__ = 'geoip2'
4-
__version__ = '3.0.0'
5-
__author__ = 'Gregory Oschwald'
6-
__license__ = 'Apache License, Version 2.0'
7-
__copyright__ = 'Copyright (c) 2013-2019 Maxmind, Inc.'
3+
__title__ = "geoip2"
4+
__version__ = "3.0.0"
5+
__author__ = "Gregory Oschwald"
6+
__license__ = "Apache License, Version 2.0"
7+
__copyright__ = "Copyright (c) 2013-2019 Maxmind, Inc."

geoip2/compat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def compat_ip_network(network, strict=True):
1818
if isinstance(network, bytes):
1919
network = network.decode()
2020
return ipaddress.ip_network(network, strict)
21+
22+
2123
else:
2224

2325
def compat_ip_address(address):

0 commit comments

Comments
 (0)