8000 CLI doesn't print Git info w/`--version`, while `.version` command can · Issue #2337 · sopel-irc/sopel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
CLI doesn't print Git info w/--version, while .version command can #2337
Open
@dgw

Description

@dgw

Context

The CLI code to get Sopel's version only checks the Python platform release and imports Sopel's __version__:

sopel/sopel/cli/run.py

Lines 214 to 220 in 0479737

def print_version():
"""Print Python version and Sopel version on stdout."""
py_ver = '%s.%s.%s' % (sys.version_info.major,
sys.version_info.minor,
sys.version_info.micro)
print('Sopel %s (running on Python %s)' % (__version__, py_ver))
print('https://sopel.chat/')

On Git-based/editable installations, this will be a ".dev0" version number that doesn't mean anything.

We already have the ability, within the version built-in plugin, to show which Git commit is checked out:

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
GIT_DIR = os.path.join(PROJECT_DIR, '.git')
def git_info():
head = os.path.join(GIT_DIR, 'HEAD')
if os.path.isfile(head):
with open(head) as h:
head_loc = h.readline()[5:-1] # strip ref: and \n
head_file = os.path.join(GIT_DIR, head_loc)
if os.path.isfile(head_file):
with open(head_file) as h:
sha = h.readline()
if sha:
return sha

While not foolproof (the working directory can be changed while Sopel is running, for example, or the working copy might be modified without having been committed yet), this is still much more useful information to show.

Proposal

How to get Sopel's version number, and/or the Git SHA if relevant (possibly with a "dirty" flag if the working directory is not clean, as I've seen other tools do), could become part of tools. Or somewhere else, if that would cause a circular import; I haven't looked yet.

Then both the CLI code and version plugin could use a common function call(s) to show the version information consistently.

Notes

I thought we had an issue for this already, honestly, but it appears not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0