diff --git a/templates/python/.envrc b/templates/python/.envrc new file mode 100644 index 0000000..944d27b --- /dev/null +++ b/templates/python/.envrc @@ -0,0 +1,2 @@ +watch_file "flake.nix" "pyproject.toml" +use flake diff --git a/templates/python/.gitignore b/templates/python/.gitignore new file mode 100644 index 0000000..d116ea8 --- /dev/null +++ b/templates/python/.gitignore @@ -0,0 +1,14 @@ +# Secrets +.env + +# Nix +.direnv/ +result + +# Python +.ruff_cache +.ropeproject + +# Runtime +rename.sqlite3 +rename.sqlite3-journal diff --git a/templates/python/flake.nix b/templates/python/flake.nix new file mode 100644 index 0000000..857efe8 --- /dev/null +++ b/templates/python/flake.nix @@ -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}"; } + ]; + }; + }; + }; +} diff --git a/templates/python/pyproject.toml b/templates/python/pyproject.toml new file mode 100644 index 0000000..21f1d60 --- /dev/null +++ b/templates/python/pyproject.toml @@ -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 diff --git a/templates/python/rename/__init__.py b/templates/python/rename/__init__.py new file mode 100644 index 0000000..86966d1 --- /dev/null +++ b/templates/python/rename/__init__.py @@ -0,0 +1 @@ +from .main import run diff --git a/templates/python/rename/main.py b/templates/python/rename/main.py new file mode 100644 index 0000000..e07b871 --- /dev/null +++ b/templates/python/rename/main.py @@ -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 diff --git a/templates/python/setup b/templates/python/setup new file mode 100755 index 0000000..eba97e5 --- /dev/null +++ b/templates/python/setup @@ -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