summary refs log tree commit diff
path: root/pkgs/tools/networking/httpie/default.nix
blob: a0e2b8e01cc12db0fa216a54387d9e6bd07fae64 (plain) (blame)
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
{ stdenv, fetchFromGitHub, python3Packages, docutils, }:

python3Packages.buildPythonApplication rec {
  pname = "httpie";
  version = "2.0.0";

  src = fetchFromGitHub {
    owner = "jakubroztocil";
    repo = "httpie";
    rev = version;
    sha256 = "0d0rsn5i973l9y0ws3xmnzaw4jwxdlryyjbasnlddph5mvkf7dq0";
  };

  outputs = [ "out" "doc" "man" ];

  propagatedBuildInputs = with python3Packages; [ pygments requests setuptools ];
  dontUseSetuptoolsCheck = true;
  patches = [ ./strip-venv.patch ];

  checkInputs = with python3Packages; [
    mock
    pytest
    pytest-httpbin
    pytestCheckHook
  ];

  postInstall = ''
    # install completions
    install -Dm555 \
      extras/httpie-completion.bash \
      $out/share/bash-completion/completions/http.bash
    install -Dm555 \
      extras/httpie-completion.fish \
      $out/share/fish/vendor_completions.d/http.fish

    mkdir -p $man/share/man/man1

    docdir=$doc/share/doc/httpie
    mkdir -p $docdir/html

    cp AUTHORS.rst CHANGELOG.rst CONTRIBUTING.rst $docdir

    # helpfully, the readme has a `no-web` class to exclude
    # the parts that are not relevant for offline docs

    # this one build link was not marked however
    sed -e 's/^|build|//g' -i README.rst

    toHtml() {
      ${docutils}/bin/rst2html5 \
        --strip-elements-with-class=no-web \
        --title=http \
        --no-generator \
        --no-datestamp \
        --no-source-link \
        "$1" \
        "$2"
    }

    toHtml README.rst $docdir/html/index.html
    toHtml CHANGELOG.rst $docdir/html/CHANGELOG.html
    toHtml CONTRIBUTING.rst $docdir/html/CONTRIBUTING.html

    # change a few links to the local files
    substituteInPlace $docdir/html/index.html \
      --replace \
        'https://github.com/jakubroztocil/httpie/blob/master/CHANGELOG.rst' \
        "CHANGELOG.html" \
      --replace \
        'https://github.com/jakubroztocil/httpie/blob/master/CONTRIBUTING.rst' \
        "CONTRIBUTING.html"

    ${docutils}/bin/rst2man \
      --strip-elements-with-class=no-web \
      --title=http \
      --no-generator \
      --no-datestamp \
      --no-source-link \
      README.rst \
      $man/share/man/man1/http.1
  '';

  # the tests call rst2pseudoxml.py from docutils
  preCheck = ''
    export PATH=${docutils}/bin:$PATH
  '';

  meta = {
    description = "A command line HTTP client whose goal is to make CLI human-friendly";
    homepage = https://httpie.org/;
    license = stdenv.lib.licenses.bsd3;
    maintainers = with stdenv.lib.maintainers; [ antono relrod schneefux ];
  };
}