Skip to content

Commit

Permalink
Expand "--version" output
Browse files Browse the repository at this point in the history
Add build, copyright, git version/date, license, and author information to the
output of 'ksconf --version'.  Oh, and some ASCII art!

Continue to improve the "git describe" to PEP440 version numbering logic.
  • Loading branch information
lowell80 committed Jun 29, 2018
1 parent 10e8293 commit 21d9778
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 14 deletions.
105 changes: 101 additions & 4 deletions ksconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,108 @@
git check-attr -a -- *.conf
"""

# _version.py is autogenerated at build time. But is missing on first call to setup.py
from __future__ import absolute_import
from __future__ import unicode_literals

__author__ = "Lowell Alleman <lowell@kintyre.co>"
__copyright__ = "(c) 2018 Kintyre Solutions, Inc"
__license__ = "Apache Public License v2"

# _version.py is autogenerated at build time. But is missing on first call to setup.py
try:
from ._version import version
from ._version import version as __version__, build as __build__, vcs_info as __vcs_info__
except ImportError:
version = None
__version__ = None
__build__ = None
__vcs_info__ = None




# Because how do you pick just just ONE?!!
__ascii_sigs__ = (
"""\
#
##
### ## #### ###### ####### ### ## #######
### ## ### ### ## #### ##
##### ### ### ## ## ####### #######
### ## ### ### ## ## ### ### ##
### ## ##### ###### ##### ### ## ##
#
""",
"""\
.-..-. .--. .--.
: :' ;: .--' : .-'
: ' `. `. .--. .--. ,-.,-.: `;
: :.`. _`, :' ..'' .; :: ,. :: :
:_;:_;`.__.'`.__.'`.__.':_;:_;:_;
""",
"""\
___ ____ ______ ___
|_ ||_ _| .' ___ | .' ..]
| |_/ / .--. / .' \_| .--. _ .--. _| |_
| __'. ( (`\]| | / .'`\ \[ `.-. |'-| |-'
_| | \ \_ `'.'.\ `.___.'\| \__. | | | | | | |
|____||____|[\__) )`.____ .' '.__.' [___||__][___]
""",
"""\
_ __ __ ___ __ __ _ ___
| |/ /' _/ / _//__\| \| | __|
| <`._`.| \_| \/ | | ' | _|
|_|\_\___/ \__/\__/|_|\__|_|
""",
"""\
_ __
| | / _|
| | _____ ___ ___ _ __ | |_
| |/ / __|/ __/ _ \| '_ \| _|
| <\__ \ (_| (_) | | | | |
|_|\_\___/\___\___/|_| |_|_|
""",
"""\
_ ___
| | / __)
| | _ ___ ____ ___ ____ _| |__
| |_/ )/___)/ ___) _ \| _ (_ __)
| _ (|___ ( (__| |_| | | | || |
|_| \_|___/ \____)___/|_| |_||_|
""",
"""\
_ ___
| |_ ___ ___ ___ ___| _|
| '_|_ -| _| . | | _|
|_,_|___|___|___|_|_|_|
""",
"""\
kkkkkkkk ffffffffffffffff
k::::::k f::::::::::::::::f
k::::::k f::::::::::::::::::f
k::::::k f::::::fffffff:::::f
k:::::k kkkkkkk ssssssssss cccccccccccccccc ooooooooooo nnnn nnnnnnnn f:::::f ffffff
k:::::k k:::::k ss::::::::::s cc:::::::::::::::c oo:::::::::::oo n:::nn::::::::nn f:::::f
k:::::k k:::::kss:::::::::::::s c:::::::::::::::::co:::::::::::::::on::::::::::::::nn f:::::::ffffff
k:::::k k:::::k s::::::ssss:::::sc:::::::cccccc:::::co:::::ooooo:::::onn:::::::::::::::nf::::::::::::f
k::::::k:::::k s:::::s ssssss c::::::c ccccccco::::o o::::o n:::::nnnn:::::nf::::::::::::f
k:::::::::::k s::::::s c:::::c o::::o o::::o n::::n n::::nf:::::::ffffff
k:::::::::::k s::::::s c:::::c o::::o o::::o n::::n n::::n f:::::f
k::::::k:::::k ssssss s:::::s c::::::c ccccccco::::o o::::o n::::n n::::n f:::::f
k::::::k k:::::k s:::::ssss::::::sc:::::::cccccc:::::co:::::ooooo:::::o n::::n n::::nf:::::::f
k::::::k k:::::ks::::::::::::::s c:::::::::::::::::co:::::::::::::::o n::::n n::::nf:::::::f
k::::::k k:::::ks:::::::::::ss cc:::::::::::::::c oo:::::::::::oo n::::n n::::nf:::::::f
kkkkkkkk kkkkkkksssssssssss cccccccccccccccc ooooooooooo nnnnnn nnnnnnfffffffff
""",
"""\
_ __
| | _____ ___ ___ _ __ / _|
| |/ / __|/ __/ _ \| '_ \| |_
| <\__ \ (_| (_) | | | | _|
|_|\_\___/\___\___/|_| |_|_|
""",
"""\
_ __
| | _____ ___ ___ _ __ / _|
| |/ / __|/ __/ _ \| '_ \| |_
| <\__ \ (_| (_) | | | | _|
|_|\_\___/\___\___/|_| |_|_|
""")
22 changes: 16 additions & 6 deletions ksconf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import ksconf
import ksconf.util
from ksconf.commands import KsconfCmd, MyDescriptionHelpFormatter, get_entrypoints
from ksconf.consts import EXIT_CODE_INTERNAL_ERROR
from ksconf.util.completers import autocomplete

###################################################################################################
Expand Down Expand Up @@ -49,15 +48,26 @@ def cli(argv=None, _unittest=False):

subparsers = parser.add_subparsers()

version_info = '%(prog)s {}\n'.format(ksconf.version)
version_info = []

version_info += "\nCommands:"
from random import choice
# XXX: Check terminal size before picking a signature
version_info.append(choice(ksconf.__ascii_sigs__))
version_info.append("%(prog)s {} (Build {})".format(ksconf.__version__, ksconf.__build__))
if ksconf.__vcs_info__:
version_info.append(ksconf.__vcs_info__)
version_info.append("Written by {}.".format(ksconf.__author__))
version_info.append("Copyright {}.".format(ksconf.__copyright__))
version_info.append("Licensed under {}".format(ksconf.__license__))

version_info.append("\nCommands:")
# Add entry-point subcommands
# XXX: Eventually lazy load subcommands to save resources. (Low priority)
for (name, entry) in get_entrypoints("ksconf_cmd").items():
#sys.stderr.write("Loading {} from entry point: {!r}\n".format(name, entry))
# sys.stderr.write("Loading {} from entry point: {!r}\n".format(name, entry))
cmd_cls = entry.load()
distro = entry.dist or "Unknown"
version_info += "\n {:15} ({})".format(name, distro)
version_info.append(" {:15} ({})".format(name, distro))

if not issubclass(cmd_cls, KsconfCmd):
raise RuntimeError("Entry point {!r} not derived from KsconfCmd.".format(entry))
Expand All @@ -84,7 +94,7 @@ def cli(argv=None, _unittest=False):
"keeping the latest. Mode 'exception', the default, aborts if "
"duplicate keys are found.")
'''
parser.add_argument('--version', action='version', version=version_info)
parser.add_argument('--version', action='version', version="\n".join(version_info))
parser.add_argument("--force-color", action="store_true", default=False,
help="Force TTY color mode on. Useful if piping the output a color-aware "
"pager, like 'less -R'")
Expand Down
21 changes: 17 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@
import os
import re
from setuptools import setup
from textwrap import dedent

from ksconf.setup_entrypoints import get_entrypoints_setup


def get_ver():
# Todo: Add fall-back method for tarballs (sdist) builds. See what others have done.
# Todo: There has to be a better library/method of doing this junk.
from ksconf.vc.git import git_cmd
ver_file = os.path.join("ksconf", "_version.py")
#git_sha1 = git_cmd(["rev-parse", "HEAD"]).stdout[:12]
vc_info = git_cmd(["show", "-s", "--abbrev=8", "--format=Git SHA1 %h committed on %cd",
"--date=format:%Y-%m-%d", "HEAD"]).stdout.strip()
gitout = git_cmd(["describe", "--tags", "--always", "--dirty"])
version = gitout.stdout.strip()
version = version.lstrip("v") # Tags format is v0.0.0
# replace hash with local version format
version = re.sub(r'-(\d+)-g([a-f0-9]+)(?:-(dirty))', r'.dev\1+\2\3', version)
### XXX: Wow. this needs unittests. smh
version = re.sub(r'-(\d+)-g([a-f0-9]+)(?:(-dirty))', r'.dev\1+\2\3', version)
version = re.sub(r'\d+\.\d+-dirty$', r'.dev0+dirty', version)
version = version.replace("-dirty",".dirty")
print("Version: {}".format(version))
open(ver_file, "w").write("# Version file autogenerated by the build process.\n"
"version = {0!r}\n".format(version))
code_block = dedent("""\
# Version file autogenerated by the build process
version = {0!r}
build = {1!r}
vcs_info = {2!r}
""").format(version, os.environ.get("TRAVIS_BUILD", None), vc_info)
open(ver_file, "w").write(code_block)
return version

DESCRIPTION = """\
Expand Down

0 comments on commit 21d9778

Please sign in to comment.