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 echo "CREATE DATABASE django;" | postgres --single -E postgres
fi 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 postgres
layout pdm
export PROJECT_DIR=$(pwd) export PROJECT_DIR=$(pwd)
export WEBPORT=$(($RANDOM + 1100)) export WEBPORT=$(($RANDOM + 1100))
export PGPORT=$(($WEBPORT + 100)) export PGPORT=$(($WEBPORT + 100))

View File

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

1
.gitignore vendored
View File

@ -181,3 +181,4 @@ db_data
.direnv .direnv
/result /result
/static/ /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 tasks["test"]=test
update (){ update (){
poetry update --lock pdm update
} }
descriptions["update"]="Update the dependencies." descriptions["update"]="Update the dependencies."
tasks["update"]=update tasks["update"]=update

View File

@ -73,13 +73,27 @@
"type": "github" "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": { "poetry2nix": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2", "flake-utils": "flake-utils_2",
"nix-github-actions": "nix-github-actions", "nix-github-actions": "nix-github-actions",
"nixpkgs": [ "nixpkgs": "nixpkgs_2"
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1693051011, "lastModified": 1693051011,
@ -90,9 +104,8 @@
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "id": "poetry2nix",
"repo": "poetry2nix", "type": "indirect"
"type": "github"
} }
}, },
"root": { "root": {

View File

@ -3,53 +3,40 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = { self, nixpkgs, flake-utils, poetry2nix }: outputs = { self, nixpkgs, flake-utils, poetry2nix }:
{ (flake-utils.lib.eachDefaultSystem (system:
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:
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ self.overlays.default ];
}; };
ld_path = pkgs.lib.makeLibraryPath [ pkgs.openssl ];
inventory = pkgs.stdenv.mkDerivation { inventory = pkgs.stdenv.mkDerivation {
src = ./.; src = ./.;
version = "latest"; version = "latest";
pname = "network-inventory"; pname = "network-inventory";
buildInputs = [
pkgs.pdm
pkgs.python310
];
installPhase = '' installPhase = ''
mkdir -p $out runHook preInstall
cp -r ./src $out/code 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 in
rec { rec {
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
buildInputs = [ buildInputs = [
pkgs.inventoryDevEnv pkgs.pdm
pkgs.poetry
pkgs.python310Packages.pip
pkgs.overmind pkgs.overmind
pkgs.postgresql_15 pkgs.postgresql_15
pkgs.python310
(pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}") (pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}")
]; ];
PYTHON_KEYRING_BACKEND = "keyring.backends.fail.Keyring"; PYTHON_KEYRING_BACKEND = "keyring.backends.fail.Keyring";
@ -66,7 +53,7 @@
doCheck = true; doCheck = true;
name = "lint"; name = "lint";
src = ./.; src = ./.;
checkInputs = [ pkgs.inventoryDevEnv ]; checkInputs = [ pkgs.pdm ];
checkPhase = '' checkPhase = ''
mkdir -p $out mkdir -p $out
pylint --rc-file pyproject.toml -j 0 -E src/ pylint --rc-file pyproject.toml -j 0 -E src/
@ -82,7 +69,7 @@
doCheck = true; doCheck = true;
name = "test"; name = "test";
src = ./.; src = ./.;
checkInputs = [ pkgs.inventoryDevEnv pkgs.postgresql_15 pkgs.overmind ]; checkInputs = [ pkgs.pdm pkgs.postgresql_15 pkgs.overmind ];
checkPhase = '' checkPhase = ''
mkdir -p $out mkdir -p $out
pytest --ds=network_inventory.settings.ram_test \ pytest --ds=network_inventory.settings.ram_test \
@ -94,7 +81,6 @@
}; };
}; };
packages = { packages = {
venv = pkgs.inventoryEnv;
container = pkgs.dockerTools.buildImage { container = pkgs.dockerTools.buildImage {
name = "network-inventory"; name = "network-inventory";
tag = "latest"; tag = "latest";
@ -102,9 +88,11 @@
copyToRoot = pkgs.buildEnv { copyToRoot = pkgs.buildEnv {
name = "image-root"; name = "image-root";
paths = [ paths = [
inventory
pkgs.bashInteractive pkgs.bashInteractive
pkgs.coreutils pkgs.coreutils
inventory pkgs.pdm
pkgs.python310
(pkgs.writeShellScriptBin "start-inventory" '' (pkgs.writeShellScriptBin "start-inventory" ''
if [ -f .first_run ]; then if [ -f .first_run ]; then
sleep 2 sleep 2
@ -138,12 +126,14 @@
]; ];
}; };
config = { config = {
Cmd = [ "start-inventory" ]; Cmd = [ "pdm run start-inventory" ];
WorkingDir = "/code"; WorkingDir = "/code";
Env = [ Env = [
"POSTGRES_DB=network_inventory" "POSTGRES_DB=network_inventory"
"DJANGO_SETTINGS_MODULE=network_inventory.settings.production" "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] [tool.pylint]
max-line-length = 88 max-line-length = 88
load-plugins = [ load-plugins = [
"pylint_django", "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] [tool.mypy]
exclude = [ exclude = [
"tests/", "tests/",
@ -54,35 +69,20 @@ module = [
] ]
ignore_missing_imports = true ignore_missing_imports = true
[tool.poetry.group.main.dependencies] [tool.pdm.dev-dependencies]
python = "^3.9" linting = [
Django = "^4.1.3" "black>=23.7.0",
django-crispy-forms = "^1.14.0" "django-stubs>=4.2.3",
django-filter = "^23.2" "mypy>=1.5.1",
django-floppyforms = "^1.9.0" "pylint>=2.17.5",
django-guardian = "^2.4.0" "pylint-django>=2.5.3",
django-htmx = "^1.13.0" ]
django-model-utils = "^4.2.0" test = [
django-nested-admin = "^4.0.2" "coverage>=7.3.0",
django-tables2 = "^2.4.1" "mixer>=7.2.2",
gunicorn = "^20.1.0" "pytest>=7.4.0",
psycopg2-binary = "^2.9.5" "pytest-cov>=4.1.0",
PyYAML = "^6.0" "pytest-django>=4.5.2",
"pytest-xdist>=3.3.1",
[tool.poetry.group.dev.dependencies] "python-lsp-server>=1.7.4",
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"