move to uv and nix for building docker images

This commit is contained in:
Markbeep
2025-03-17 11:12:56 +01:00
parent d6b301d372
commit fa0eb84877
6 changed files with 1581 additions and 85 deletions
+7 -5
View File
@@ -165,15 +165,17 @@ Suggestions are always welcome. Do note though that a big goal is to keep this p
Virtual environments help isolate any installed packages to this directory. Project was made with `Python 3.11`. Any python version above 3.9 _should_ work, but if there are any problems use `>= 3.11`.
For improved dependency management, `uv` is used instead of `pip`.
```sh
python -m venv .venv
uv venv .venv
source .venv/bin/activate # sh/bash
source .venv/bin/activate.fish # fish
.venv\Scripts\activate.bat # cmd
.venv\Scripts\Activate.ps1 # powershell
pip install -r requirements.txt
uv sync
```
For local development, environment variables can be added to `.env.local` and they'll be used wherever required.
@@ -183,7 +185,7 @@ For local development, environment variables can be added to `.env.local` and th
[Alembic](https://alembic.sqlalchemy.org/en/latest/) is used to create database migrations. Run the following before starting up the application for the first time. It will initialize the directory if non-existant, create the database file as well as execute any required migrations.
```sh
alembic upgrade heads
uv run alembic upgrade heads
```
_In case of any model changes, remember to create migrations using `alembic revision --autogenerate -m "<message>"`._
@@ -195,7 +197,7 @@ Running the application is best done in multiple terminals:
1. Start FastAPI dev mode:
```sh
fastapi dev
uv run fastapi dev
```
Website can be visited at http://localhost:8000.
@@ -204,7 +206,7 @@ Website can be visited at http://localhost:8000.
```sh
npm i
tailwindcss -i styles/globals.css -o static/globals.css --watch
uv run tailwindcss -i styles/globals.css -o static/globals.css --watch
# Alternatively npx can be used to run tailwindcss
npx @tailwindcss/cli@4 -i styles/globals.css -o static/globals.css --watch
```
Generated
+73 -1
View File
@@ -14,9 +14,81 @@
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz"
}
},
"pyproject-build-systems": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"pyproject-nix": [
"pyproject-nix"
],
"uv2nix": [
"uv2nix"
]
},
"locked": {
"lastModified": 1741647088,
"narHash": "sha256-y/Aj21rMGdE23dcFfD4lRhNMgkhIRucp+uuWLWUXv0M=",
"owner": "pyproject-nix",
"repo": "build-system-pkgs",
"rev": "6d7eced86469cf89ed4d19d91b870163deb0dca2",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "build-system-pkgs",
"type": "github"
}
},
"pyproject-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1741648141,
"narHash": "sha256-jQEZCSCgm60NGmBg3JPu290DDhNVI1GVVEd0P8VCnME=",
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"rev": "7747e5a058245c7abe033a798f818f0572d8e155",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"pyproject-build-systems": "pyproject-build-systems",
"pyproject-nix": "pyproject-nix",
"uv2nix": "uv2nix"
}
},
"uv2nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"pyproject-nix": [
"pyproject-nix"
]
},
"locked": {
"lastModified": 1742147344,
"narHash": "sha256-//dMTPMfAeUFQWkwyuFF0NBTENliZF/p1gCWln2eDHA=",
"owner": "pyproject-nix",
"repo": "uv2nix",
"rev": "3bc6e12cf559c2fd39ce6f4e5d408817e53ac648",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "uv2nix",
"type": "github"
}
}
},
+70 -4
View File
@@ -1,22 +1,88 @@
{
description = "A Nix-flake-based Python development environment";
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz";
outputs = { self, nixpkgs }:
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:pyproject-nix/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.uv2nix.follows = "uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, uv2nix, pyproject-nix, pyproject-build-systems, ... }:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
overlay = workspace.mkPyprojectOverlay {
sourcePreference = "wheel";
};
pyprojectOverrides = _final: _prev: {
# Implement build fixups here.
# Note that uv2nix is _not_ using Nixpkgs buildPythonPackage.
# It's using https://pyproject-nix.github.io/pyproject.nix/build.html
};
in
{
packages = forEachSupportedSystem ({ pkgs }:
let
python = pkgs.python311;
pythonSet =
# Use base package set from pyproject.nix builders
(pkgs.callPackage pyproject-nix.build.packages {
inherit python;
}).overrideScope
(
nixpkgs.lib.composeManyExtensions [
pyproject-build-systems.overlays.default
overlay
pyprojectOverrides
]
);
in
{
tailwindcss = pkgs.tailwindcss;
default = pythonSet.mkVirtualEnv "hello-world-env" workspace.deps.default;
docker = pkgs.dockerTools.buildLayeredImage {
name = "audiobookrequest";
config = {
Cmd = ["alembic upgrade heads && fastapi run --port $ABR_APP__PORT"];
ExposedPorts = {
"8000/tcp" = {};
};
Env = [
"ABR_APP__PORT=8000"
];
};
};
});
devShells = forEachSupportedSystem ({ pkgs }: {
default = pkgs.mkShell {
venvDir = ".venv";
packages = with pkgs; [ python311 nodejs_23 sqlite nodePackages.browser-sync ] ++
packages = with pkgs; [ python311 nodejs_23 sqlite nodePackages.browser-sync uv ] ++
(with pkgs.python311Packages; [
pip
venvShellHook
]);
};
+37 -4
View File
@@ -1,11 +1,41 @@
[project]
name = "audiobookrequest"
name = "AudioBookRequest"
version = "1.2.2"
requires-python = ">= 3.11"
dynamic = ["version"]
dependencies = [
"aiohttp==3.11.13",
"alembic==1.15.1",
"argon2-cffi==23.1.0",
"argon2-cffi-bindings==21.2.0",
"fastapi==0.115.11",
"fastapi-cli==0.0.7",
"itsdangerous==2.2.0",
"jinja2==3.1.6",
"jinja2-fragments==1.8.0",
"pydantic==2.10.6",
"pydantic-settings==2.8.1",
"pydantic-core==2.27.2",
"pyjwt==2.10.1",
"pyright==1.1.396",
"pytailwindcss==0.2.0",
"sqlmodel==0.0.23",
"terminaltables==3.1.10",
"torrent-parser==0.4.1",
"typer==0.15.2",
"urllib3==2.3.0",
"rapidfuzz>=3.12.2",
"python-multipart>=0.0.20",
]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.sdist]
include = ["app/*.py", "alembic/"]
[tool.uv]
package = false
[tool.pyright]
include = ["**/*.py"]
@@ -15,3 +45,6 @@ ignore = []
typeCheckingMode = "strict"
reportUnknownParameterType = true
reportMissingParameterType = true
[dependency-groups]
dev = ["black>=25.1.0"]
-71
View File
@@ -1,71 +0,0 @@
aiohappyeyeballs==2.5.0
aiohttp==3.11.13
aiosignal==1.3.2
alembic==1.15.1
annotated-types==0.7.0
anyio==4.8.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
attrs==25.1.0
black==25.1.0
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
click==8.1.8
colorclass==2.2.2
dnspython==2.7.0
docopt==0.6.2
email_validator==2.2.0
fastapi==0.115.11
fastapi-cli==0.0.7
frozenlist==1.5.0
greenlet==3.1.1
h11==0.14.0
httpcore==1.0.7
httptools==0.6.4
httpx==0.28.1
idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.6
jinja2_fragments==1.8.0
Mako==1.3.9
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mdurl==0.1.2
multidict==6.1.0
mypy-extensions==1.0.0
nodeenv==1.9.1
packaging==24.2
pathspec==0.12.1
pip-upgrader==1.4.15
platformdirs==4.3.6
propcache==0.3.0
pycparser==2.22
pydantic==2.10.6
pydantic-settings==2.8.1
pydantic_core==2.27.2
Pygments==2.19.1
PyJWT==2.10.1
pyright==1.1.396
pytailwindcss==0.2.0
python-dotenv==1.0.1
python-multipart==0.0.20
PyYAML==6.0.2
RapidFuzz==3.12.2
rich==13.9.4
rich-toolkit==0.13.2
shellingham==1.5.4
sniffio==1.3.1
SQLAlchemy==2.0.38
sqlmodel==0.0.23
starlette==0.46.0
terminaltables==3.1.10
torrent-parser==0.4.1
typer==0.15.2
typing_extensions==4.12.2
urllib3==2.3.0
uvicorn==0.34.0
uvloop==0.21.0
watchfiles==1.0.4
websockets==15.0.1
yarl==1.18.3
Generated
+1394
View File
File diff suppressed because it is too large Load Diff