Replace poetry with pdm

In addition we stop using Nix managing the Python dependencies. It just takes
too much time to again and again fix the various problems.
This commit is contained in:
Andreas Zweili 2023-08-27 14:17:54 +02:00
parent 46b0c579e1
commit 45a2d9ed22
11 changed files with 1212 additions and 1417 deletions

23
.envrc
View File

@ -9,7 +9,30 @@ layout_postgres() {
echo "CREATE DATABASE django;" | postgres --single -E postgres
fi
}
layout_pdm() {
PYPROJECT_TOML="${PYPROJECT_TOML:-pyproject.toml}"
if [ ! -f "$PYPROJECT_TOML" ]; then
log_status "No pyproject.toml found. Executing \`pmd init\` to create a \`$PYPROJECT_TOML\` first."
pdm init --non-interactive --python "$(python3 --version 2>/dev/null | cut -d' ' -f2 | cut -d. -f1-2)"
fi
VIRTUAL_ENV=$(pdm venv list | grep "^\*" | awk -F" " '{print $3}')
if [ -z "$VIRTUAL_ENV" ] || [ ! -d "$VIRTUAL_ENV" ]; then
log_status "No virtual environment exists. Executing \`pdm info\` to create one."
pdm info
VIRTUAL_ENV=$(pdm venv list | grep "^\*" | awk -F" " '{print $3}')
fi
PATH_add "$VIRTUAL_ENV/bin"
export PDM_ACTIVE=1
export VIRTUAL_ENV
}
layout postgres
layout pdm
export PROJECT_DIR=$(pwd)
export WEBPORT=$(($RANDOM + 1100))
export PGPORT=$(($WEBPORT + 100))

View File

@ -32,7 +32,7 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Buid container
run: |
nix build .#container
nix build --no-sandbox .#container
docker load < result
- name: Log into registry

1
.gitignore vendored
View File

@ -181,3 +181,4 @@ db_data
.direnv
/result
/static/
.pdm-python

2
dev.sh
View File

@ -132,7 +132,7 @@ descriptions["test"]="Run the tests in the RAM DB and write a coverage report."
tasks["test"]=test
update (){
poetry update --lock
pdm update
}
descriptions["update"]="Update the dependencies."
tasks["update"]=update

View File

@ -73,13 +73,27 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1693003285,
"narHash": "sha256-5nm4yrEHKupjn62MibENtfqlP6pWcRTuSKrMiH9bLkc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5690c4271f2998c304a45c91a0aeb8fb69feaea7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"poetry2nix": {
"inputs": {
"flake-utils": "flake-utils_2",
"nix-github-actions": "nix-github-actions",
"nixpkgs": [
"nixpkgs"
]
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1693051011,
@ -90,9 +104,8 @@
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "poetry2nix",
"type": "github"
"id": "poetry2nix",
"type": "indirect"
}
},
"root": {

View File

@ -3,53 +3,40 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
{
overlays.default = nixpkgs.lib.composeManyExtensions [
poetry2nix.overlay
(final: prev: rec {
inventoryDevEnv = prev.poetry2nix.mkPoetryEnv
{
projectDir = ./.;
groups = [ "main" "dev" ];
};
inventoryPackage = prev.poetry2nix.mkPoetryApplication {
projectDir = ./.;
groups = [ "main" ];
};
inventoryEnv = inventoryPackage.dependencyEnv;
})
];
} // (flake-utils.lib.eachDefaultSystem (system:
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
ld_path = pkgs.lib.makeLibraryPath [ pkgs.openssl ];
inventory = pkgs.stdenv.mkDerivation {
src = ./.;
version = "latest";
pname = "network-inventory";
buildInputs = [
pkgs.pdm
pkgs.python310
];
installPhase = ''
mkdir -p $out
cp -r ./src $out/code
runHook preInstall
mkdir -p $out/code
pdm sync --production --no-editable --fail-fast
cp pdm.toml pdm.lock pyproject.toml $out/code/
cp -r .venv $out/code/.venv
cp -r ./src $out/code/src
runHook postInstall
'';
};
in
rec {
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.inventoryDevEnv
pkgs.poetry
pkgs.python310Packages.pip
pkgs.pdm
pkgs.overmind
pkgs.postgresql_15
pkgs.python310
(pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}")
];
PYTHON_KEYRING_BACKEND = "keyring.backends.fail.Keyring";
@ -66,7 +53,7 @@
doCheck = true;
name = "lint";
src = ./.;
checkInputs = [ pkgs.inventoryDevEnv ];
checkInputs = [ pkgs.pdm ];
checkPhase = ''
mkdir -p $out
pylint --rc-file pyproject.toml -j 0 -E src/
@ -82,7 +69,7 @@
doCheck = true;
name = "test";
src = ./.;
checkInputs = [ pkgs.inventoryDevEnv pkgs.postgresql_15 pkgs.overmind ];
checkInputs = [ pkgs.pdm pkgs.postgresql_15 pkgs.overmind ];
checkPhase = ''
mkdir -p $out
pytest --ds=network_inventory.settings.ram_test \
@ -94,7 +81,6 @@
};
};
packages = {
venv = pkgs.inventoryEnv;
container = pkgs.dockerTools.buildImage {
name = "network-inventory";
tag = "latest";
@ -102,9 +88,11 @@
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
inventory
pkgs.bashInteractive
pkgs.coreutils
inventory
pkgs.pdm
pkgs.python310
(pkgs.writeShellScriptBin "start-inventory" ''
if [ -f .first_run ]; then
sleep 2
@ -138,12 +126,14 @@
];
};
config = {
Cmd = [ "start-inventory" ];
Cmd = [ "pdm run start-inventory" ];
WorkingDir = "/code";
Env = [
"POSTGRES_DB=network_inventory"
"DJANGO_SETTINGS_MODULE=network_inventory.settings.production"
"PYTHONPATH=/lib/python3.10:/lib/python3.10/site-packages:/code"
"PYTHONPATH=$PYTHONPATH:/lib/python3.10:/lib/python3.10/site-packages:/code/src:/code/.venv/lib/python3.10/site-packages"
"PATH=$PATH:/bin:/code/.venv/bin"
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ld_path}"
];
};
};

1098
pdm.lock Normal file

File diff suppressed because it is too large Load Diff

2
pdm.toml Normal file
View File

@ -0,0 +1,2 @@
[venv]
backend = "venv"

1330
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +0,0 @@
[virtualenvs]
in-project = true

View File

@ -1,20 +1,35 @@
[project]
description = "A Django application designed to track IT inventory of multiple customers."
authors = [
{name = "Andreas Zweili", email = "andreas@zweili.ch"},
]
dependencies = [
"Django>=4.1.3",
"django-crispy-forms>=1.14,<2.0.0", # version 2 breaks tests
"django-filter>=23.2",
"django-floppyforms>=1.9.0",
"django-guardian>=2.4.0",
"django-htmx>=1.16.0",
"django-model-utils>=4.3.1",
"django-nested-admin>=4.0.2",
"django-tables2>=2.4.1,<2.6.0", # version 2.6 breaks tests
"gunicorn>=21.2.0",
"psycopg2-binary>=2.9.7",
"PyYAML>=6.0.1",
"setuptools>=68.1.2",
]
requires-python = ">=3.10"
license = {text = "GPLv3+"}
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
]
[tool.pylint]
max-line-length = 88
load-plugins = [
"pylint_django",
]
[tool.poetry]
name = "network_inventory"
version = "0.1.0"
description = ""
authors = ["Andreas Zweili <andreas@zweili.ch>"]
license = "GPLv3"
packages = [
{ include = "src" },
]
virtualenvs.in-project = true
[tool.mypy]
exclude = [
"tests/",
@ -54,35 +69,20 @@ module = [
]
ignore_missing_imports = true
[tool.poetry.group.main.dependencies]
python = "^3.9"
Django = "^4.1.3"
django-crispy-forms = "^1.14.0"
django-filter = "^23.2"
django-floppyforms = "^1.9.0"
django-guardian = "^2.4.0"
django-htmx = "^1.13.0"
django-model-utils = "^4.2.0"
django-nested-admin = "^4.0.2"
django-tables2 = "^2.4.1"
gunicorn = "^20.1.0"
psycopg2-binary = "^2.9.5"
PyYAML = "^6.0"
[tool.poetry.group.dev.dependencies]
black = "^22.10.0"
coverage = "^6.5.0"
mixer = "^7.2.2"
pylint = "^2.15.8"
pytest = "^7.2.0"
pytest-cov = "^4.0.0"
pytest-django = "^4.5.2"
pytest-xdist = "^3.1.0"
python-lsp-server = "^1.7.3"
mypy = "^1.4.1"
django-stubs = "^4.2.3"
pylint-django = "^2.5.3"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.pdm.dev-dependencies]
linting = [
"black>=23.7.0",
"django-stubs>=4.2.3",
"mypy>=1.5.1",
"pylint>=2.17.5",
"pylint-django>=2.5.3",
]
test = [
"coverage>=7.3.0",
"mixer>=7.2.2",
"pytest>=7.4.0",
"pytest-cov>=4.1.0",
"pytest-django>=4.5.2",
"pytest-xdist>=3.3.1",
"python-lsp-server>=1.7.4",
]