Refactor to clean up python files
Combine unnecessary amount of python files into single main.py Add default.nix for building without Flakes enabled Adjust flake.nix to use poetry2nix callPackage for both default and shell, to be more consistent
This commit is contained in:
parent
6772fdbc2c
commit
ddee47ce40
9
default.nix
Normal file
9
default.nix
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
python3,
|
||||||
|
mkPoetryApplication,
|
||||||
|
}:
|
||||||
|
mkPoetryApplication {
|
||||||
|
python = python3;
|
||||||
|
projectDir = ./.;
|
||||||
|
checkGroups = [];
|
||||||
|
}
|
18
flake.nix
18
flake.nix
|
@ -13,15 +13,6 @@
|
||||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||||
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
|
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
|
||||||
in {
|
in {
|
||||||
packages = forAllSystems (system: let
|
|
||||||
inherit (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}) mkPoetryApplication;
|
|
||||||
in {
|
|
||||||
default = mkPoetryApplication {
|
|
||||||
projectDir = self;
|
|
||||||
checkGroups = [];
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
apps = forAllSystems (system: {
|
apps = forAllSystems (system: {
|
||||||
default = {
|
default = {
|
||||||
type = "app";
|
type = "app";
|
||||||
|
@ -30,10 +21,11 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
devShells = forAllSystems (system: {
|
devShells = forAllSystems (system: {
|
||||||
default = import ./shell.nix {
|
default = (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}).callPackage ./shell.nix {};
|
||||||
pkgs = pkgs.${system};
|
});
|
||||||
inherit (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}) mkPoetryEnv;
|
|
||||||
};
|
packages = forAllSystems (system: {
|
||||||
|
default = (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}).callPackage ./default.nix {};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
34
poetry.lock
generated
34
poetry.lock
generated
|
@ -1,4 +1,4 @@
|
||||||
# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand.
|
# This file is automatically @generated by Poetry 1.8.0 and should not be changed by hand.
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "black"
|
name = "black"
|
||||||
|
@ -230,18 +230,15 @@ files = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nodeenv"
|
name = "nodeenv"
|
||||||
version = "1.8.0"
|
version = "1.9.0"
|
||||||
description = "Node.js virtual environment builder"
|
description = "Node.js virtual environment builder"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*"
|
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||||
files = [
|
files = [
|
||||||
{file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"},
|
{file = "nodeenv-1.9.0-py2.py3-none-any.whl", hash = "sha256:508ecec98f9f3330b636d4448c0f1a56fc68017c68f1e7857ebc52acf0eb879a"},
|
||||||
{file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"},
|
{file = "nodeenv-1.9.0.tar.gz", hash = "sha256:07f144e90dae547bf0d4ee8da0ee42664a42a04e02ed68e06324348dafe4bdb1"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
setuptools = "*"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "notify-py"
|
name = "notify-py"
|
||||||
version = "0.3.42"
|
version = "0.3.42"
|
||||||
|
@ -373,21 +370,6 @@ files = [
|
||||||
{file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"},
|
{file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "setuptools"
|
|
||||||
version = "70.0.0"
|
|
||||||
description = "Easily download, build, install, upgrade, and uninstall Python packages"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "setuptools-70.0.0-py3-none-any.whl", hash = "sha256:54faa7f2e8d2d11bcd2c07bed282eef1046b5c080d1c32add737d7b5817b1ad4"},
|
|
||||||
{file = "setuptools-70.0.0.tar.gz", hash = "sha256:f211a66637b8fa059bb28183da127d4e86396c991a942b028c6650d4319c3fd0"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"]
|
|
||||||
testing = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mypy (==1.9)", "packaging (>=23.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.1)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tomli"
|
name = "tomli"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
@ -401,13 +383,13 @@ files = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typing-extensions"
|
name = "typing-extensions"
|
||||||
version = "4.12.0"
|
version = "4.12.1"
|
||||||
description = "Backported and Experimental Type Hints for Python 3.8+"
|
description = "Backported and Experimental Type Hints for Python 3.8+"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.8"
|
||||||
files = [
|
files = [
|
||||||
{file = "typing_extensions-4.12.0-py3-none-any.whl", hash = "sha256:b349c66bea9016ac22978d800cfff206d5f9816951f12a7d0ec5578b0a819594"},
|
{file = "typing_extensions-4.12.1-py3-none-any.whl", hash = "sha256:6024b58b69089e5a89c347397254e35f1bf02a907728ec7fee9bf0fe837d203a"},
|
||||||
{file = "typing_extensions-4.12.0.tar.gz", hash = "sha256:8cbcdc8606ebcb0d95453ad7dc5065e6237b6aa230a31e81d0f440c30fed5fd8"},
|
{file = "typing_extensions-4.12.1.tar.gz", hash = "sha256:915f5e35ff76f56588223f15fdd5938f9a1cf9195c0de25130c627e4d597f6d1"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -9,7 +9,7 @@ repository = "https://git.xenia.me.uk/pixelifytica/nix-background-upgrade"
|
||||||
packages = [{include = "nix_background_upgrade", from = "src"}]
|
packages = [{include = "nix_background_upgrade", from = "src"}]
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
nix-background-upgrade = 'nix_background_upgrade.cli:main'
|
nix-background-upgrade = 'nix_background_upgrade.main:main'
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.9"
|
python = "^3.9"
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
from .notification import create_notification
|
|
||||||
|
|
||||||
|
|
||||||
def main(*args, **kwargs) -> None:
|
|
||||||
"""
|
|
||||||
Sends a test notification to check everything is working
|
|
||||||
|
|
||||||
:returns: None
|
|
||||||
"""
|
|
||||||
notification = create_notification()
|
|
||||||
notification.message = "This is a test notification"
|
|
||||||
notification.send()
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
|
@ -1,15 +0,0 @@
|
||||||
"""
|
|
||||||
Control upgrading home-manager configuration
|
|
||||||
"""
|
|
||||||
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
|
||||||
def home_manager_switch() -> None:
|
|
||||||
"""
|
|
||||||
Switch home-manager to new version
|
|
||||||
|
|
||||||
:returns: None
|
|
||||||
"""
|
|
||||||
subprocess.Popen("which -a home-manager".split())
|
|
||||||
return
|
|
66
src/nix_background_upgrade/main.py
Normal file
66
src/nix_background_upgrade/main.py
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import subprocess
|
||||||
|
from os import getenv
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from notifypy import Notify
|
||||||
|
|
||||||
|
NIXOS_CONFIGURATION: str = getenv("NIXOS_CONFIGURATION", "")
|
||||||
|
|
||||||
|
|
||||||
|
def create_notification(source: Optional[str] = None) -> Notify:
|
||||||
|
"""
|
||||||
|
Create notification class
|
||||||
|
|
||||||
|
:param source: Name of originating file or function, used in default notification
|
||||||
|
title
|
||||||
|
|
||||||
|
:returns: Notify class with custom defaults
|
||||||
|
"""
|
||||||
|
if source is None:
|
||||||
|
source = "Nix process"
|
||||||
|
return Notify(
|
||||||
|
default_notification_title="Message from {}".format(source),
|
||||||
|
default_notification_icon=Path(__file__).parent / "./nix-snowflake.png",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def nixos_switch() -> int:
|
||||||
|
"""
|
||||||
|
Switch NixOS system to new version
|
||||||
|
|
||||||
|
:returns: Error code of `sudo nixos-rebuild switch` call
|
||||||
|
"""
|
||||||
|
notification = create_notification(source="nixos_switch")
|
||||||
|
try:
|
||||||
|
subprocess.run("which -a nixos-rebuild".split()).check_returncode()
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
notification.message = e
|
||||||
|
notification.send()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def home_manager_switch() -> None:
|
||||||
|
"""
|
||||||
|
Switch home-manager to new version
|
||||||
|
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
subprocess.Popen("which -a home-manager".split())
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def main(*args, **kwargs) -> None:
|
||||||
|
"""
|
||||||
|
Sends a test notification to check everything is working
|
||||||
|
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
notification = create_notification()
|
||||||
|
notification.message = "This is a test notification"
|
||||||
|
notification.send()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -1,25 +0,0 @@
|
||||||
"""
|
|
||||||
Control upgrading NixOS configuration
|
|
||||||
"""
|
|
||||||
|
|
||||||
import subprocess
|
|
||||||
from os import getenv
|
|
||||||
|
|
||||||
from .notification import create_notification
|
|
||||||
|
|
||||||
NIXOS_CONFIGURATION: str = getenv("NIXOS_CONFIGURATION", "")
|
|
||||||
|
|
||||||
|
|
||||||
def nixos_switch() -> int:
|
|
||||||
"""
|
|
||||||
Switch NixOS system to new version
|
|
||||||
|
|
||||||
:returns: Error code of `sudo nixos-rebuild switch` call
|
|
||||||
"""
|
|
||||||
notification = create_notification(source="nixos_switch")
|
|
||||||
try:
|
|
||||||
subprocess.run("which -a nixos-rebuild".split()).check_returncode()
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
notification.message = e
|
|
||||||
notification.send()
|
|
||||||
return 0
|
|
|
@ -1,21 +0,0 @@
|
||||||
from pathlib import Path
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from notifypy import Notify
|
|
||||||
|
|
||||||
|
|
||||||
def create_notification(source: Optional[str] = None) -> Notify:
|
|
||||||
"""
|
|
||||||
Create notification class
|
|
||||||
|
|
||||||
:param source: Name of originating file or function, used in default notification
|
|
||||||
title
|
|
||||||
|
|
||||||
:returns: Notify class with custom defaults
|
|
||||||
"""
|
|
||||||
if source is None:
|
|
||||||
source = "Nix process"
|
|
||||||
return Notify(
|
|
||||||
default_notification_title="Message from {}".format(source),
|
|
||||||
default_notification_icon=Path(__file__).parent / "./nix-snowflake.png",
|
|
||||||
)
|
|
Loading…
Reference in a new issue