summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/furo/default.nix
blob: f676a9b0b979f34833adc295895b2bcadbdd64cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
  stdenv,
  lib,
  nodejs,
  buildNpmPackage,
  buildPythonPackage,
  runCommand,
  fetchFromGitHub,
  fetchPypi,
  flit-core,
  accessible-pygments,
  beautifulsoup4,
  pygments,
  sphinx,
  sphinx-basic-ng,
  unzip,
}:

let
  pname = "furo";
  version = "2025.07.19";
  # version on pypi doesn't have month & day padded with 0
  pypiVersion =
    let
      versionComponents = lib.strings.splitString "." version;
      dropLeadingZero = lib.strings.removePrefix "0";
    in
    # year
    (lib.lists.elemAt versionComponents 0)
    + "."
    # month
    + (dropLeadingZero (lib.lists.elemAt versionComponents 1))
    + "."
    # day
    + (dropLeadingZero (lib.lists.elemAt versionComponents 2));

  src = fetchFromGitHub {
    owner = "pradyunsg";
    repo = "furo";
    tag = version;
    hash = "sha256-pIF5zrh5YbkuSkrateEB/tDULSNbeVn2Qx+Fm3nOYGE=";
  };

  web-bin =
    let
      web-bin-src = fetchPypi {
        inherit pname;
        version = pypiVersion;
        format = "wheel";
        dist = "py3";
        python = "py3";
        hash = "sha256-veqGmCLf0rSU6oTAlzk3410Vda8Ii2chopx/eHityeM=";
      };
    in
    runCommand "${pname}-web-bin"
      {
        nativeBuildInputs = [ unzip ];
      }
      ''
        mkdir $out
        unzip ${web-bin-src}
        cp -rv furo/theme/furo/static/{scripts,styles} $out/
      '';

  web-native = buildNpmPackage {
    pname = "${pname}-web";
    inherit version src;

    npmDepsHash = "sha256-dcdHoyqF9zC/eKtEqMho7TK2E1KIvoXo0iwSPTzj+Kw=";

    installPhase = ''
      pushd src/furo/theme/furo/static
      mkdir $out
      cp -rv scripts styles $out/
      popd
    '';
  };

  web = if (lib.meta.availableOn stdenv.buildPlatform nodejs) then web-native else web-bin;
in

buildPythonPackage rec {
  inherit pname version src;
  pyproject = true;

  postPatch = ''
    # build with boring backend that does not manage a node env
    substituteInPlace pyproject.toml \
      --replace-fail "sphinx-theme-builder >= 0.2.0a10" "flit-core" \
      --replace-fail "sphinx_theme_builder" "flit_core.buildapi"

    pushd src/furo/theme/furo/static
    cp -rv ${web}/{scripts,styles} .
    popd
  '';

  build-system = [ flit-core ];

  pythonRelaxDeps = [ "sphinx" ];

  dependencies = [
    accessible-pygments
    beautifulsoup4
    pygments
    sphinx
    sphinx-basic-ng
  ];

  pythonImportsCheck = [ "furo" ];

  passthru = {
    inherit web;
  };

  meta = {
    description = "Clean customizable documentation theme for Sphinx";
    homepage = "https://github.com/pradyunsg/furo";
    changelog = "https://github.com/pradyunsg/furo/blob/${version}/docs/changelog.md";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ Luflosi ];
  };
}