1{ stdenv, buildPythonPackage, fetchFromGitHub, pytest, nose, libarchive, glibcLocales
2# unrar is non-free software
3, useUnrar ? false, unrar
4}:
5
6assert useUnrar -> unrar != null;
7assert !useUnrar -> libarchive != null;
8
9buildPythonPackage rec {
10 pname = "rarfile";
11 version = "3.0";
12
13 src = fetchFromGitHub {
14 owner = "markokr";
15 repo = "rarfile";
16 rev = "rarfile_3_0";
17 sha256 = "07yliz6p1bxzhipnrgz133gl8laic35gl4rqfay7f1vc384ch7sn";
18 };
19 buildInputs = [ pytest nose glibcLocales ];
20
21 prePatch = ''
22 substituteInPlace rarfile.py \
23 '' + (if useUnrar then
24 ''--replace 'UNRAR_TOOL = "unrar"' "UNRAR_TOOL = \"${unrar}/bin/unrar\""
25 ''
26 else
27 ''--replace 'ALT_TOOL = "bsdtar"' "ALT_TOOL = \"${libarchive}/bin/bsdtar\""
28 '')
29 + ''
30 '';
31 # the tests only work with the standard unrar package
32 doCheck = useUnrar;
33 LC_ALL = "en_US.UTF-8";
34 checkPhase = ''
35 py.test test -k "not test_printdir"
36 '';
37
38 meta = with stdenv.lib; {
39 description = "RAR archive reader for Python";
40 homepage = https://github.com/markokr/rarfile;
41 license = licenses.isc;
42 };
43}