@@ -37,6 +37,7 @@
;;; Copyright © 2020 Holger Peters <holger.peters@posteo.de>
;;; Copyright © 2020 Noisytoot <noisytoot@gmail.com>
;;; Copyright © 2020 Edouard Klein <edk@beaver-labs.com>
+;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -4029,3 +4030,69 @@ request/response web apps to larger, grown applications.")
than 326,000 known user-agents. Users can pick a random one, or select one
based on filters.")
(license license:expat)))
+
+(define-public python-httptools
+ (package
+ (name "python-httptools")
+ (version "0.1.1")
+ (source (origin
+ ;; The PyPI release does not contain tests.
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/MagicStack/httptools.git")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "0g08128x2ixsiwrzskxc6c8ymgzs39wbzr5mhy0mjk30q9pqqv77"))))
+ (build-system python-build-system)
+ (arguments
+ `(#:phases
+ (modify-phases %standard-phases
+ (add-after 'unpack 'patch-hardcoded-paths
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let ((http-parser (assoc-ref inputs "http-parser")))
+ (substitute* "httptools/parser/cparser.pxd"
+ (("\\.\\./\\.\\./vendor/http-parser/http_parser\\.h")
+ (string-append http-parser "/include/http_parser.h"))))
+ #t))
+ (add-after 'patch-hardcoded-paths 'disable-failing-test
+ (lambda _
+ ;; TestResponseParser.test_parser_response_1 fails every time.
+ ;; We force it to pass to avoid patching it out.
+ (substitute* "tests/test_parser.py"
+ (("data received after completed connection")
+ "invalid constant string"))
+ #t))
+ (replace 'build
+ (lambda _
+ (invoke "python" "setup.py" "build_ext"
+ "--use-system-http-parser" "--inplace")
+ #t))
+ (replace 'install
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((out (assoc-ref outputs "out")))
+ (invoke "python" "setup.py" "install"
+ (string-append "--prefix=" out)
+ "--single-version-externally-managed" "--root=/"
+ "--skip-build")
+ #t)))
+ (replace 'check
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((out (assoc-ref outputs "out")))
+ (invoke "pytest")
+ #t))))))
+ (inputs
+ `(("http-parser" ,http-parser)))
+ (native-inputs
+ `(("python-cython" ,python-cython-0.29.14)
+ ("python-pytest" ,python-pytest)))
+ (home-page
+ "https://github.com/MagicStack/httptools")
+ (synopsis
+ "Python bindings for the NodeJS HTTP parser")
+ (description
+ "@code{python-httptools} creates Python bindings for the
+NodeJS HTTP parser. It provides collection of framework independent HTTP
+protocol utils.")
+ (license license:expat)))
@@ -20278,3 +20278,14 @@ permissively licensed, async/await-native I/O library for Python.")
;; Choice of either license.
(license (list license:expat license:asl2.0))))
+;; This is only needed for python-httptools.
+(define-public python-cython-0.29.14
+ (package (inherit python-cython)
+ (version "0.29.14")
+ (source
+ (origin
+ (method url-fetch)
+ (uri (pypi-uri "Cython" version))
+ (sha256
+ (base32
+ "050lh336791yl76krn44zm2dz00mlhpb26bk9fq9wcfh0f3vpmp4"))))))