Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def get_vcs_list():
def generate_long_version_py(VCS):
s = io.StringIO()
s.write(get(f"src/{VCS}/long_header.py", add_ver=True, do_strip=True))
for piece in ["src/subprocess_helper.py",
for piece in ("src/subprocess_helper.py",
"src/from_parentdir.py",
f"src/{VCS}/from_keywords.py",
f"src/{VCS}/from_vcs.py",
"src/render.py",
f"src/{VCS}/long_get_versions.py"]:
f"src/{VCS}/long_get_versions.py"):
s.write(get(piece, unquote=True, do_strip=True))
return s.getvalue()

Expand Down
20 changes: 10 additions & 10 deletions src/cmdclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def finalize_options(self):

def run(self):
vers = get_versions(verbose=True)
print("Version: %s" % vers["version"])
print(" full-revisionid: %s" % vers.get("full-revisionid"))
print(" dirty: %s" % vers.get("dirty"))
print(" date: %s" % vers.get("date"))
print("Version: {}".format(vers["version"]))
print(" full-revisionid: {}".format(vers.get("full-revisionid")))
print(" dirty: {}".format(vers.get("dirty")))
print(" date: {}".format(vers.get("date")))
if vers["error"]:
print(" error: %s" % vers["error"])
print(" error: {}".format(vers["error"]))
cmds["version"] = cmd_version

# we override "build_py" in setuptools
Expand Down Expand Up @@ -93,7 +93,7 @@ def run(self):
if cfg.versionfile_build:
target_versionfile = os.path.join(self.build_lib,
cfg.versionfile_build)
print("UPDATING %s" % target_versionfile)
print(f"UPDATING {target_versionfile}")
write_to_version_file(target_versionfile, versions)
cmds["build_py"] = cmd_build_py

Expand Down Expand Up @@ -125,7 +125,7 @@ def run(self):
"version update. This can happen if you are running build_ext "
"without first running build_py.")
return
print("UPDATING %s" % target_versionfile)
print(f"UPDATING {target_versionfile}")
write_to_version_file(target_versionfile, versions)
cmds["build_ext"] = cmd_build_ext

Expand All @@ -144,7 +144,7 @@ def run(self):
cfg = get_config_from_root(root)
versions = get_versions()
target_versionfile = cfg.versionfile_source
print("UPDATING %s" % target_versionfile)
print(f"UPDATING {target_versionfile}")
write_to_version_file(target_versionfile, versions)

_build_exe.run(self)
Expand Down Expand Up @@ -173,7 +173,7 @@ def run(self):
cfg = get_config_from_root(root)
versions = get_versions()
target_versionfile = cfg.versionfile_source
print("UPDATING %s" % target_versionfile)
print(f"UPDATING {target_versionfile}")
write_to_version_file(target_versionfile, versions)

_py2exe.run(self)
Expand Down Expand Up @@ -249,7 +249,7 @@ def make_release_tree(self, base_dir, files):
# (remembering that it may be a hardlink) and replace it with an
# updated value
target_versionfile = os.path.join(base_dir, cfg.versionfile_source)
print("UPDATING %s" % target_versionfile)
print(f"UPDATING {target_versionfile}")
write_to_version_file(target_versionfile,
self._versioneer_generated_versions)
cmds["sdist"] = cmd_sdist
Expand Down
6 changes: 3 additions & 3 deletions src/from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json

version_json = '''
%s
{}
''' # END VERSION_JSON


Expand Down Expand Up @@ -41,7 +41,7 @@ def write_to_version_file(filename, versions):
contents = json.dumps(versions, sort_keys=True,
indent=1, separators=(",", ": "))
with open(filename, "w") as f:
f.write(SHORT_VERSION_PY % contents)
f.write(SHORT_VERSION_PY.format(contents))

print("set %s to '%s'" % (filename, versions["version"]))
print("set {} to '{}'".format(filename, versions["version"]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use an f-string if we're here.

Suggested change
print("set {} to '{}'".format(filename, versions["version"]))
print(f"set {filename} to {versions['version']:r}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we're modifying functionality, by changing '%s' to {...} instead of '{...}', aren't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I suspect you meant !r instead of :r. It will call repr(), but then how is that helpful?

>>> i = 2
>>> 
>>> f"We print 'i' as '{i}'"
"We print 'i' as '2'"
>>> 
>>> f"We print 'i' as {i!r}"
"We print 'i' as 2"
>>> 

We might use triple quotes instead:

f"""set {filename} to '{versions["version"]}'"""

But then it gets unreadable.


4 changes: 2 additions & 2 deletions src/from_parentdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
root = os.path.dirname(root) # up a level

if verbose:
print("Tried directories %s but none started with prefix %s" %
(str(rootdirs), parentdir_prefix))
print(f"Tried directories {str(rootdirs)} "
f"but none started with prefix {parentdir_prefix}")
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")


10 changes: 5 additions & 5 deletions src/get_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_versions(verbose=False):

assert cfg.VCS is not None, "please set [versioneer]VCS= in setup.cfg"
handlers = HANDLERS.get(cfg.VCS)
assert handlers, "unrecognized VCS '%s'" % cfg.VCS
assert handlers, f"unrecognized VCS '{cfg.VCS}'"
verbose = verbose or cfg.verbose
assert cfg.versionfile_source is not None, \
"please set versioneer.versionfile_source"
Expand All @@ -46,15 +46,15 @@ def get_versions(verbose=False):
keywords = get_keywords_f(versionfile_abs)
ver = from_keywords_f(keywords, cfg.tag_prefix, verbose)
if verbose:
print("got version from expanded keyword %s" % ver)
print(f"got version from expanded keyword {ver}")
return ver
except NotThisMethod:
pass

try:
ver = versions_from_file(versionfile_abs)
if verbose:
print("got version from file %s %s" % (versionfile_abs, ver))
print(f"got version from file {versionfile_abs} {ver}")
return ver
except NotThisMethod:
pass
Expand All @@ -65,7 +65,7 @@ def get_versions(verbose=False):
pieces = from_vcs_f(cfg.tag_prefix, root, verbose)
ver = render(pieces, cfg.style)
if verbose:
print("got version from VCS %s" % ver)
print(f"got version from VCS {ver}")
return ver
except NotThisMethod:
pass
Expand All @@ -74,7 +74,7 @@ def get_versions(verbose=False):
if cfg.parentdir_prefix:
ver = versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
if verbose:
print("got version from parentdir %s" % ver)
print(f"got version from parentdir {ver}")
return ver
except NotThisMethod:
pass
Expand Down
8 changes: 5 additions & 3 deletions src/git/from_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# "stabilization", as well as "HEAD" and "master".
tags = {r for r in refs if re.search(r'\d', r)}
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
discarded_tags = ",".join(sorted(refs - tags))
print(f"discarding '{discarded_tags}', no digits")
if verbose:
print("likely tags: %s" % ",".join(sorted(tags)))
likely_tags = ",".join(sorted(tags))
print(f"likely tags: {likely_tags}")
for ref in sorted(tags):
# sorting will prefer e.g. "2.0" over "2.0rc1"
if ref.startswith(tag_prefix):
Expand All @@ -83,7 +85,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
if not re.match(r'\d', r):
continue
if verbose:
print("picking %s" % r)
print(f"picking {r}")
return {"version": r,
"full-revisionid": keywords["full"].strip(),
"dirty": False, "error": None,
Expand Down
12 changes: 5 additions & 7 deletions src/git/from_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
hide_stderr=not verbose)
if rc != 0:
if verbose:
print("Directory %s not under git control" % root)
print(f"Directory {root} not under git control")
raise NotThisMethod("'git rev-parse --git-dir' returned error")

# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
Expand Down Expand Up @@ -111,18 +111,16 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
if not mo:
# unparsable. Maybe git-describe is misbehaving?
pieces["error"] = ("unable to parse git-describe output: '%s'"
% describe_out)
pieces["error"] = f"unable to parse git-describe output: '{describe_out}'"
return pieces

# tag
full_tag = mo.group(1)
if not full_tag.startswith(tag_prefix):
error = f"tag '{full_tag}' doesn't start with prefix '{tag_prefix}'"
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
% (full_tag, tag_prefix))
print(error)
pieces["error"] = error
return pieces
pieces["closest-tag"] = full_tag[len(tag_prefix):]

Expand Down
4 changes: 2 additions & 2 deletions src/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def get_root():
me_dir = os.path.normcase(os.path.splitext(my_path)[0])
vsr_dir = os.path.normcase(os.path.splitext(versioneer_py)[0])
if me_dir != vsr_dir and "VERSIONEER_PEP518" not in globals():
print("Warning: build in %s is using versioneer.py from %s"
% (os.path.dirname(my_path), versioneer_py))
print(f"Warning: build in {os.path.dirname(my_path)} "
f"is using versioneer.py from {versioneer_py}")
except NameError:
pass
return root
Expand Down
2 changes: 1 addition & 1 deletion src/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def main():
mode = "--vendor" if len(sys.argv) == 2 else sys.argv[2]

if command in ("version", "--version"):
print("versioneer (installer) %s" % newver)
print(f"versioneer (installer) {newver}")
sys.exit(0)
elif command in ("help", "-help", "--help"):
print(usage)
Expand Down
10 changes: 5 additions & 5 deletions src/setupfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def do_setup():
print(CONFIG_ERROR, file=sys.stderr)
return 1

print(" creating %s" % cfg.versionfile_source)
print(f" creating {cfg.versionfile_source}")
with open(cfg.versionfile_source, "w") as f:
LONG = LONG_VERSION_PY[cfg.VCS]
f.write(LONG % {"DOLLAR": "$",
Expand All @@ -91,17 +91,17 @@ def do_setup():
module = os.path.splitext(os.path.basename(cfg.versionfile_source))[0]
snippet = INIT_PY_SNIPPET.format(module)
if OLD_SNIPPET in old:
print(" replacing boilerplate in %s" % ipy)
print(f" replacing boilerplate in {ipy}")
with open(ipy, "w") as f:
f.write(old.replace(OLD_SNIPPET, snippet))
elif snippet not in old:
print(" appending to %s" % ipy)
print(f" appending to {ipy}")
with open(ipy, "a") as f:
f.write(snippet)
else:
print(" %s unmodified" % ipy)
print(f" {ipy} unmodified")
else:
print(" %s doesn't exist, ok" % ipy)
print(f" {ipy} doesn't exist, ok")
ipy = None

# Make VCS-specific changes. For git, this means creating/changing
Expand Down
8 changes: 4 additions & 4 deletions src/subprocess_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
if e.errno == errno.ENOENT:
continue
if verbose:
print("unable to run %s" % dispcmd)
print(f"unable to run {dispcmd}")
print(e)
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
print(f"unable to find command, tried {commands}")
return None, None
stdout = process.communicate()[0].strip().decode()
if process.returncode != 0:
if verbose:
print("unable to run %s (error)" % dispcmd)
print("stdout was %s" % stdout)
print(f"unable to run {dispcmd} (error)")
print(f"stdout was {stdout}")
return None, process.returncode
return stdout, process.returncode

Expand Down
1 change: 0 additions & 1 deletion test/demoapp-pyproject/src/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion test/demoapp-script-only/fake.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion test/demoapp/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from setuptools import setup
import versioneer
commands = versioneer.get_cmdclass().copy()
Expand Down
1 change: 0 additions & 1 deletion test/demoapp/src/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion test/demoapp2-setuptools-subproject/subproject/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from setuptools import setup
import versioneer
commands = versioneer.get_cmdclass().copy()
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from demolib import __version__ as libversion

def run(*args, **kwargs):
print("__version__:%s" % demo.__version__)
print("_version:%s" % str(_version))
print(f"__version__:{demo.__version__}")
print(f"_version:{str(_version)}")
versions = _version.get_versions()
for k in sorted(versions.keys()):
print("%s:%s" % (k,versions[k]))
print("demolib:%s" % libversion)
print(f"{k}:{versions[k]}")
print(f"demolib:{libversion}")
1 change: 0 additions & 1 deletion test/demoapp2-setuptools/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from setuptools import setup
import versioneer
commands = versioneer.get_cmdclass().copy()
Expand Down
1 change: 0 additions & 1 deletion test/demoapp2-setuptools/src/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

8 changes: 4 additions & 4 deletions test/demoapp2-setuptools/src/demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from demolib import __version__ as libversion

def run(*args, **kwargs):
print("__version__:%s" % demo.__version__)
print("_version:%s" % str(_version))
print(f"__version__:{demo.__version__}")
print(f"_version:{str(_version)}")
versions = _version.get_versions()
for k in sorted(versions.keys()):
print("%s:%s" % (k,versions[k]))
print("demolib:%s" % libversion)
print(f"{k}:{versions[k]}")
print(f"demolib:{libversion}")
1 change: 0 additions & 1 deletion test/demoappext-setuptools/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

8 changes: 4 additions & 4 deletions test/demoappext-setuptools/demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from demolib import __version__ as libversion

def run(*args, **kwargs):
print("__version__:%s" % demo.__version__)
print("_version:%s" % str(_version))
print(f"__version__:{demo.__version__}")
print(f"_version:{str(_version)}")
versions = _version.get_versions()
for k in sorted(versions.keys()):
print("%s:%s" % (k,versions[k]))
print("demolib:%s" % libversion)
print(f"{k}:{versions[k]}")
print(f"demolib:{libversion}")
1 change: 0 additions & 1 deletion test/demoappext-setuptools/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from setuptools import setup, Extension
import versioneer
commands = versioneer.get_cmdclass().copy()
Expand Down
1 change: 0 additions & 1 deletion test/demolib/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from setuptools import setup
import versioneer
commands = versioneer.get_cmdclass().copy()
Expand Down
1 change: 0 additions & 1 deletion test/demolib/src/demolib/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

4 changes: 2 additions & 2 deletions test/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ def test_date_gpg(self):
class RenderPieces(unittest.TestCase):
def do_render(self, pieces):
out = {}
for style in ["pep440", "pep440-branch", "pep440-pre", "pep440-post",
for style in ("pep440", "pep440-branch", "pep440-pre", "pep440-post",
"pep440-post-branch", "pep440-old", "git-describe",
"git-describe-long"]:
"git-describe-long"):
out[style] = render(pieces, style)["version"]
DEFAULT = "pep440"
self.assertEqual(render(pieces, ""), render(pieces, DEFAULT))
Expand Down
4 changes: 2 additions & 2 deletions test/run_pyflakes_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def get_filenames():
if not rel_fn.endswith(".py"):
continue
fn = os.path.join(dirpath, rel_fn)
if fn in [os.path.join("src", "header.py"),
if fn in (os.path.join("src", "header.py"),
os.path.join("src", "git", "long_header.py"),
]:
):
continue
print("pyflakes on:", fn)
yield fn
Expand Down