Skip to content

Commit 71820dd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 94ac056 commit 71820dd

File tree

6 files changed

+229
-183
lines changed

6 files changed

+229
-183
lines changed

.codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# show coverage in CI status, not as a comment.
1+
# show coverage in CI status, not as a comment.
22
comment: off
33
coverage:
44
status:

CONTRIBUTING.rst

-1
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,3 @@ Before you submit a pull request, check that it meets these guidelines:
101101
3. The pull request should work for Python 2.7, 3.3, 3.4, 3.5 and for PyPy. Check
102102
https://travis-ci.org/sbillinge/diffpy.test_data/pull_requests
103103
and make sure that the tests pass for all supported Python versions.
104-

diffpy.test_data/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
21
from ._version import get_versions
3-
__version__ = get_versions()['version']
2+
3+
__version__ = get_versions()["version"]
44
del get_versions

diffpy.test_data/_version.py

+77-59
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# This file helps to compute a version number in source trees obtained from
32
# git-archive tarball (such as those provided by githubs download-from-tag
43
# feature). Distribution tarballs (built by setup.py sdist) and build
@@ -58,28 +57,32 @@ class NotThisMethod(Exception):
5857

5958
def register_vcs_handler(vcs, method): # decorator
6059
"""Decorator to mark a method as the handler for a particular VCS."""
60+
6161
def decorate(f):
6262
"""Store f in HANDLERS[vcs][method]."""
6363
if vcs not in HANDLERS:
6464
HANDLERS[vcs] = {}
6565
HANDLERS[vcs][method] = f
6666
return f
67+
6768
return decorate
6869

6970

70-
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
71-
env=None):
71+
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
7272
"""Call the given command(s)."""
7373
assert isinstance(commands, list)
7474
p = None
7575
for c in commands:
7676
try:
7777
dispcmd = str([c] + args)
7878
# remember shell=False, so use git.cmd on windows, not just git
79-
p = subprocess.Popen([c] + args, cwd=cwd, env=env,
80-
stdout=subprocess.PIPE,
81-
stderr=(subprocess.PIPE if hide_stderr
82-
else None))
79+
p = subprocess.Popen(
80+
[c] + args,
81+
cwd=cwd,
82+
env=env,
83+
stdout=subprocess.PIPE,
84+
stderr=(subprocess.PIPE if hide_stderr else None),
85+
)
8386
break
8487
except EnvironmentError:
8588
e = sys.exc_info()[1]
@@ -116,16 +119,19 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
116119
for i in range(3):
117120
dirname = os.path.basename(root)
118121
if dirname.startswith(parentdir_prefix):
119-
return {"version": dirname[len(parentdir_prefix):],
120-
"full-revisionid": None,
121-
"dirty": False, "error": None, "date": None}
122+
return {
123+
"version": dirname[len(parentdir_prefix) :],
124+
"full-revisionid": None,
125+
"dirty": False,
126+
"error": None,
127+
"date": None,
128+
}
122129
else:
123130
rootdirs.append(root)
124131
root = os.path.dirname(root) # up a level
125132

126133
if verbose:
127-
print("Tried directories %s but none started with prefix %s" %
128-
(str(rootdirs), parentdir_prefix))
134+
print("Tried directories %s but none started with prefix %s" % (str(rootdirs), parentdir_prefix))
129135
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
130136

131137

@@ -181,7 +187,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
181187
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
182188
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
183189
TAG = "tag: "
184-
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
190+
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
185191
if not tags:
186192
# Either we're using git < 1.8.3, or there really are no tags. We use
187193
# a heuristic: assume all version tags have a digit. The old git %d
@@ -190,27 +196,34 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
190196
# between branches and tags. By ignoring refnames without digits, we
191197
# filter out many common branch names like "release" and
192198
# "stabilization", as well as "HEAD" and "master".
193-
tags = set([r for r in refs if re.search(r'\d', r)])
199+
tags = set([r for r in refs if re.search(r"\d", r)])
194200
if verbose:
195201
print("discarding '%s', no digits" % ",".join(refs - tags))
196202
if verbose:
197203
print("likely tags: %s" % ",".join(sorted(tags)))
198204
for ref in sorted(tags):
199205
# sorting will prefer e.g. "2.0" over "2.0rc1"
200206
if ref.startswith(tag_prefix):
201-
r = ref[len(tag_prefix):]
207+
r = ref[len(tag_prefix) :]
202208
if verbose:
203209
print("picking %s" % r)
204-
return {"version": r,
205-
"full-revisionid": keywords["full"].strip(),
206-
"dirty": False, "error": None,
207-
"date": date}
210+
return {
211+
"version": r,
212+
"full-revisionid": keywords["full"].strip(),
213+
"dirty": False,
214+
"error": None,
215+
"date": date,
216+
}
208217
# no suitable tags, so version is "0+unknown", but full hex is still there
209218
if verbose:
210219
print("no suitable tags, using unknown + full revision id")
211-
return {"version": "0+unknown",
212-
"full-revisionid": keywords["full"].strip(),
213-
"dirty": False, "error": "no suitable tags", "date": None}
220+
return {
221+
"version": "0+unknown",
222+
"full-revisionid": keywords["full"].strip(),
223+
"dirty": False,
224+
"error": "no suitable tags",
225+
"date": None,
226+
}
214227

215228

216229
@register_vcs_handler("git", "pieces_from_vcs")
@@ -225,19 +238,17 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
225238
if sys.platform == "win32":
226239
GITS = ["git.cmd", "git.exe"]
227240

228-
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
229-
hide_stderr=True)
241+
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
230242
if rc != 0:
231243
if verbose:
232244
print("Directory %s not under git control" % root)
233245
raise NotThisMethod("'git rev-parse --git-dir' returned error")
234246

235247
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
236248
# if there isn't one, this yields HEX[-dirty] (no NUM)
237-
describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
238-
"--always", "--long",
239-
"--match", "%s*" % tag_prefix],
240-
cwd=root)
249+
describe_out, rc = run_command(
250+
GITS, ["describe", "--tags", "--dirty", "--always", "--long", "--match", "%s*" % tag_prefix], cwd=root
251+
)
241252
# --long was added in git-1.5.5
242253
if describe_out is None:
243254
raise NotThisMethod("'git describe' failed")
@@ -260,17 +271,16 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
260271
dirty = git_describe.endswith("-dirty")
261272
pieces["dirty"] = dirty
262273
if dirty:
263-
git_describe = git_describe[:git_describe.rindex("-dirty")]
274+
git_describe = git_describe[: git_describe.rindex("-dirty")]
264275

265276
# now we have TAG-NUM-gHEX or HEX
266277

267278
if "-" in git_describe:
268279
# TAG-NUM-gHEX
269-
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
280+
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
270281
if not mo:
271282
# unparseable. Maybe git-describe is misbehaving?
272-
pieces["error"] = ("unable to parse git-describe output: '%s'"
273-
% describe_out)
283+
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
274284
return pieces
275285

276286
# tag
@@ -279,10 +289,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
279289
if verbose:
280290
fmt = "tag '%s' doesn't start with prefix '%s'"
281291
print(fmt % (full_tag, tag_prefix))
282-
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
283-
% (full_tag, tag_prefix))
292+
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (full_tag, tag_prefix)
284293
return pieces
285-
pieces["closest-tag"] = full_tag[len(tag_prefix):]
294+
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
286295

287296
# distance: number of commits since tag
288297
pieces["distance"] = int(mo.group(2))
@@ -293,13 +302,11 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
293302
else:
294303
# HEX: no tags
295304
pieces["closest-tag"] = None
296-
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
297-
cwd=root)
305+
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
298306
pieces["distance"] = int(count_out) # total number of commits
299307

300308
# commit date: see ISO-8601 comment in git_versions_from_keywords()
301-
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
302-
cwd=root)[0].strip()
309+
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip()
303310
pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
304311

305312
return pieces
@@ -330,8 +337,7 @@ def render_pep440(pieces):
330337
rendered += ".dirty"
331338
else:
332339
# exception #1
333-
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
334-
pieces["short"])
340+
rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
335341
if pieces["dirty"]:
336342
rendered += ".dirty"
337343
return rendered
@@ -445,11 +451,13 @@ def render_git_describe_long(pieces):
445451
def render(pieces, style):
446452
"""Render the given version pieces into the requested style."""
447453
if pieces["error"]:
448-
return {"version": "unknown",
449-
"full-revisionid": pieces.get("long"),
450-
"dirty": None,
451-
"error": pieces["error"],
452-
"date": None}
454+
return {
455+
"version": "unknown",
456+
"full-revisionid": pieces.get("long"),
457+
"dirty": None,
458+
"error": pieces["error"],
459+
"date": None,
460+
}
453461

454462
if not style or style == "default":
455463
style = "pep440" # the default
@@ -469,9 +477,13 @@ def render(pieces, style):
469477
else:
470478
raise ValueError("unknown style '%s'" % style)
471479

472-
return {"version": rendered, "full-revisionid": pieces["long"],
473-
"dirty": pieces["dirty"], "error": None,
474-
"date": pieces.get("date")}
480+
return {
481+
"version": rendered,
482+
"full-revisionid": pieces["long"],
483+
"dirty": pieces["dirty"],
484+
"error": None,
485+
"date": pieces.get("date"),
486+
}
475487

476488

477489
def get_versions():
@@ -485,8 +497,7 @@ def get_versions():
485497
verbose = cfg.verbose
486498

487499
try:
488-
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
489-
verbose)
500+
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
490501
except NotThisMethod:
491502
pass
492503

@@ -495,13 +506,16 @@ def get_versions():
495506
# versionfile_source is the relative path from the top of the source
496507
# tree (where the .git directory might live) to this file. Invert
497508
# this to find the root from __file__.
498-
for i in cfg.versionfile_source.split('/'):
509+
for i in cfg.versionfile_source.split("/"):
499510
root = os.path.dirname(root)
500511
except NameError:
501-
return {"version": "0+unknown", "full-revisionid": None,
502-
"dirty": None,
503-
"error": "unable to find root of source tree",
504-
"date": None}
512+
return {
513+
"version": "0+unknown",
514+
"full-revisionid": None,
515+
"dirty": None,
516+
"error": "unable to find root of source tree",
517+
"date": None,
518+
}
505519

506520
try:
507521
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
@@ -515,6 +529,10 @@ def get_versions():
515529
except NotThisMethod:
516530
pass
517531

518-
return {"version": "0+unknown", "full-revisionid": None,
519-
"dirty": None,
520-
"error": "unable to compute version", "date": None}
532+
return {
533+
"version": "0+unknown",
534+
"full-revisionid": None,
535+
"dirty": None,
536+
"error": "unable to compute version",
537+
"date": None,
538+
}

setup.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from os import path
2-
from setuptools import setup, find_packages
31
import sys
4-
import versioneer
2+
from os import path
53

4+
from setuptools import find_packages, setup
5+
6+
import versioneer
67

78
# NOTE: This file must remain Python 2 compatible for the foreseeable future,
89
# to ensure that we error out properly for people with outdated setuptools
@@ -19,39 +20,40 @@
1920
Upgrade pip like so:
2021
2122
pip install --upgrade pip
22-
""".format(*(sys.version_info[:2] + min_version))
23+
""".format(
24+
*(sys.version_info[:2] + min_version)
25+
)
2326
sys.exit(error)
2427

2528
here = path.abspath(path.dirname(__file__))
2629

27-
with open(path.join(here, 'README.rst'), encoding='utf-8') as readme_file:
30+
with open(path.join(here, "README.rst"), encoding="utf-8") as readme_file:
2831
readme = readme_file.read()
2932

30-
with open(path.join(here, 'requirements.txt')) as requirements_file:
33+
with open(path.join(here, "requirements.txt")) as requirements_file:
3134
# Parse requirements.txt, ignoring any commented-out lines.
32-
requirements = [line for line in requirements_file.read().splitlines()
33-
if not line.startswith('#')]
35+
requirements = [line for line in requirements_file.read().splitlines() if not line.startswith("#")]
3436

3537

3638
setup(
37-
name='diffpy.test_data',
39+
name="diffpy.test_data",
3840
version=versioneer.get_version(),
3941
cmdclass=versioneer.get_cmdclass(),
4042
description="Community shared diffraction data for testing data reduction and modeling codes",
4143
long_description=readme,
4244
author="Billinge Group",
43-
author_email='[email protected]',
44-
url='https://github.com/sbillinge/diffpy.test_data',
45-
python_requires='>={}'.format('.'.join(str(n) for n in min_version)),
46-
packages=find_packages(exclude=['docs', 'tests']),
45+
author_email="[email protected]",
46+
url="https://github.com/sbillinge/diffpy.test_data",
47+
python_requires=">={}".format(".".join(str(n) for n in min_version)),
48+
packages=find_packages(exclude=["docs", "tests"]),
4749
entry_points={
48-
'console_scripts': [
50+
"console_scripts": [
4951
# 'command = some.module:some_function',
5052
],
5153
},
5254
include_package_data=True,
5355
package_data={
54-
'diffpy.test_data': [
56+
"diffpy.test_data": [
5557
# When adding files here, remember to update MANIFEST.in as well,
5658
# or else they will not be included in the distribution on PyPI!
5759
# 'path/to/data_file',
@@ -60,8 +62,8 @@
6062
install_requires=requirements,
6163
license="BSD (3-clause)",
6264
classifiers=[
63-
'Development Status :: 2 - Pre-Alpha',
64-
'Natural Language :: English',
65-
'Programming Language :: Python :: 3',
65+
"Development Status :: 2 - Pre-Alpha",
66+
"Natural Language :: English",
67+
"Programming Language :: Python :: 3",
6668
],
6769
)

0 commit comments

Comments
 (0)