From d2dba2fc313a753036d4598a3b56d67b42b9a00b Mon Sep 17 00:00:00 2001 From: Ismael Arias Date: Thu, 6 Jan 2022 13:08:51 +0100 Subject: [PATCH] Fixed the --version command when installed from source (#344) The command only worked when running it inside the git repository. Now, it works from everywhere, and the version is constructed using the latest git tag and the SHA of the latest commit, which may help with further debugging in future issues. --- auto_cpufreq/core.py | 13 ++++--------- setup.py | 6 +++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 66cdc34..aefd6fa 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -12,6 +12,7 @@ import time import click import warnings import configparser +import pkg_resources from math import isclose from pathlib import Path from shutil import which @@ -111,7 +112,7 @@ except PermissionError: # display running version of auto-cpufreq def app_version(): - print("auto-cpufreq version:") + print("auto-cpufreq version: ", end="") # snap package if os.getenv("PKG_MARKER") == "SNAP": @@ -120,19 +121,13 @@ def app_version(): elif dist_name in ["arch", "manjaro", "garuda"]: aur_pkg_check = call("pacman -Qs auto-cpufreq > /dev/null", shell=True) if aur_pkg_check == 1: - print( - "Git commit:", - check_output(["git", "describe", "--always"]).strip().decode(), - ) + print(pkg_resources.require("auto-cpufreq")[0].version) else: print(getoutput("pacman -Qi auto-cpufreq | grep Version")) else: # source code (auto-cpufreq-installer) try: - print( - "Git commit:", - check_output(["git", "describe", "--always"]).strip().decode(), - ) + print(pkg_resources.require("auto-cpufreq")[0].version) except Exception as e: print(repr(e)) pass diff --git a/setup.py b/setup.py index 6c542b6..a4d58ca 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,11 @@ def read(name): setup( name="auto-cpufreq", - version="1.0", + version_config={ + "template": "{tag}.{sha}", + "dev_template": "{tag}.{sha}" + }, + setup_requires=["setuptools-git-versioning"], description="Automatic CPU speed & power optimizer for Linux", long_description=readme, author="Adnan Hodzic",