templates/python: init

This commit is contained in:
Infinidoge 2025-01-20 14:44:59 -05:00
parent adc5376072
commit e6e80da7e3
Signed by: Infinidoge
SSH key fingerprint: SHA256:oAMyvotlNFraMmZmr+p6AxnNfW/GioTs1pOn3V4tQ7A
7 changed files with 157 additions and 0 deletions

2
templates/python/.envrc Normal file
View file

@ -0,0 +1,2 @@
watch_file "flake.nix" "pyproject.toml"
use flake

14
templates/python/.gitignore vendored Normal file
View file

@ -0,0 +1,14 @@
# Secrets
.env
# Nix
.direnv/
result
# Python
.ruff_cache
.ropeproject
# Runtime
rename.sqlite3
rename.sqlite3-journal

View file

@ -0,0 +1,66 @@
{
description = "Template for general python applications";
inputs = {
nixpkgs.url = "github:Infinidoge/nixpkgs/feat/disnake";
flake-parts.url = "github:hercules-ci/flake-parts";
devshell.url = "github:numtide/devshell";
pyproject-nix.url = "github:nix-community/pyproject.nix";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
devshell.inputs.nixpkgs.follows = "nixpkgs";
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
imports = with inputs; [
devshell.flakeModule
];
perSystem = { config, pkgs, ... }:
let
project = inputs.pyproject-nix.lib.project.loadPyproject {
projectRoot = ./.;
};
python = pkgs.python3;
in
{
packages.default = (python.pkgs.buildPythonPackage (
project.renderers.buildPythonPackage { inherit python; }
)).overrideAttrs { allowSubstitutes = false; preferLocalBuild = true; };
devshells.default =
let
env = python.withPackages (
project.renderers.withPackages {
inherit python;
extraPackages = p: with p; [
python-lsp-server
python-lsp-ruff
pylsp-rope
isort
black
];
}
);
in
{
devshell = {
name = "rename";
motd = "";
packages = [
env
];
};
env = [
{ name = "PYTHONPATH"; prefix = "${env}/${env.sitePackages}"; }
];
};
};
};
}

View file

@ -0,0 +1,21 @@
[project]
name = "rename"
version = "0.0.1"
dependencies = [
"disnake",
"python-dotenv",
"aiosqlite"
]
[project.scripts]
rename = "rename:run"
[tool.setuptools.packages]
find = {}
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.ruff]
line-length = 120

View file

@ -0,0 +1 @@
from .main import run

View file

@ -0,0 +1,27 @@
import logging
import os
import sys
from dotenv import find_dotenv, load_dotenv
# Logger setup
log = logging.getLogger("rename")
log.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
log.addHandler(handler)
if load_dotenv(find_dotenv(usecwd=True)):
log.debug("Loaded .env")
else:
log.debug("Didn't find .env")
TOKEN = os.getenv("TOKEN")
def run():
pass

26
templates/python/setup Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# vim: set ft=bash:
set -e
if [ $# -lt 3 ]; then
echo "Not enough arguments"
echo 'usage: ./setup basename'
exit 1
fi
nameBase=$1
files=(
"flake.nix"
".gitignore"
"pyproject.toml"
"rename/main.py"
)
for file in ${files[@]}; do
sed -i "
s/rename/$nameBase/g;
" $file
done
mv rename $nameBase