Skip to content

Commit a0f7aa7

Browse files
committed
update versioneer script
1 parent 81dd31f commit a0f7aa7

File tree

3 files changed

+238
-198
lines changed

3 files changed

+238
-198
lines changed

pytensor/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from functools import singledispatch
3030
from typing import Any, NoReturn, Optional
3131

32+
from pytensor.version import version as __version__
33+
3234

3335
pytensor_logger = logging.getLogger("pytensor")
3436
logging_default_handler = logging.StreamHandler()
@@ -49,10 +51,6 @@ def disable_log_handler(logger=pytensor_logger, handler=logging_default_handler)
4951
logger.removeHandler(handler)
5052

5153

52-
# Version information.
53-
from pytensor.version import version as __version__
54-
55-
5654
# Raise a meaningful warning/error if the pytensor directory is in the Python
5755
# path.
5856
rpath = os.path.realpath(__path__[0])

pytensor/_version.py

+68-96
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
12
# This file helps to compute a version number in source trees obtained from
23
# git-archive tarball (such as those provided by githubs download-from-tag
34
# feature). Distribution tarballs (built by setup.py sdist) and build
45
# directories (produced by setup.py build) will contain a much shorter file
56
# that just contains the computed version number.
67

7-
# This file is released into the public domain. Generated by
8-
# versioneer-0.23.dev0 (https://github.com/python-versioneer/python-versioneer)
8+
# This file is released into the public domain.
9+
# Generated by versioneer-0.28
10+
# https://github.com/python-versioneer/python-versioneer
911

1012
"""Git implementation of _version.py."""
1113

1214
import errno
13-
import functools
1415
import os
1516
import re
1617
import subprocess
1718
import sys
1819
from typing import Callable, Dict
20+
import functools
1921

2022

2123
def get_keywords():
@@ -59,18 +61,17 @@ class NotThisMethod(Exception):
5961

6062
def register_vcs_handler(vcs, method): # decorator
6163
"""Create decorator to mark a method as the handler of a VCS."""
62-
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
69-
7070
return decorate
7171

7272

73-
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
73+
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
74+
env=None):
7475
"""Call the given command(s)."""
7576
assert isinstance(commands, list)
7677
process = None
@@ -86,14 +87,10 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
8687
try:
8788
dispcmd = str([command] + args)
8889
# remember shell=False, so use git.cmd on windows, not just git
89-
process = subprocess.Popen(
90-
[command] + args,
91-
cwd=cwd,
92-
env=env,
93-
stdout=subprocess.PIPE,
94-
stderr=(subprocess.PIPE if hide_stderr else None),
95-
**popen_kwargs
96-
)
90+
process = subprocess.Popen([command] + args, cwd=cwd, env=env,
91+
stdout=subprocess.PIPE,
92+
stderr=(subprocess.PIPE if hide_stderr
93+
else None), **popen_kwargs)
9794
break
9895
except OSError:
9996
e = sys.exc_info()[1]
@@ -105,7 +102,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
105102
return None, None
106103
else:
107104
if verbose:
108-
print(f"unable to find command, tried {commands}")
105+
print("unable to find command, tried %s" % (commands,))
109106
return None, None
110107
stdout = process.communicate()[0].strip().decode()
111108
if process.returncode != 0:
@@ -128,21 +125,15 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
128125
for _ in range(3):
129126
dirname = os.path.basename(root)
130127
if dirname.startswith(parentdir_prefix):
131-
return {
132-
"version": dirname[len(parentdir_prefix) :],
133-
"full-revisionid": None,
134-
"dirty": False,
135-
"error": None,
136-
"date": None,
137-
}
128+
return {"version": dirname[len(parentdir_prefix):],
129+
"full-revisionid": None,
130+
"dirty": False, "error": None, "date": None}
138131
rootdirs.append(root)
139132
root = os.path.dirname(root) # up a level
140133

141134
if verbose:
142-
print(
143-
"Tried directories %s but none started with prefix %s"
144-
% (str(rootdirs), parentdir_prefix)
145-
)
135+
print("Tried directories %s but none started with prefix %s" %
136+
(str(rootdirs), parentdir_prefix))
146137
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
147138

148139

@@ -155,7 +146,7 @@ def git_get_keywords(versionfile_abs):
155146
# _version.py.
156147
keywords = {}
157148
try:
158-
with open(versionfile_abs) as fobj:
149+
with open(versionfile_abs, "r") as fobj:
159150
for line in fobj:
160151
if line.strip().startswith("git_refnames ="):
161152
mo = re.search(r'=\s*"(.*)"', line)
@@ -201,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
201192
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
202193
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
203194
TAG = "tag: "
204-
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
195+
tags = {r[len(TAG):] for r in refs if r.startswith(TAG)}
205196
if not tags:
206197
# Either we're using git < 1.8.3, or there really are no tags. We use
207198
# a heuristic: assume all version tags have a digit. The old git %d
@@ -210,39 +201,32 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
210201
# between branches and tags. By ignoring refnames without digits, we
211202
# filter out many common branch names like "release" and
212203
# "stabilization", as well as "HEAD" and "master".
213-
tags = {r for r in refs if re.search(r"\d", r)}
204+
tags = {r for r in refs if re.search(r'\d', r)}
214205
if verbose:
215206
print("discarding '%s', no digits" % ",".join(refs - tags))
216207
if verbose:
217208
print("likely tags: %s" % ",".join(sorted(tags)))
218209
for ref in sorted(tags):
219210
# sorting will prefer e.g. "2.0" over "2.0rc1"
220211
if ref.startswith(tag_prefix):
221-
r = ref[len(tag_prefix) :]
212+
r = ref[len(tag_prefix):]
222213
# Filter out refs that exactly match prefix or that don't start
223214
# with a number once the prefix is stripped (mostly a concern
224215
# when prefix is '')
225-
if not re.match(r"\d", r):
216+
if not re.match(r'\d', r):
226217
continue
227218
if verbose:
228219
print("picking %s" % r)
229-
return {
230-
"version": r,
231-
"full-revisionid": keywords["full"].strip(),
232-
"dirty": False,
233-
"error": None,
234-
"date": date,
235-
}
220+
return {"version": r,
221+
"full-revisionid": keywords["full"].strip(),
222+
"dirty": False, "error": None,
223+
"date": date}
236224
# no suitable tags, so version is "0+unknown", but full hex is still there
237225
if verbose:
238226
print("no suitable tags, using unknown + full revision id")
239-
return {
240-
"version": "0+unknown",
241-
"full-revisionid": keywords["full"].strip(),
242-
"dirty": False,
243-
"error": "no suitable tags",
244-
"date": None,
245-
}
227+
return {"version": "0+unknown",
228+
"full-revisionid": keywords["full"].strip(),
229+
"dirty": False, "error": "no suitable tags", "date": None}
246230

247231

248232
@register_vcs_handler("git", "pieces_from_vcs")
@@ -264,21 +248,19 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
264248
env.pop("GIT_DIR", None)
265249
runner = functools.partial(runner, env=env)
266250

267-
_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
251+
_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root,
252+
hide_stderr=not verbose)
268253
if rc != 0:
269254
if verbose:
270255
print("Directory %s not under git control" % root)
271256
raise NotThisMethod("'git rev-parse --git-dir' returned error")
272257

273-
MATCH_ARGS = ["--match", "%s*" % tag_prefix] if tag_prefix else []
274-
275258
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
276259
# if there isn't one, this yields HEX[-dirty] (no NUM)
277-
describe_out, rc = runner(
278-
GITS,
279-
["describe", "--tags", "--dirty", "--always", "--long", *MATCH_ARGS],
280-
cwd=root,
281-
)
260+
describe_out, rc = runner(GITS, [
261+
"describe", "--tags", "--dirty", "--always", "--long",
262+
"--match", f"{tag_prefix}[[:digit:]]*"
263+
], cwd=root)
282264
# --long was added in git-1.5.5
283265
if describe_out is None:
284266
raise NotThisMethod("'git describe' failed")
@@ -293,7 +275,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
293275
pieces["short"] = full_out[:7] # maybe improved later
294276
pieces["error"] = None
295277

296-
branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root)
278+
branch_name, rc = runner(GITS, ["rev-parse", "--abbrev-ref", "HEAD"],
279+
cwd=root)
297280
# --abbrev-ref was added in git-1.6.3
298281
if rc != 0 or branch_name is None:
299282
raise NotThisMethod("'git rev-parse --abbrev-ref' returned error")
@@ -333,16 +316,17 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
333316
dirty = git_describe.endswith("-dirty")
334317
pieces["dirty"] = dirty
335318
if dirty:
336-
git_describe = git_describe[: git_describe.rindex("-dirty")]
319+
git_describe = git_describe[:git_describe.rindex("-dirty")]
337320

338321
# now we have TAG-NUM-gHEX or HEX
339322

340323
if "-" in git_describe:
341324
# TAG-NUM-gHEX
342-
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
325+
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
343326
if not mo:
344327
# unparsable. Maybe git-describe is misbehaving?
345-
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
328+
pieces["error"] = ("unable to parse git-describe output: '%s'"
329+
% describe_out)
346330
return pieces
347331

348332
# tag
@@ -351,12 +335,10 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
351335
if verbose:
352336
fmt = "tag '%s' doesn't start with prefix '%s'"
353337
print(fmt % (full_tag, tag_prefix))
354-
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
355-
full_tag,
356-
tag_prefix,
357-
)
338+
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
339+
% (full_tag, tag_prefix))
358340
return pieces
359-
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
341+
pieces["closest-tag"] = full_tag[len(tag_prefix):]
360342

361343
# distance: number of commits since tag
362344
pieces["distance"] = int(mo.group(2))
@@ -367,8 +349,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
367349
else:
368350
# HEX: no tags
369351
pieces["closest-tag"] = None
370-
count_out, rc = runner(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
371-
pieces["distance"] = int(count_out) # total number of commits
352+
out, rc = runner(GITS, ["rev-list", "HEAD", "--left-right"], cwd=root)
353+
pieces["distance"] = len(out.split()) # total number of commits
372354

373355
# commit date: see ISO-8601 comment in git_versions_from_keywords()
374356
date = runner(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip()
@@ -405,7 +387,8 @@ def render_pep440(pieces):
405387
rendered += ".dirty"
406388
else:
407389
# exception #1
408-
rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
390+
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
391+
pieces["short"])
409392
if pieces["dirty"]:
410393
rendered += ".dirty"
411394
return rendered
@@ -434,7 +417,8 @@ def render_pep440_branch(pieces):
434417
rendered = "0"
435418
if pieces["branch"] != "master":
436419
rendered += ".dev0"
437-
rendered += "+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
420+
rendered += "+untagged.%d.g%s" % (pieces["distance"],
421+
pieces["short"])
438422
if pieces["dirty"]:
439423
rendered += ".dirty"
440424
return rendered
@@ -595,13 +579,11 @@ def render_git_describe_long(pieces):
595579
def render(pieces, style):
596580
"""Render the given version pieces into the requested style."""
597581
if pieces["error"]:
598-
return {
599-
"version": "unknown",
600-
"full-revisionid": pieces.get("long"),
601-
"dirty": None,
602-
"error": pieces["error"],
603-
"date": None,
604-
}
582+
return {"version": "unknown",
583+
"full-revisionid": pieces.get("long"),
584+
"dirty": None,
585+
"error": pieces["error"],
586+
"date": None}
605587

606588
if not style or style == "default":
607589
style = "pep440" # the default
@@ -625,13 +607,9 @@ def render(pieces, style):
625607
else:
626608
raise ValueError("unknown style '%s'" % style)
627609

628-
return {
629-
"version": rendered,
630-
"full-revisionid": pieces["long"],
631-
"dirty": pieces["dirty"],
632-
"error": None,
633-
"date": pieces.get("date"),
634-
}
610+
return {"version": rendered, "full-revisionid": pieces["long"],
611+
"dirty": pieces["dirty"], "error": None,
612+
"date": pieces.get("date")}
635613

636614

637615
def get_versions():
@@ -645,7 +623,8 @@ def get_versions():
645623
verbose = cfg.verbose
646624

647625
try:
648-
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
626+
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
627+
verbose)
649628
except NotThisMethod:
650629
pass
651630

@@ -654,16 +633,13 @@ def get_versions():
654633
# versionfile_source is the relative path from the top of the source
655634
# tree (where the .git directory might live) to this file. Invert
656635
# this to find the root from __file__.
657-
for _ in cfg.versionfile_source.split("/"):
636+
for _ in cfg.versionfile_source.split('/'):
658637
root = os.path.dirname(root)
659638
except NameError:
660-
return {
661-
"version": "0+unknown",
662-
"full-revisionid": None,
663-
"dirty": None,
664-
"error": "unable to find root of source tree",
665-
"date": None,
666-
}
639+
return {"version": "0+unknown", "full-revisionid": None,
640+
"dirty": None,
641+
"error": "unable to find root of source tree",
642+
"date": None}
667643

668644
try:
669645
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
@@ -677,10 +653,6 @@ def get_versions():
677653
except NotThisMethod:
678654
pass
679655

680-
return {
681-
"version": "0+unknown",
682-
"full-revisionid": None,
683-
"dirty": None,
684-
"error": "unable to compute version",
685-
"date": None,
686-
}
656+
return {"version": "0+unknown", "full-revisionid": None,
657+
"dirty": None,
658+
"error": "unable to compute version", "date": None}

0 commit comments

Comments
 (0)