Skip to content

Commit 0dd2c51

Browse files
authored
Merge pull request #4 from diffpy/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2 parents 61e9157 + 3ef1457 commit 0dd2c51

File tree

15 files changed

+761
-466
lines changed

15 files changed

+761
-466
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
default_language_version:
22
python: python3
33
repos:
4-
- repo: https://github.com/ambv/black
5-
rev: stable
4+
- repo: https://github.com/psf/black
5+
rev: 24.4.2
66
hooks:
77
- id: black
88
- repo: https://github.com/pre-commit/pre-commit-hooks
99
rev: v2.0.0
1010
hooks:
1111
- id: flake8
1212
- repo: https://github.com/kynan/nbstripout
13-
rev: 0.3.9
13+
rev: 0.7.1
1414
hooks:
1515
- id: nbstripout

devutils/makesdist

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python
22

3-
'''Create source distribution tar.gz archive, where each file belongs
3+
"""Create source distribution tar.gz archive, where each file belongs
44
to a root user and modification time is set to the git commit time.
5-
'''
5+
"""
66

77
import sys
88
import os
@@ -15,37 +15,43 @@ BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
1515
sys.path.insert(0, BASEDIR)
1616

1717
from setup import versiondata, FALLBACK_VERSION
18-
timestamp = versiondata.getint('DEFAULT', 'timestamp')
1918

20-
vfb = versiondata.get('DEFAULT', 'version').split('.post')[0] + '.post0'
19+
timestamp = versiondata.getint("DEFAULT", "timestamp")
20+
21+
vfb = versiondata.get("DEFAULT", "version").split(".post")[0] + ".post0"
2122
emsg = "Invalid FALLBACK_VERSION. Expected %r got %r."
2223
assert vfb == FALLBACK_VERSION, emsg % (vfb, FALLBACK_VERSION)
2324

25+
2426
def inform(s):
2527
sys.stdout.write(s)
2628
sys.stdout.flush()
2729
return
2830

31+
2932
inform('Run "setup.py sdist --formats=tar" ')
30-
cmd_sdist = [sys.executable] + 'setup.py sdist --formats=tar'.split()
31-
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, 'w'))
32-
if ec: sys.exit(ec)
33+
cmd_sdist = [sys.executable] + "setup.py sdist --formats=tar".split()
34+
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, "w"))
35+
if ec:
36+
sys.exit(ec)
3337
inform("[done]\n")
3438

35-
tarname = max(glob.glob(BASEDIR + '/dist/*.tar'), key=os.path.getmtime)
39+
tarname = max(glob.glob(BASEDIR + "/dist/*.tar"), key=os.path.getmtime)
3640

3741
tfin = tarfile.open(tarname)
38-
fpout = gzip.GzipFile(tarname + '.gz', 'w', mtime=0)
39-
tfout = tarfile.open(fileobj=fpout, mode='w')
42+
fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0)
43+
tfout = tarfile.open(fileobj=fpout, mode="w")
44+
4045

4146
def fixtarinfo(tinfo):
4247
tinfo.uid = tinfo.gid = 0
43-
tinfo.uname = tinfo.gname = 'root'
48+
tinfo.uname = tinfo.gname = "root"
4449
tinfo.mtime = timestamp
4550
tinfo.mode &= ~0o022
4651
return tinfo
4752

48-
inform('Filter %s --> %s.gz ' % (2 * (os.path.basename(tarname),)))
53+
54+
inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),)))
4955
for ti in tfin:
5056
tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti))
5157

fourigui/__init__.py

Lines changed: 2 additions & 2 deletions
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

fourigui/_version.py

Lines changed: 95 additions & 59 deletions
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,22 @@ 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(
135+
"Tried directories %s but none started with prefix %s"
136+
% (str(rootdirs), parentdir_prefix)
137+
)
129138
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
130139

131140

@@ -181,7 +190,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
181190
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
182191
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
183192
TAG = "tag: "
184-
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
193+
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
185194
if not tags:
186195
# Either we're using git < 1.8.3, or there really are no tags. We use
187196
# a heuristic: assume all version tags have a digit. The old git %d
@@ -190,27 +199,34 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
190199
# between branches and tags. By ignoring refnames without digits, we
191200
# filter out many common branch names like "release" and
192201
# "stabilization", as well as "HEAD" and "master".
193-
tags = set([r for r in refs if re.search(r'\d', r)])
202+
tags = set([r for r in refs if re.search(r"\d", r)])
194203
if verbose:
195204
print("discarding '%s', no digits" % ",".join(refs - tags))
196205
if verbose:
197206
print("likely tags: %s" % ",".join(sorted(tags)))
198207
for ref in sorted(tags):
199208
# sorting will prefer e.g. "2.0" over "2.0rc1"
200209
if ref.startswith(tag_prefix):
201-
r = ref[len(tag_prefix):]
210+
r = ref[len(tag_prefix) :]
202211
if verbose:
203212
print("picking %s" % r)
204-
return {"version": r,
205-
"full-revisionid": keywords["full"].strip(),
206-
"dirty": False, "error": None,
207-
"date": date}
213+
return {
214+
"version": r,
215+
"full-revisionid": keywords["full"].strip(),
216+
"dirty": False,
217+
"error": None,
218+
"date": date,
219+
}
208220
# no suitable tags, so version is "0+unknown", but full hex is still there
209221
if verbose:
210222
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}
223+
return {
224+
"version": "0+unknown",
225+
"full-revisionid": keywords["full"].strip(),
226+
"dirty": False,
227+
"error": "no suitable tags",
228+
"date": None,
229+
}
214230

215231

216232
@register_vcs_handler("git", "pieces_from_vcs")
@@ -225,19 +241,27 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
225241
if sys.platform == "win32":
226242
GITS = ["git.cmd", "git.exe"]
227243

228-
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
229-
hide_stderr=True)
244+
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
230245
if rc != 0:
231246
if verbose:
232247
print("Directory %s not under git control" % root)
233248
raise NotThisMethod("'git rev-parse --git-dir' returned error")
234249

235250
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
236251
# 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)
252+
describe_out, rc = run_command(
253+
GITS,
254+
[
255+
"describe",
256+
"--tags",
257+
"--dirty",
258+
"--always",
259+
"--long",
260+
"--match",
261+
"%s*" % tag_prefix,
262+
],
263+
cwd=root,
264+
)
241265
# --long was added in git-1.5.5
242266
if describe_out is None:
243267
raise NotThisMethod("'git describe' failed")
@@ -260,17 +284,16 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
260284
dirty = git_describe.endswith("-dirty")
261285
pieces["dirty"] = dirty
262286
if dirty:
263-
git_describe = git_describe[:git_describe.rindex("-dirty")]
287+
git_describe = git_describe[: git_describe.rindex("-dirty")]
264288

265289
# now we have TAG-NUM-gHEX or HEX
266290

267291
if "-" in git_describe:
268292
# TAG-NUM-gHEX
269-
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
293+
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
270294
if not mo:
271295
# unparseable. Maybe git-describe is misbehaving?
272-
pieces["error"] = ("unable to parse git-describe output: '%s'"
273-
% describe_out)
296+
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
274297
return pieces
275298

276299
# tag
@@ -279,10 +302,12 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
279302
if verbose:
280303
fmt = "tag '%s' doesn't start with prefix '%s'"
281304
print(fmt % (full_tag, tag_prefix))
282-
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
283-
% (full_tag, tag_prefix))
305+
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
306+
full_tag,
307+
tag_prefix,
308+
)
284309
return pieces
285-
pieces["closest-tag"] = full_tag[len(tag_prefix):]
310+
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
286311

287312
# distance: number of commits since tag
288313
pieces["distance"] = int(mo.group(2))
@@ -293,13 +318,13 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
293318
else:
294319
# HEX: no tags
295320
pieces["closest-tag"] = None
296-
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
297-
cwd=root)
321+
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
298322
pieces["distance"] = int(count_out) # total number of commits
299323

300324
# 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()
325+
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[
326+
0
327+
].strip()
303328
pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
304329

305330
return pieces
@@ -330,8 +355,7 @@ def render_pep440(pieces):
330355
rendered += ".dirty"
331356
else:
332357
# exception #1
333-
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
334-
pieces["short"])
358+
rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
335359
if pieces["dirty"]:
336360
rendered += ".dirty"
337361
return rendered
@@ -445,11 +469,13 @@ def render_git_describe_long(pieces):
445469
def render(pieces, style):
446470
"""Render the given version pieces into the requested style."""
447471
if pieces["error"]:
448-
return {"version": "unknown",
449-
"full-revisionid": pieces.get("long"),
450-
"dirty": None,
451-
"error": pieces["error"],
452-
"date": None}
472+
return {
473+
"version": "unknown",
474+
"full-revisionid": pieces.get("long"),
475+
"dirty": None,
476+
"error": pieces["error"],
477+
"date": None,
478+
}
453479

454480
if not style or style == "default":
455481
style = "pep440" # the default
@@ -469,9 +495,13 @@ def render(pieces, style):
469495
else:
470496
raise ValueError("unknown style '%s'" % style)
471497

472-
return {"version": rendered, "full-revisionid": pieces["long"],
473-
"dirty": pieces["dirty"], "error": None,
474-
"date": pieces.get("date")}
498+
return {
499+
"version": rendered,
500+
"full-revisionid": pieces["long"],
501+
"dirty": pieces["dirty"],
502+
"error": None,
503+
"date": pieces.get("date"),
504+
}
475505

476506

477507
def get_versions():
@@ -485,8 +515,7 @@ def get_versions():
485515
verbose = cfg.verbose
486516

487517
try:
488-
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
489-
verbose)
518+
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
490519
except NotThisMethod:
491520
pass
492521

@@ -495,13 +524,16 @@ def get_versions():
495524
# versionfile_source is the relative path from the top of the source
496525
# tree (where the .git directory might live) to this file. Invert
497526
# this to find the root from __file__.
498-
for i in cfg.versionfile_source.split('/'):
527+
for i in cfg.versionfile_source.split("/"):
499528
root = os.path.dirname(root)
500529
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}
530+
return {
531+
"version": "0+unknown",
532+
"full-revisionid": None,
533+
"dirty": None,
534+
"error": "unable to find root of source tree",
535+
"date": None,
536+
}
505537

506538
try:
507539
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
@@ -515,6 +547,10 @@ def get_versions():
515547
except NotThisMethod:
516548
pass
517549

518-
return {"version": "0+unknown", "full-revisionid": None,
519-
"dirty": None,
520-
"error": "unable to compute version", "date": None}
550+
return {
551+
"version": "0+unknown",
552+
"full-revisionid": None,
553+
"dirty": None,
554+
"error": "unable to compute version",
555+
"date": None,
556+
}

0 commit comments

Comments
 (0)