Patchwork [1/1] gnu: Add python-betamax.

login
register
mail settings
Submitter Leo Famulari
Date Oct. 16, 2016, 5:17 p.m.
Message ID <7303d3cdb0afa8e657039a476c4a13048ecb748e.1476638200.git.leo@famulari.name>
Download mbox | patch
Permalink /patch/16563/
State New
Headers show

Comments

Leo Famulari - Oct. 16, 2016, 5:17 p.m.
This is a build time dependency of python-requests-toolbelt when using
Python 3.5.

* gnu/packages/python.scm (python-betamax, python2-betamax): New variables.
---
 gnu/packages/python.scm | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
Marius Bakke - Oct. 16, 2016, 8:22 p.m.
Leo Famulari <leo@famulari.name> writes:

> This is a build time dependency of python-requests-toolbelt when using
> Python 3.5.
>
> * gnu/packages/python.scm (python-betamax, python2-betamax): New variables.

This LGTM, but I have a couple of off-topic remarks.

The requests input/reference was a bit odd and seems to come from a
python PTH [0] file that sets up the full path to the requests library:

$ cat /gnu/store/q73wijsf2bapjwy47z5cl3jbq9rydmim-python-betamax-0.8.0/lib/python3.4/site-packages/python-betamax-0.8.0.pth
import sys; sys.__plen = len(sys.path)
./betamax-0.8.0-py3.4.egg
/gnu/store/4yxlmdi684axj11dxf0d905dfrjvaw3s-python-requests-2.9.1/lib/python3.4/site-packages/requests-2.9.1-py3.4.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)

I can load this from a pure environment:

$ ./pre-inst-env guix environment --container --pure --ad-hoc python-betamax python
[...]
[env]# python3 -c 'import betamax'
[env]#

Doing the same when applied to wip-python-build-system results in:

[env]# python3 -c 'import betamax'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/gnu/store/gs8jwja6d5k96l32v5psvxwzvwk61rll-profile/lib/python3.4/site-packages/betamax/__init__.py", line 13, in <module>
    from .decorator import use_cassette
  File "/gnu/store/gs8jwja6d5k96l32v5psvxwzvwk61rll-profile/lib/python3.4/site-packages/betamax/decorator.py", line 4, in <module>
    import requests
ImportError: No module named 'requests'

Can we leverage this mechanism instead of propagating everything? Are
there any drawbacks to doing that?

I'll have to do some more investigation around how those .pth files are
created, but food for thought. Perhaps it only works with eggs?

0: https://docs.python.org/3/library/site.html
Hartmut Goebel - Oct. 17, 2016, 8:56 a.m.
Am 16.10.2016 um 19:17 schrieb Leo Famulari:
> +    (inputs
> +     `(("python-requests" ,python-requests)))

These need to be propagated inputs, In assume. Please refer to the
Python packaging guide which was updated some days ago.
Hartmut Goebel - Oct. 17, 2016, 12:03 p.m.
Am 16.10.2016 um 22:22 schrieb Marius Bakke:
> Can we leverage this mechanism instead of propagating everything? Are
> there any drawbacks to doing that?

propagating all inputs is the correct way for two reasons:

a) In Python only *one* version of a module can but used within an
environment [*] So you will end up in troubles if some packages list
different (incompatible) versions of a package in a .pth file. You will
have a lot of fun debugging this. (It took me one or two hours to
understand what's going on there, and being one of the core developers
of PyInstaller I'm quite skilled regarding all these import mechanisms
in Python.)

b) guix will not be able to tack these dependencies AFAIK, see
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20765


[*] One can install different version of a module, but this is rarely
used and not supported when installing via pip.

> I'll have to do some more investigation around how those .pth files are
> created, but food for thought. Perhaps it only works with eggs?

They are very archaic and work with normal module, too.
https://docs.python.org/3/library/site.html

You may want to compare the results of (I suggest using a virtual
environment for the tests):

easy_install py==1.4.31
python ./setup.py easy_install py==1.4.31
python ./setup.py install py==1.4.31
python ./setup.py install --root=/ py==1.4.31

BTW: Just today I discovered nasty problems with namespace packages
under python2. So I still need to do some recherché.

Patch

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 07ac017..3e3ff9e 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -11068,3 +11068,35 @@  with an associated set of resolve methods that know how to fetch data.")
 provide extendible implementations of common aspects of a cloud so that you can
 focus on building massively scalable web applications.")
     (license license:expat)))
+
+(define-public python-betamax
+  (package
+    (name "python-betamax")
+    (version "0.8.0")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (pypi-uri "betamax" version))
+        (sha256
+         (base32
+          "18f8v5gng3j773jlbbzx4rg1i4y2zw3m2l1zpmbvp8bh5a2q1i42"))))
+    (build-system python-build-system)
+    (arguments
+     '(;; Many tests fail because they require networking.
+       #:tests? #f))
+    (inputs
+     `(("python-requests" ,python-requests)))
+    (home-page "https://github.com/sigmavirus24/betamax")
+    (synopsis "Record HTTP interactions with python-requests")
+    (description "Betamax will record your test suite's HTTP interactions and
+replay them during future tests.  It is designed to work with python-requests.")
+    (license license:expat)
+    (properties `((python2-variant . ,(delay python2-betamax))))))
+
+(define-public python2-betamax
+  (let ((base (package-with-python2 (strip-python2-variant python-betamax))))
+    (package
+      (inherit base)
+      (native-inputs
+       `(("python2-setuptools" ,python2-setuptools)
+         ,@(package-native-inputs base))))))