1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 astor,
12 dill,
13 filelock,
14
15 # tests
16 pytestCheckHook,
17 torch,
18 pythonAtLeast,
19}:
20
21buildPythonPackage rec {
22 pname = "depyf";
23 version = "0.19.0";
24 pyproject = true;
25
26 src = fetchFromGitHub {
27 owner = "thuml";
28 repo = "depyf";
29 tag = "v${version}";
30 hash = "sha256-AGM5Pm0hhqOX9CY7dFijZLqhWmY7xnmKWakh4MUtOMs=";
31 };
32
33 # don't try to read git commit
34 postPatch = ''
35 substituteInPlace setup.py \
36 --replace-fail 'commit_id = get_git_commit_id()' 'commit_id = None'
37 '';
38
39 build-system = [
40 setuptools
41 ];
42
43 dependencies = [
44 astor
45 dill
46 filelock
47 ];
48
49 nativeCheckInputs = [
50 pytestCheckHook
51 torch
52 ];
53
54 disabledTestPaths = [
55 # if self.quitting: raise BdbQuit
56 # E bdb.BdbQuit
57 "tests/test_pytorch/test_pytorch.py"
58 ]
59 ++ lib.optionals (pythonAtLeast "3.13") [
60
61 # depyf.decompiler.DecompilationError: DecompilationError: Failed to decompile instruction ...
62 # NotImplementedError: Unsupported instruction: LOAD_FAST_LOAD_FAST
63 "tests/test_code_owner.py"
64 ]
65 ++ lib.optionals stdenv.hostPlatform.isDarwin [
66 # E torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
67 # E CppCompileError: C++ compile error
68 "tests/test_pytorch/test_export.py"
69 "tests/test_pytorch/test_logging.py"
70 "tests/test_pytorch/test_simple_graph.py"
71 ];
72
73 # All remaining tests fail with:
74 # ValueError: invalid literal for int() with base 10: 'L1'
75 doCheck = !(pythonAtLeast "3.13");
76
77 pythonImportsCheck = [ "depyf" ];
78
79 meta = {
80 description = "Decompile python functions, from bytecode to source code";
81 homepage = "https://github.com/thuml/depyf";
82 changelog = "https://github.com/thuml/depyf/releases/tag/v${version}";
83 license = lib.licenses.mit;
84 };
85}