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

feat: support for pyproject.toml #576

Merged
merged 2 commits into from
Oct 13, 2023
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
2 changes: 1 addition & 1 deletion auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function setup_venv {

# tool install
function install {
python3 setup.py install --record files.txt
pip3 install .
mkdir -p /usr/local/share/auto-cpufreq/
cp -r scripts/ /usr/local/share/auto-cpufreq/
cp -r images/ /usr/local/share/auto-cpufreq/
Expand Down
Empty file added auto_cpufreq/bin/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion bin/auto-cpufreq → auto_cpufreq/bin/auto_cpufreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from click import UsageError
from subprocess import call, run

sys.path.append("../")
# sys.path.append("../")
from auto_cpufreq.core import *
from auto_cpufreq.power_helper import *

Expand Down
7 changes: 5 additions & 2 deletions bin/auto-cpufreq-gtk → auto_cpufreq/bin/auto_cpufreq_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
from gi.repository import Gtk, GLib
from auto_cpufreq.gui.app import ToolWindow

if __name__ == "__main__":
def main():
win = ToolWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
GLib.set_prgname("auto-cpufreq")
Gtk.main()
Gtk.main()

if __name__ == "__main__":
main()
22 changes: 20 additions & 2 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import pickle
import warnings
import configparser
import pkg_resources
# import pkg_resources
import importlib.metadata
from math import isclose
from pathlib import Path
from shutil import which
Expand Down Expand Up @@ -204,9 +205,26 @@ def new_update(custom_dir):
print(f"package cloned to directory {custom_dir}")
run(['./auto-cpufreq-installer'], input='i\n', encoding='utf-8')

def get_literal_version(package_name):
try:
package_metadata = importlib.metadata.metadata(package_name)

package_name = package_metadata['Name']
metadata_version = package_metadata['Version']

numbered_version, _, git_version = metadata_version.partition("+")

# Construct the literal version string
literal_version = f"{numbered_version}+{git_version}"

return literal_version

except importlib.metadata.PackageNotFoundError:
return f"Package '{package_name}' not found"

# return formatted version for a better readability
def get_formatted_version():
literal_version = pkg_resources.require("auto-cpufreq")[0].version
literal_version = get_literal_version("auto-cpufreq")
splitted_version = literal_version.split("+")
formatted_version = splitted_version[0]

Expand Down
13 changes: 8 additions & 5 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{ lib, python310Packages, fetchFromGitHub, callPackage, pkgs, version ? "git"}:
{ lib, python310Packages, fetchFromGitHub, callPackage, pkgs}:

python310Packages.buildPythonPackage rec {
pname = "auto-cpufreq";
inherit version;
# use pyproject.toml instead of setup.py
format = "pyproject";

pname = "auto-cpufreq";
version = "2.0.0dev";
src = ../.;


nativeBuildInputs = with pkgs; [ wrapGAppsHook gobject-introspection ];

buildInputs = with pkgs; [ gtk3 ];
buildInputs = with pkgs; [ gtk3 python310Packages.poetry-core ];

propagatedBuildInputs = with python310Packages; [ requests pygobject3 click distro psutil setuptools setuptools-git-versioning ];
propagatedBuildInputs = with python310Packages; [ requests pygobject3 click distro psutil setuptools poetry-dynamic-versioning ];

doCheck = false;
pythonImportsCheck = [ "auto_cpufreq" ];
Expand Down
1,287 changes: 1,287 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[tool.poetry]
name = "auto-cpufreq"
version = "2.0.0"
description = "Automatic CPU speed & power optimizer for Linux"
authors = ["Adnan Hodzic <adnan@hodzic.org>"]
license = "GPL-3.0-or-later"
readme = "README.md"
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Operating System :: POSIX :: Linux",
"Environment :: Console",
"Natural Language :: English"
]
keywords=["linux", "cpu", "speed", "power", "frequency", "turbo", "optimzier", "auto", "cpufreq"]
repository = "https://github.com/AdnanHodzic/auto-cpufreq"
documentation = "https://github.com/AdnanHodzic/auto-cpufreq#readme"
packages = [
{ include = "./auto_cpufreq" },
{ include = "./auto_cpufreq/gui" },
]

[tool.poetry.dependencies]
python = "^3.8"
psutil = "^5.9.5"
click = "^8.1.0"
distro = "^1.8.0"
requests = "^2.31.0"
PyGObject = "^3.46.0"

[tool.poetry.group.dev.dependencies]
poetry = "^1.6.1"

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"

[tool.poetry.scripts]
auto-cpufreq = "auto_cpufreq.bin.auto_cpufreq:main"
auto-cpufreq-gtk = "auto_cpufreq.bin.auto_cpufreq_gtk:main"

# https://github.com/mtkennerly/poetry-dynamic-versioning
[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
format = "v{base}+{commit}"

# SideNote
# Regarding zip_safe = https://setuptools.pypa.io/en/latest/deprecated/zip_safe.html
2 changes: 1 addition & 1 deletion scripts/start_app
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# load python virtual environment
venv_dir=/opt/auto-cpufreq/venv
. "${venv_dir}/bin/activate"
python_command="${venv_dir}/bin/python ${venv_dir}/bin/auto-cpufreq-gtk"
python_command="${venv_dir}/bin/auto-cpufreq-gtk"

# if [ "$XDG_SESSION_TYPE" = "wayland" ] ; then
# # necessary for running on wayland
Expand Down
File renamed without changes.