Skip to content

Commit

Permalink
Fixed the --version command when installed from source (#344)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ariasmn authored and AdnanHodzic committed Jan 8, 2022
1 parent 1673583 commit d2dba2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 4 additions & 9 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import click
import warnings
import configparser
import pkg_resources
from math import isclose
from pathlib import Path
from shutil import which
Expand Down Expand Up @@ -111,7 +112,7 @@ def get_config(config_file=""):
# 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":
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d2dba2f

Please sign in to comment.