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.
This commit is contained in:
Ismael Arias 2022-01-06 13:08:51 +01:00 committed by Adnan Hodzic
parent 1673583304
commit d2dba2fc31
2 changed files with 9 additions and 10 deletions

View File

@ -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

View File

@ -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",