feat(templates): python template

This commit is contained in:
Gabriel Fontes
2024-09-02 23:08:39 -03:00
parent 752f15060f
commit 6390e833ee
7 changed files with 136 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
.venv/
build/
*.egg-info/
venv/
__pycache__/
*.py[cod]
+51
View File
@@ -0,0 +1,51 @@
# Foo Bar
TODO
## Installation
You can install the package using `pipx`
```bash
pipx install git+https://github.com/misterio77/foo-bar
```
Alternatively, use pip with `--user`:
```bash
pip install --user git+https://github.com/misterio77/foo-bar
```
Or use nix:
```bash
nix shell github:misterio77/foo-bar
```
## Usage
TODO
## Hacking
Use [poetry](https://python-poetry.org/), like so:
```bash
poetry install
poetry shell
```
Or use nix:
```bash
nix develop -c $SHELL
```
You can then use `python -m` to run it, as well as all the usual dev tools:
```bash
python -m foo_bar # Run
mypy # Type check
ruff check # Lint
ruff format # Format
pytest # Run tests
```
Python LSP will also be available. Check your editor docs on how to enable it.
+32
View File
@@ -0,0 +1,32 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
systems.url = "github:nix-systems/default";
poetry2nix.url = "github:nix-community/poetry2nix";
poetry2nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
nixpkgs,
systems,
poetry2nix,
...
}: let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = forEachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
p2nix = poetry2nix.lib.mkPoetry2Nix {inherit pkgs;};
in {
default = p2nix.mkPoetryApplication {
projectDir = ./.;
preferWheels = true;
checkPhase = ''
mypy
ruff check
pytest
'';
};
});
};
}
+2
View File
@@ -0,0 +1,2 @@
def hello_world() -> str:
return "Hello, world!"
+9
View File
@@ -0,0 +1,9 @@
from foo_bar import hello_world
def main() -> None:
print(hello_world())
if __name__ == "__main__":
main()
+31
View File
@@ -0,0 +1,31 @@
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "foo-bar"
version = "0.1.0"
authors = []
description = ""
[tool.poetry.dependencies]
python = "^3.12"
[tool.poetry.group.dev.dependencies]
pytest = "^8.3"
ruff = "0.6.1"
mypy = "^1.11"
python-lsp-server = "^1.12"
pylsp-mypy = "^0.6"
[tool.poetry.scripts]
foo-bar = "foo_bar.__main__:main"
[tool.ruff]
line-length = 88
[tool.mypy]
files = "."
strict = true
[tool.pytest.ini_options]
testpaths = ["tests/*"]
pythonpath = ["."]
+5
View File
@@ -0,0 +1,5 @@
from foo_bar import hello_world
def test_hello_world() -> None:
assert hello_world() == "Hello, world!"