Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI doesn't print Git info w/--version, while .version command can #2337

Open
dgw opened this issue Aug 3, 2022 · 0 comments
Open

CLI doesn't print Git info w/--version, while .version command can #2337

dgw opened this issue Aug 3, 2022 · 0 comments

Comments

@dgw
Copy link
Member

dgw commented Aug 3, 2022

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.

@dgw dgw added the Feature label Aug 3, 2022
@dgw dgw added this to the 8.1.0 milestone Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants