Remove poetry2nix

This commit is contained in:
Andreas Zweili 2023-08-28 12:57:32 +02:00
parent 796c8f3744
commit b92ef58c82
7 changed files with 106 additions and 196 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
[*.sh]
indent_style = space
indent_size = 4
[.envrc]
indent_style = space
indent_size = 4

30
.envrc
View File

@ -10,8 +10,36 @@ layout_postgres() {
fi
}
layout postgres
layout_poetry() {
PYPROJECT_TOML="${PYPROJECT_TOML:-pyproject.toml}"
if [[ ! -f "$PYPROJECT_TOML" ]]; then
log_status "No pyproject.toml found. Executing \`poetry init\` to create a \`$PYPROJECT_TOML\` first."
poetry init
fi
if [[ -d ".venv" ]]; then
VIRTUAL_ENV="$(pwd)/.venv"
else
VIRTUAL_ENV=$(
poetry env info --path 2>/dev/null
true
)
fi
if [[ -z $VIRTUAL_ENV || ! -d $VIRTUAL_ENV ]]; then
log_status "No virtual environment exists. Executing \`poetry install\` to create one."
poetry install
VIRTUAL_ENV=$(poetry env info --path)
fi
PATH_add "$VIRTUAL_ENV/bin"
export POETRY_ACTIVE=1
export VIRTUAL_ENV
}
layout poetry
export PROJECT_DIR=$(pwd)
export WEBPORT=$(($RANDOM + 1100))
export PGPORT=$(($WEBPORT + 100))
watch_file "$PGDATA/postgresql.conf"

View File

@ -13,6 +13,9 @@ jobs:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Environment setup
run: nix develop --command bash -c "poetry install"
- name: Test
run: |
nix flake check -L -j auto
run: nix develop --command bash -c "dev test"
env:
PROJECT_DIR: ${{ github.workspace }}

30
dev.sh
View File

@ -104,7 +104,6 @@ clean () {
descriptions["clean"]="Reset the project to a fresh state including the database."
tasks["clean"]=clean
cleanall() {
git clean -xdf
}
@ -117,16 +116,28 @@ debug () {
descriptions["debug"]="Run the tests and drop into the debugger on failure."
tasks["debug"]=debug
check (){
nix flake check
lint() {
echo "Running pylint"
poetry run \
pylint \
--rc-file="$PROJECT_DIR/pyproject.toml" \
-j 0 \
-E "$PROJECT_DIR/src"
echo "Running mypy"
poetry run \
mypy --config-file="$PROJECT_DIR/pyproject.toml" "$PROJECT_DIR/src"
}
descriptions["check"]="Run the linter and tests."
tasks["check"]=check
descriptions["lint"]="Run the linters against the src directory."
tasks["lint"]=lint
test() {
export DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test
pytest -nauto --nomigrations --cov-config="$PROJECT_DIR/.coveragerc" --cov-report=html "$PROJECT_DIR/src"
DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test poetry run \
pytest \
-nauto \
--nomigrations \
--cov-config="$PROJECT_DIR/.coveragerc" \
--cov-report=html \
"$PROJECT_DIR/src"
}
descriptions["test"]="Run the tests in the RAM DB and write a coverage report."
tasks["test"]=test
@ -140,8 +151,7 @@ tasks["update"]=update
# only one task at a time
if [ $# != 1 ]; then
printf "usage: dev <task_name>\n\n"
for task in "${!tasks[@]}"
do
for task in "${!tasks[@]}"; do
echo "$task - ${descriptions[$task]}"
done

View File

@ -18,45 +18,6 @@
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1687709756,
"narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nix-github-actions": {
"inputs": {
"nixpkgs": [
"poetry2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1690856737,
"narHash": "sha256-34M2FVqiKCwFUmA8/LnwxnQYiFZIL4QiNqQ1NRQX2gs=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "bfeb681177b5128d061ebbef7ded30bc21a3f135",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-github-actions",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1688918189,
@ -73,33 +34,10 @@
"type": "github"
}
},
"poetry2nix": {
"inputs": {
"flake-utils": "flake-utils_2",
"nix-github-actions": "nix-github-actions",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1693051011,
"narHash": "sha256-HNbuVCS/Fnl1YZOjBk9/MlIem+wM8fvIzTH0CVQrLSQ=",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "5b3a5151cf212021ff8d424f215fb030e4ff2837",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "poetry2nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"poetry2nix": "poetry2nix"
"nixpkgs": "nixpkgs"
}
},
"systems": {
@ -116,21 +54,6 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

114
flake.nix
View File

@ -3,34 +3,12 @@
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:
outputs = { self, nixpkgs, flake-utils }:
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
inventory = pkgs.stdenv.mkDerivation {
src = ./.;
@ -45,9 +23,7 @@
rec {
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.inventoryDevEnv
pkgs.poetry
pkgs.python310Packages.pip
pkgs.overmind
pkgs.postgresql_15
(pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}")
@ -57,44 +33,7 @@
export DJANGO_SETTINGS_MODULE=network_inventory.settings.local
'';
};
checks = {
lint = pkgs.stdenv.mkDerivation {
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontInstall = true;
doCheck = true;
name = "lint";
src = ./.;
checkInputs = [ pkgs.inventoryDevEnv ];
checkPhase = ''
mkdir -p $out
pylint --rc-file pyproject.toml -j 0 -E src/
cd src/ && mypy --config-file=../pyproject.toml .
'';
DJANGO_SETTINGS_MODULE = "network_inventory.settings.ram_test";
};
tests = pkgs.stdenv.mkDerivation {
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontInstall = true;
doCheck = true;
name = "test";
src = ./.;
checkInputs = [ pkgs.inventoryDevEnv pkgs.postgresql_15 pkgs.overmind ];
checkPhase = ''
mkdir -p $out
pytest --ds=network_inventory.settings.ram_test \
-nauto \
--nomigrations \
--cov=./src \
./src
'';
};
};
packages = {
venv = pkgs.inventoryEnv;
container = pkgs.dockerTools.buildImage {
name = "network-inventory";
tag = "latest";
@ -102,38 +41,39 @@
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
inventory
pkgs.bashInteractive
pkgs.coreutils
inventory
pkgs.poetry
(pkgs.writeShellScriptBin "start-inventory" ''
if [ -f .first_run ]; then
sleep 2
${pkgs.inventoryEnv}/bin/django-admin collectstatic --noinput
${pkgs.inventoryEnv}/bin/django-admin makemigrations
${pkgs.inventoryEnv}/bin/django-admin migrate
django-admin collectstatic --noinput
django-admin makemigrations
django-admin migrate
else
${pkgs.inventoryEnv}/bin/django-admin collectstatic --noinput
${pkgs.inventoryEnv}/bin/django-admin makemigrations backups
${pkgs.inventoryEnv}/bin/django-admin makemigrations computers
${pkgs.inventoryEnv}/bin/django-admin makemigrations core
${pkgs.inventoryEnv}/bin/django-admin makemigrations customers
${pkgs.inventoryEnv}/bin/django-admin makemigrations devices
${pkgs.inventoryEnv}/bin/django-admin makemigrations licenses
${pkgs.inventoryEnv}/bin/django-admin makemigrations nets
${pkgs.inventoryEnv}/bin/django-admin makemigrations softwares
${pkgs.inventoryEnv}/bin/django-admin makemigrations users
${pkgs.inventoryEnv}/bin/django-admin makemigrations
${pkgs.inventoryEnv}/bin/django-admin migrate
${pkgs.inventoryEnv}/bin/django-admin loaddata backups
${pkgs.inventoryEnv}/bin/django-admin loaddata computers
${pkgs.inventoryEnv}/bin/django-admin loaddata core
${pkgs.inventoryEnv}/bin/django-admin loaddata devices
${pkgs.inventoryEnv}/bin/django-admin loaddata nets
${pkgs.inventoryEnv}/bin/django-admin loaddata softwares
${pkgs.inventoryEnv}/bin/django-admin shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@example.com', 'password')"
django-admin collectstatic --noinput
django-admin makemigrations backups
django-admin makemigrations computers
django-admin makemigrations core
django-admin makemigrations customers
django-admin makemigrations devices
django-admin makemigrations licenses
django-admin makemigrations nets
django-admin makemigrations softwares
django-admin makemigrations users
django-admin makemigrations
django-admin migrate
django-admin loaddata backups
django-admin loaddata computers
django-admin loaddata core
django-admin loaddata devices
django-admin loaddata nets
django-admin loaddata softwares
django-admin shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@example.com', 'password')"
touch .first_run
fi
${pkgs.inventoryEnv}/bin/gunicorn network_inventory.wsgi:application --reload --bind 0.0.0.0:8000 --workers 3
gunicorn network_inventory.wsgi:application --reload --bind 0.0.0.0:8000 --workers 3
'')
];
};

View File

@ -13,7 +13,6 @@ license = "GPLv3"
packages = [
{ include = "src" },
]
virtualenvs.in-project = true
[tool.mypy]
exclude = [