templates/python: init
This commit is contained in:
parent
adc5376072
commit
e6e80da7e3
7 changed files with 157 additions and 0 deletions
2
templates/python/.envrc
Normal file
2
templates/python/.envrc
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
watch_file "flake.nix" "pyproject.toml"
|
||||||
|
use flake
|
14
templates/python/.gitignore
vendored
Normal file
14
templates/python/.gitignore
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Secrets
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Nix
|
||||||
|
.direnv/
|
||||||
|
result
|
||||||
|
|
||||||
|
# Python
|
||||||
|
.ruff_cache
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# Runtime
|
||||||
|
rename.sqlite3
|
||||||
|
rename.sqlite3-journal
|
66
templates/python/flake.nix
Normal file
66
templates/python/flake.nix
Normal 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}"; }
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
21
templates/python/pyproject.toml
Normal file
21
templates/python/pyproject.toml
Normal 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
|
1
templates/python/rename/__init__.py
Normal file
1
templates/python/rename/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from .main import run
|
27
templates/python/rename/main.py
Normal file
27
templates/python/rename/main.py
Normal 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
26
templates/python/setup
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue