From 617c5fcaf012b3f8278c1bf8642c40396cf916fa Mon Sep 17 00:00:00 2001 From: Charles Strahan Date: Sun, 12 Jul 2015 17:46:44 -0400 Subject: [PATCH] rainbowstream: purify (close #8791) This obviates the need for `cc` to be available at run time. --- .../python-modules/rainbowstream/image.patch | 18 ++++++++++++++++++ pkgs/top-level/python-packages.nix | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 pkgs/development/python-modules/rainbowstream/image.patch diff --git a/pkgs/development/python-modules/rainbowstream/image.patch b/pkgs/development/python-modules/rainbowstream/image.patch new file mode 100644 index 00000000000..215152ae4fb --- /dev/null +++ b/pkgs/development/python-modules/rainbowstream/image.patch @@ -0,0 +1,18 @@ +diff --git a/rainbowstream/c_image.py b/rainbowstream/c_image.py +index f050150..a0fb77d 100644 +--- a/rainbowstream/c_image.py ++++ b/rainbowstream/c_image.py +@@ -12,11 +12,7 @@ def call_c(): + """ + Call the C program for converting RGB to Ansi colors + """ +- library = expanduser('~/.image.so') +- sauce = join(dirname(__file__), 'image.c') +- if not exists(library) or getmtime(sauce) > getmtime(library): +- build = "cc -fPIC -shared -o %s %s" % (library, sauce) +- os.system(build + " >/dev/null 2>&1") ++ library = '@CLIB@' + image_c = ctypes.cdll.LoadLibrary(library) + image_c.init() + return image_c.rgb_to_ansi + diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 08c0cfee510..222b9150511 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -7505,11 +7505,23 @@ let doCheck = false; + patches = [ + ../development/python-modules/rainbowstream/image.patch + ]; + + postPatch = '' + clib=$out/${python.sitePackages}/rainbowstream/image.so + substituteInPlace rainbowstream/c_image.py \ + --replace @CLIB@ $clib + ''; + preBuild = '' export LC_ALL="en_US.UTF-8" ''; postInstall = '' + mkdir -p $out/lib + cc -fPIC -shared -o $clib rainbowstream/image.c for prog in "$out/bin/"*; do wrapProgram "$prog" \ --prefix PYTHONPATH : "$PYTHONPATH"