Skip to content

Commit 00ff89d

Browse files
Chris Fonnesbecktwiecki
Chris Fonnesbeck
authored andcommitted
Ensuring pre-commit checks pass
1 parent f3f9ece commit 00ff89d

File tree

5 files changed

+280
-196
lines changed

5 files changed

+280
-196
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ repos:
5252
- id: pylint
5353
args: [--rcfile=.pylintrc]
5454
files: ^pymc/
55+
exclude: (?x)(pymc/_version.py)
5556
- repo: https://github.com/MarcoGorelli/madforhooks
5657
rev: 0.3.0
5758
hooks:
5859
- id: no-print-statements
5960
files: ^pymc/
61+
exclude: (?x)(pymc/_version.py)
6062
- repo: local
6163
hooks:
6264
- id: check-no-tests-are-ignored
@@ -77,6 +79,7 @@ repos:
7779
entry: from \.[\.\w]* import
7880
types: [python]
7981
language: pygrep
82+
exclude: (?x)(pymc/_version.py|versioneer.py)
8083
- id: no-internal-links
8184
name: Check no links that should be cross-references are in the docs
8285
description: >-

pymc/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __set_compiler_flags():
4646

4747
__set_compiler_flags()
4848

49-
from pymc import gp, ode, sampling
49+
from pymc import _version, gp, ode, sampling
5050
from pymc.aesaraf import *
5151
from pymc.backends import *
5252
from pymc.blocking import *
@@ -75,5 +75,4 @@ def __set_compiler_flags():
7575
from pymc.variational import *
7676
from pymc.vartypes import *
7777

78-
from . import _version
79-
__version__ = _version.get_versions()['version']
78+
__version__ = _version.get_versions()["version"]

pymc/_version.py

Lines changed: 96 additions & 63 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
@@ -11,12 +10,13 @@
1110
"""Git implementation of _version.py."""
1211

1312
import errno
13+
import functools
1414
import os
1515
import re
1616
import subprocess
1717
import sys
18+
1819
from typing import Callable, Dict
19-
import functools
2020

2121

2222
def get_keywords():
@@ -60,17 +60,18 @@ class NotThisMethod(Exception):
6060

6161
def register_vcs_handler(vcs, method): # decorator
6262
"""Create decorator to mark a method as the handler of a VCS."""
63+
6364
def decorate(f):
6465
"""Store f in HANDLERS[vcs][method]."""
6566
if vcs not in HANDLERS:
6667
HANDLERS[vcs] = {}
6768
HANDLERS[vcs][method] = f
6869
return f
70+
6971
return decorate
7072

7173

72-
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
73-
env=None):
74+
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
7475
"""Call the given command(s)."""
7576
assert isinstance(commands, list)
7677
process = None
@@ -86,10 +87,14 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
8687
try:
8788
dispcmd = str([command] + args)
8889
# remember shell=False, so use git.cmd on windows, not just git
89-
process = subprocess.Popen([command] + args, cwd=cwd, env=env,
90-
stdout=subprocess.PIPE,
91-
stderr=(subprocess.PIPE if hide_stderr
92-
else None), **popen_kwargs)
90+
process = subprocess.Popen(
91+
[command] + args,
92+
cwd=cwd,
93+
env=env,
94+
stdout=subprocess.PIPE,
95+
stderr=(subprocess.PIPE if hide_stderr else None),
96+
**popen_kwargs,
97+
)
9398
break
9499
except OSError:
95100
e = sys.exc_info()[1]
@@ -101,7 +106,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
101106
return None, None
102107
else:
103108
if verbose:
104-
print("unable to find command, tried %s" % (commands,))
109+
print(f"unable to find command, tried {commands}")
105110
return None, None
106111
stdout = process.communicate()[0].strip().decode()
107112
if process.returncode != 0:
@@ -124,15 +129,21 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
124129
for _ in range(3):
125130
dirname = os.path.basename(root)
126131
if dirname.startswith(parentdir_prefix):
127-
return {"version": dirname[len(parentdir_prefix):],
128-
"full-revisionid": None,
129-
"dirty": False, "error": None, "date": None}
132+
return {
133+
"version": dirname[len(parentdir_prefix) :],
134+
"full-revisionid": None,
135+
"dirty": False,
136+
"error": None,
137+
"date": None,
138+
}
130139
rootdirs.append(root)
131140
root = os.path.dirname(root) # up a level
132141

133142
if verbose:
134-
print("Tried directories %s but none started with prefix %s" %
135-
(str(rootdirs), parentdir_prefix))
143+
print(
144+
"Tried directories %s but none started with prefix %s"
145+
% (str(rootdirs), parentdir_prefix)
146+
)
136147
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
137148

138149

@@ -145,7 +156,7 @@ def git_get_keywords(versionfile_abs):
145156
# _version.py.
146157
keywords = {}
147158
try:
148-
with open(versionfile_abs, "r") as fobj:
159+
with open(versionfile_abs) as fobj:
149160
for line in fobj:
150161
if line.strip().startswith("git_refnames ="):
151162
mo = re.search(r'=\s*"(.*)"', line)
@@ -191,7 +202,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
191202
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
192203
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
193204
TAG = "tag: "
194-
tags = {r[len(TAG):] for r in refs if r.startswith(TAG)}
205+
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
195206
if not tags:
196207
# Either we're using git < 1.8.3, or there really are no tags. We use
197208
# a heuristic: assume all version tags have a digit. The old git %d
@@ -200,32 +211,39 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
200211
# between branches and tags. By ignoring refnames without digits, we
201212
# filter out many common branch names like "release" and
202213
# "stabilization", as well as "HEAD" and "master".
203-
tags = {r for r in refs if re.search(r'\d', r)}
214+
tags = {r for r in refs if re.search(r"\d", r)}
204215
if verbose:
205216
print("discarding '%s', no digits" % ",".join(refs - tags))
206217
if verbose:
207218
print("likely tags: %s" % ",".join(sorted(tags)))
208219
for ref in sorted(tags):
209220
# sorting will prefer e.g. "2.0" over "2.0rc1"
210221
if ref.startswith(tag_prefix):
211-
r = ref[len(tag_prefix):]
222+
r = ref[len(tag_prefix) :]
212223
# Filter out refs that exactly match prefix or that don't start
213224
# with a number once the prefix is stripped (mostly a concern
214225
# when prefix is '')
215-
if not re.match(r'\d', r):
226+
if not re.match(r"\d", r):
216227
continue
217228
if verbose:
218229
print("picking %s" % r)
219-
return {"version": r,
220-
"full-revisionid": keywords["full"].strip(),
221-
"dirty": False, "error": None,
222-
"date": date}
230+
return {
231+
"version": r,
232+
"full-revisionid": keywords["full"].strip(),
233+
"dirty": False,
234+
"error": None,
235+
"date": date,
236+
}
223237
# no suitable tags, so version is "0+unknown", but full hex is still there
224238
if verbose:
225239
print("no suitable tags, using unknown + full revision id")
226-
return {"version": "0+unknown",
227-
"full-revisionid": keywords["full"].strip(),
228-
"dirty": False, "error": "no suitable tags", "date": None}
240+
return {
241+
"version": "0+unknown",
242+
"full-revisionid": keywords["full"].strip(),
243+
"dirty": False,
244+
"error": "no suitable tags",
245+
"date": None,
246+
}
229247

230248

231249
@register_vcs_handler("git", "pieces_from_vcs")
@@ -247,19 +265,27 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
247265
env.pop("GIT_DIR", None)
248266
runner = functools.partial(runner, env=env)
249267

250-
_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root,
251-
hide_stderr=True)
268+
_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
252269
if rc != 0:
253270
if verbose:
254271
print("Directory %s not under git control" % root)
255272
raise NotThisMethod("'git rev-parse --git-dir' returned error")
256273

257274
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
258275
# if there isn't one, this yields HEX[-dirty] (no NUM)
259-
describe_out, rc = runner(GITS, [
260-
"describe", "--tags", "--dirty", "--always", "--long",
261-
"--match", f"{tag_prefix}[[:digit:]]*"
262-
], cwd=root)
276+
describe_out, rc = runner(
277+
GITS,
278+
[
279+
"describe",
280+
"--tags",
281+
"--dirty",
282+
"--always",
283+
"--long",
284+
"--match",
285+
f"{tag_prefix}[[:digit:]]*",
286+
],
287+
cwd=root,
288+
)
263289
# --long was added in git-1.5.5
264290
if describe_out is None:
265291
raise NotThisMethod("'git describe' failed")
@@ -274,8 +300,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
274300
pieces["short"] = full_out[:7] # maybe improved later
275301
pieces["error"] = None
276302

277-
branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"],
278-
cwd=root)
303+
branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root)
279304
# --abbrev-ref was added in git-1.6.3
280305
if rc != 0 or branch_name is None:
281306
raise NotThisMethod("'git rev-parse --abbrev-ref' returned error")
@@ -315,17 +340,16 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
315340
dirty = git_describe.endswith("-dirty")
316341
pieces["dirty"] = dirty
317342
if dirty:
318-
git_describe = git_describe[:git_describe.rindex("-dirty")]
343+
git_describe = git_describe[: git_describe.rindex("-dirty")]
319344

320345
# now we have TAG-NUM-gHEX or HEX
321346

322347
if "-" in git_describe:
323348
# TAG-NUM-gHEX
324-
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
349+
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
325350
if not mo:
326351
# unparsable. Maybe git-describe is misbehaving?
327-
pieces["error"] = ("unable to parse git-describe output: '%s'"
328-
% describe_out)
352+
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
329353
return pieces
330354

331355
# tag
@@ -334,10 +358,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
334358
if verbose:
335359
fmt = "tag '%s' doesn't start with prefix '%s'"
336360
print(fmt % (full_tag, tag_prefix))
337-
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
338-
% (full_tag, tag_prefix))
361+
pieces["error"] = f"tag '{full_tag}' doesn't start with prefix '{tag_prefix}'"
339362
return pieces
340-
pieces["closest-tag"] = full_tag[len(tag_prefix):]
363+
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
341364

342365
# distance: number of commits since tag
343366
pieces["distance"] = int(mo.group(2))
@@ -386,8 +409,7 @@ def render_pep440(pieces):
386409
rendered += ".dirty"
387410
else:
388411
# exception #1
389-
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
390-
pieces["short"])
412+
rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
391413
if pieces["dirty"]:
392414
rendered += ".dirty"
393415
return rendered
@@ -416,8 +438,7 @@ def render_pep440_branch(pieces):
416438
rendered = "0"
417439
if pieces["branch"] != "master":
418440
rendered += ".dev0"
419-
rendered += "+untagged.%d.g%s" % (pieces["distance"],
420-
pieces["short"])
441+
rendered += "+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
421442
if pieces["dirty"]:
422443
rendered += ".dirty"
423444
return rendered
@@ -578,11 +599,13 @@ def render_git_describe_long(pieces):
578599
def render(pieces, style):
579600
"""Render the given version pieces into the requested style."""
580601
if pieces["error"]:
581-
return {"version": "unknown",
582-
"full-revisionid": pieces.get("long"),
583-
"dirty": None,
584-
"error": pieces["error"],
585-
"date": None}
602+
return {
603+
"version": "unknown",
604+
"full-revisionid": pieces.get("long"),
605+
"dirty": None,
606+
"error": pieces["error"],
607+
"date": None,
608+
}
586609

587610
if not style or style == "default":
588611
style = "pep440" # the default
@@ -606,9 +629,13 @@ def render(pieces, style):
606629
else:
607630
raise ValueError("unknown style '%s'" % style)
608631

609-
return {"version": rendered, "full-revisionid": pieces["long"],
610-
"dirty": pieces["dirty"], "error": None,
611-
"date": pieces.get("date")}
632+
return {
633+
"version": rendered,
634+
"full-revisionid": pieces["long"],
635+
"dirty": pieces["dirty"],
636+
"error": None,
637+
"date": pieces.get("date"),
638+
}
612639

613640

614641
def get_versions():
@@ -622,8 +649,7 @@ def get_versions():
622649
verbose = cfg.verbose
623650

624651
try:
625-
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
626-
verbose)
652+
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
627653
except NotThisMethod:
628654
pass
629655

@@ -632,13 +658,16 @@ def get_versions():
632658
# versionfile_source is the relative path from the top of the source
633659
# tree (where the .git directory might live) to this file. Invert
634660
# this to find the root from __file__.
635-
for _ in cfg.versionfile_source.split('/'):
661+
for _ in cfg.versionfile_source.split("/"):
636662
root = os.path.dirname(root)
637663
except NameError:
638-
return {"version": "0+unknown", "full-revisionid": None,
639-
"dirty": None,
640-
"error": "unable to find root of source tree",
641-
"date": None}
664+
return {
665+
"version": "0+unknown",
666+
"full-revisionid": None,
667+
"dirty": None,
668+
"error": "unable to find root of source tree",
669+
"date": None,
670+
}
642671

643672
try:
644673
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
@@ -652,6 +681,10 @@ def get_versions():
652681
except NotThisMethod:
653682
pass
654683

655-
return {"version": "0+unknown", "full-revisionid": None,
656-
"dirty": None,
657-
"error": "unable to compute version", "date": None}
684+
return {
685+
"version": "0+unknown",
686+
"full-revisionid": None,
687+
"dirty": None,
688+
"error": "unable to compute version",
689+
"date": None,
690+
}

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from os.path import dirname, join, realpath
1919

2020
from setuptools import find_packages, setup
21+
2122
import versioneer
2223

2324
DESCRIPTION = "Probabilistic Programming in Python: Bayesian Modeling and Probabilistic Machine Learning with Aesara"

0 commit comments

Comments
 (0)