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:
Evie Litherland-Smith 2024-06-02 06:52:28 +01:00
parent 6772fdbc2c
commit ddee47ce40
9 changed files with 89 additions and 118 deletions

9
default.nix Normal file
View file

@ -0,0 +1,9 @@
{
python3,
mkPoetryApplication,
}:
mkPoetryApplication {
python = python3;
projectDir = ./.;
checkGroups = [];
}

View file

@ -13,15 +13,6 @@
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
in {
packages = forAllSystems (system: let
inherit (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}) mkPoetryApplication;
in {
default = mkPoetryApplication {
projectDir = self;
checkGroups = [];
};
});
apps = forAllSystems (system: {
default = {
type = "app";
@ -30,10 +21,11 @@
});
devShells = forAllSystems (system: {
default = import ./shell.nix {
pkgs = pkgs.${system};
inherit (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}) mkPoetryEnv;
};
default = (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}).callPackage ./shell.nix {};
});
packages = forAllSystems (system: {
default = (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}).callPackage ./default.nix {};
});
};
}

34
poetry.lock generated
View file

@ -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]]
name = "black"
@ -230,18 +230,15 @@ files = [
[[package]]
name = "nodeenv"
version = "1.8.0"
version = "1.9.0"
description = "Node.js virtual environment builder"
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 = [
{file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"},
{file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"},
{file = "nodeenv-1.9.0-py2.py3-none-any.whl", hash = "sha256:508ecec98f9f3330b636d4448c0f1a56fc68017c68f1e7857ebc52acf0eb879a"},
{file = "nodeenv-1.9.0.tar.gz", hash = "sha256:07f144e90dae547bf0d4ee8da0ee42664a42a04e02ed68e06324348dafe4bdb1"},
]
[package.dependencies]
setuptools = "*"
[[package]]
name = "notify-py"
version = "0.3.42"
@ -373,21 +370,6 @@ files = [
{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]]
name = "tomli"
version = "2.0.1"
@ -401,13 +383,13 @@ files = [
[[package]]
name = "typing-extensions"
version = "4.12.0"
version = "4.12.1"
description = "Backported and Experimental Type Hints for Python 3.8+"
optional = false
python-versions = ">=3.8"
files = [
{file = "typing_extensions-4.12.0-py3-none-any.whl", hash = "sha256:b349c66bea9016ac22978d800cfff206d5f9816951f12a7d0ec5578b0a819594"},
{file = "typing_extensions-4.12.0.tar.gz", hash = "sha256:8cbcdc8606ebcb0d95453ad7dc5065e6237b6aa230a31e81d0f440c30fed5fd8"},
{file = "typing_extensions-4.12.1-py3-none-any.whl", hash = "sha256:6024b58b69089e5a89c347397254e35f1bf02a907728ec7fee9bf0fe837d203a"},
{file = "typing_extensions-4.12.1.tar.gz", hash = "sha256:915f5e35ff76f56588223f15fdd5938f9a1cf9195c0de25130c627e4d597f6d1"},
]
[[package]]

View file

@ -9,7 +9,7 @@ repository = "https://git.xenia.me.uk/pixelifytica/nix-background-upgrade"
packages = [{include = "nix_background_upgrade", from = "src"}]
[tool.poetry.scripts]
nix-background-upgrade = 'nix_background_upgrade.cli:main'
nix-background-upgrade = 'nix_background_upgrade.main:main'
[tool.poetry.dependencies]
python = "^3.9"

View file

@ -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()

View file

@ -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

View 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()

View file

@ -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

View file

@ -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",
)