1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pytestCheckHook,
6 libarchive,
7 pythonOlder,
8 setuptools,
9 # unrar is non-free software
10 useUnrar ? false,
11 unrar,
12}:
13
14assert useUnrar -> unrar != null;
15assert !useUnrar -> libarchive != null;
16
17buildPythonPackage rec {
18 pname = "rarfile";
19 version = "4.2";
20 pyproject = true;
21
22 disabled = pythonOlder "3.6";
23
24 src = fetchFromGitHub {
25 owner = "markokr";
26 repo = "rarfile";
27 rev = "refs/tags/v${version}";
28 hash = "sha256-ZiwD2LG25fMd4Z+QWsh/x3ceG5QRBH4s/TZDwMnfpNI=";
29 };
30
31 prePatch =
32 ''
33 substituteInPlace rarfile.py \
34 ''
35 + (
36 if useUnrar then
37 ''
38 --replace 'UNRAR_TOOL = "unrar"' "UNRAR_TOOL = \"${unrar}/bin/unrar\""
39 ''
40 else
41 ''
42 --replace 'ALT_TOOL = "bsdtar"' "ALT_TOOL = \"${libarchive}/bin/bsdtar\""
43 ''
44 )
45 + "";
46
47 build-system = [ setuptools ];
48
49 nativeCheckInputs = [ pytestCheckHook ];
50
51 # The tests only work with the standard unrar package
52 doCheck = useUnrar;
53
54 pythonImportsCheck = [ "rarfile" ];
55
56 meta = with lib; {
57 description = "RAR archive reader for Python";
58 homepage = "https://github.com/markokr/rarfile";
59 changelog = "https://github.com/markokr/rarfile/releases/tag/v${version}";
60 license = licenses.isc;
61 maintainers = [ ];
62 };
63}