Fixed the --version command when installed from source (#347)
* 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. * Improving version output. Renaming version_config to setuptools_git_versioning to be compliant with new plugin version. Formatted the version when a git hash is present for a better readability. The version is set in the setup.py file. This will be used for the tar.gz releases. Snap version is also retrieved from setup.py too, so we avoid code repetition.
This commit is contained in:
parent
7b7e82b2b1
commit
5e503f89c2
|
@ -12,6 +12,7 @@ import time
|
||||||
import click
|
import click
|
||||||
import warnings
|
import warnings
|
||||||
import configparser
|
import configparser
|
||||||
|
import pkg_resources
|
||||||
from math import isclose
|
from math import isclose
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import which
|
from shutil import which
|
||||||
|
@ -111,7 +112,7 @@ except PermissionError:
|
||||||
# display running version of auto-cpufreq
|
# display running version of auto-cpufreq
|
||||||
def app_version():
|
def app_version():
|
||||||
|
|
||||||
print("auto-cpufreq version:")
|
print("auto-cpufreq version: ", end="")
|
||||||
|
|
||||||
# snap package
|
# snap package
|
||||||
if os.getenv("PKG_MARKER") == "SNAP":
|
if os.getenv("PKG_MARKER") == "SNAP":
|
||||||
|
@ -120,23 +121,27 @@ def app_version():
|
||||||
elif dist_name in ["arch", "manjaro", "garuda"]:
|
elif dist_name in ["arch", "manjaro", "garuda"]:
|
||||||
aur_pkg_check = call("pacman -Qs auto-cpufreq > /dev/null", shell=True)
|
aur_pkg_check = call("pacman -Qs auto-cpufreq > /dev/null", shell=True)
|
||||||
if aur_pkg_check == 1:
|
if aur_pkg_check == 1:
|
||||||
print(
|
print(get_formatted_version())
|
||||||
"Git commit:",
|
|
||||||
check_output(["git", "describe", "--always"]).strip().decode(),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
print(getoutput("pacman -Qi auto-cpufreq | grep Version"))
|
print(getoutput("pacman -Qi auto-cpufreq | grep Version"))
|
||||||
else:
|
else:
|
||||||
# source code (auto-cpufreq-installer)
|
# source code (auto-cpufreq-installer)
|
||||||
try:
|
try:
|
||||||
print(
|
print(get_formatted_version())
|
||||||
"Git commit:",
|
|
||||||
check_output(["git", "describe", "--always"]).strip().decode(),
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(repr(e))
|
print(repr(e))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# return formatted version for a better readability
|
||||||
|
def get_formatted_version():
|
||||||
|
literal_version = pkg_resources.require("auto-cpufreq")[0].version
|
||||||
|
splitted_version = literal_version.split("+")
|
||||||
|
formatted_version = splitted_version[0]
|
||||||
|
|
||||||
|
if len(splitted_version) > 1:
|
||||||
|
formatted_version += " (git: " + splitted_version[1] + ")"
|
||||||
|
|
||||||
|
return formatted_version
|
||||||
|
|
||||||
def app_res_use():
|
def app_res_use():
|
||||||
p = psutil.Process()
|
p = psutil.Process()
|
||||||
|
|
10
setup.py
10
setup.py
|
@ -12,10 +12,18 @@ def read(name):
|
||||||
with open(os.path.join(this, name)) as f:
|
with open(os.path.join(this, name)) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
|
# Used for the tar.gz/snap releases
|
||||||
|
VERSION = "1.9.0"
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="auto-cpufreq",
|
name="auto-cpufreq",
|
||||||
version="1.0",
|
setuptools_git_versioning={
|
||||||
|
"starting_version": VERSION,
|
||||||
|
"template": "{tag}+{sha}",
|
||||||
|
"dev_template": "{tag}+{sha}",
|
||||||
|
"dirty_template": "{tag}+{sha}.post{ccount}.dirty"
|
||||||
|
},
|
||||||
|
setup_requires=["setuptools-git-versioning"],
|
||||||
description="Automatic CPU speed & power optimizer for Linux",
|
description="Automatic CPU speed & power optimizer for Linux",
|
||||||
long_description=readme,
|
long_description=readme,
|
||||||
author="Adnan Hodzic",
|
author="Adnan Hodzic",
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
name: auto-cpufreq
|
name: auto-cpufreq
|
||||||
base: core20
|
base: core20
|
||||||
version: '1.9.1'
|
|
||||||
summary: Automatic CPU speed & power optimizer for Linux
|
summary: Automatic CPU speed & power optimizer for Linux
|
||||||
description: |
|
description: |
|
||||||
Automatic CPU speed & power optimizer for Linux based on active
|
Automatic CPU speed & power optimizer for Linux based on active
|
||||||
|
@ -11,6 +10,7 @@ description: |
|
||||||
license: LGPL-3.0
|
license: LGPL-3.0
|
||||||
grade: stable
|
grade: stable
|
||||||
confinement: strict
|
confinement: strict
|
||||||
|
adopt-info: auto-cpufreq
|
||||||
|
|
||||||
compression: lzo
|
compression: lzo
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@ parts:
|
||||||
- coreutils
|
- coreutils
|
||||||
- dmidecode
|
- dmidecode
|
||||||
source: .
|
source: .
|
||||||
|
override-pull: |
|
||||||
|
snapcraftctl pull
|
||||||
|
snapcraftctl set-version `grep ^VERSION $SNAPCRAFT_PART_SRC/setup.py | sed 's/.*"\(.*\)"/\1/'`
|
||||||
|
|
||||||
deploy-scripts:
|
deploy-scripts:
|
||||||
plugin: dump
|
plugin: dump
|
||||||
|
|
Loading…
Reference in New Issue