Skip to content

Commit d765424

Browse files
committed
Add Nix package for PyQGIS API Documentation builder
1 parent c81f710 commit d765424

File tree

4 files changed

+271
-1
lines changed

4 files changed

+271
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ You can either:
2525

2626
* export the PYTHONPATH yourself
2727
* export your QGIS build directory with ``export QGIS_BUILD_DIR=~/dev/QGIS/build``
28-
* or provide QGIS build directory as argument to the script: ``./build-docs.sh -qgis-build-dir ~/dev/QGIS/build``
28+
* or provide QGIS build directory as argument to the script: ``./scripts/build-docs.sh -qgis-build-dir ~/dev/QGIS/build``
2929

3030
### Testing & development
3131

flake.lock

+96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
description = "PyQGIS API Documentation";
3+
4+
# nixConfig = {
5+
# extra-substituters = [ "https://example.cachix.org" ];
6+
# extra-trusted-public-keys = [ "example.cachix.org-1:xxxx=" ];
7+
# };
8+
9+
inputs = {
10+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
11+
12+
# TODO: https://github.com/qgis/QGIS-Sysadmin-Documentation/issues/129
13+
qgisLatest = {
14+
url = "github:imincik/QGIS/nix-package-release-3_42";
15+
};
16+
};
17+
18+
outputs = inputs@{ self, nixpkgs, qgisLatest }:
19+
20+
let
21+
# Flake system
22+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
23+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
24+
nixpkgsFor = forAllSystems (system: import nixpkgs {
25+
inherit system;
26+
config.allowUnfree = true;
27+
});
28+
29+
in
30+
{
31+
#
32+
### PACKAGES
33+
#
34+
35+
packages = forAllSystems (system:
36+
let
37+
pkgs = nixpkgsFor.${system};
38+
39+
in
40+
{
41+
website-latest = pkgs.callPackage ./package.nix {
42+
qgis = inputs.qgisLatest.packages.${system}.qgis;
43+
qgisRepo = qgisLatest;
44+
};
45+
});
46+
47+
48+
#
49+
### APPS
50+
#
51+
52+
apps = forAllSystems (system:
53+
let
54+
pkgs = nixpkgsFor.${system};
55+
inherit (nixpkgs) lib;
56+
57+
wwwLauncherLatest = pkgs.writeShellApplication {
58+
name = "website";
59+
runtimeInputs = [ pkgs.python3 ];
60+
text = ''
61+
exec ${lib.getExe pkgs.python3} \
62+
-m http.server 8000 \
63+
-d ${self.packages.${system}.website-latest}/
64+
'';
65+
};
66+
67+
in
68+
rec {
69+
website-latest = {
70+
type = "app";
71+
program = "${wwwLauncherLatest}/bin/website";
72+
};
73+
default = website-latest;
74+
});
75+
76+
77+
#
78+
### SHELLS
79+
#
80+
81+
devShells = forAllSystems (system:
82+
let
83+
pkgs = nixpkgsFor.${system};
84+
85+
in
86+
{
87+
# Development environment
88+
default = pkgs.mkShell {
89+
buildInputs = [ ];
90+
};
91+
});
92+
};
93+
}

package.nix

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{ lib
2+
, stdenv
3+
4+
, qgis
5+
, qgisRepo
6+
7+
, graphviz
8+
, python3
9+
, python3Packages
10+
}:
11+
12+
let
13+
qgisPackage = qgis.override { withServer = true; };
14+
qgisVersion =
15+
let
16+
v = builtins.splitVersion qgis.version;
17+
in
18+
builtins.elemAt v 0 + "." + builtins.elemAt v 1;
19+
in
20+
21+
stdenv.mkDerivation {
22+
name = "qgis-website-${qgisVersion}";
23+
24+
src = lib.cleanSourceWith {
25+
src = ./.;
26+
filter = (
27+
path: type: (builtins.all (x: x != baseNameOf path) [
28+
".git"
29+
".github"
30+
"flake.nix"
31+
"flake.lock"
32+
"package.nix"
33+
"result"
34+
])
35+
);
36+
};
37+
38+
dontWrapQtApps = true;
39+
40+
buildInputs = with python3Packages; [
41+
graphviz
42+
python3
43+
sphinx
44+
sphinx-rtd-theme
45+
] ++ qgisPackage.passthru.unwrapped.pythonBuildInputs;
46+
47+
# Taken from
48+
# https://github.com/qgis/pyqgis-api-docs-builder/blob/main/scripts/build-docs.sh
49+
buildPhase = ''
50+
# Build RST
51+
mkdir -p temp
52+
for module in "3d" "analysis" "core" "gui" "server"; do
53+
CLASS_MAP_FILE="temp/$module/class_map.yaml"
54+
mkdir -p temp/$module
55+
cp ${qgisRepo}/python/$module/class_map.yaml $CLASS_MAP_FILE
56+
done
57+
58+
export PYTHONPATH=$PYTHONPATH:${qgisPackage}/share/qgis/python
59+
60+
python3 ./scripts/make_api_rst.py --version ${qgisVersion}
61+
62+
mkdir api/${qgisVersion}/_static
63+
cp -r _static/css api/${qgisVersion}/_static/css
64+
cp -r _static/js api/${qgisVersion}/_static/js
65+
cp _static/*.rst api/${qgisVersion}/
66+
67+
# Build HTML
68+
sed -r "s/__QGIS_VERSION__/${qgisVersion}/g;" conf.in.py > api/${qgisVersion}/conf.py
69+
sphinx-build -M html api/${qgisVersion} build/${qgisVersion} -T -j auto
70+
71+
# Move files around
72+
rm -rf build/${qgisVersion}/doctrees
73+
mv build/${qgisVersion}/html/* build/${qgisVersion}
74+
rm -rf build/${qgisVersion}/html
75+
'';
76+
77+
installPhase = ''
78+
mkdir -p $out
79+
cp -r build/* $out/
80+
'';
81+
}

0 commit comments

Comments
 (0)