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

Fixed the --version command when installed from source #347

Merged
merged 3 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 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,23 +121,27 @@ 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(get_formatted_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(get_formatted_version())
except Exception as e:
print(repr(e))
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():
p = psutil.Process()
Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ def read(name):
with open(os.path.join(this, name)) as f:
return f.read()

# Used for the tar.gz/snap releases
VERSION = "1.9.0"

setup(
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",
long_description=readme,
author="Adnan Hodzic",
Expand Down
5 changes: 4 additions & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: auto-cpufreq
base: core20
version: '1.9.1'
summary: Automatic CPU speed & power optimizer for Linux
description: |
Automatic CPU speed & power optimizer for Linux based on active
Expand All @@ -11,6 +10,7 @@ description: |
license: LGPL-3.0
grade: stable
confinement: strict
adopt-info: auto-cpufreq

compression: lzo

Expand All @@ -27,6 +27,9 @@ parts:
- coreutils
- dmidecode
source: .
override-pull: |
snapcraftctl pull
snapcraftctl set-version `grep ^VERSION $SNAPCRAFT_PART_SRC/setup.py | sed 's/.*"\(.*\)"/\1/'`

deploy-scripts:
plugin: dump
Expand Down