1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 callPackage,
7 cargo,
8 hypothesmith,
9 libcst,
10 libiconv,
11 pytestCheckHook,
12 python,
13 pythonOlder,
14 pyyaml,
15 pyyaml-ft,
16 rustPlatform,
17 rustc,
18 setuptools-rust,
19 setuptools-scm,
20 ufmt,
21}:
22
23buildPythonPackage rec {
24 pname = "libcst";
25 version = "1.8.2";
26 pyproject = true;
27
28 src = fetchFromGitHub {
29 owner = "Instagram";
30 repo = "LibCST";
31 tag = "v${version}";
32 hash = "sha256-DsbigWFFYmucOa3uHdvMFd4nbgwKLzRVdI6SjUUdFWU=";
33 };
34
35 cargoDeps = rustPlatform.fetchCargoVendor {
36 inherit
37 pname
38 version
39 src
40 cargoRoot
41 ;
42 hash = "sha256-dwqs9hXedX1jJJANyZ8nMivZBrLcMAi5NMJscW3oSdQ=";
43 };
44
45 cargoRoot = "native";
46
47 build-system = [
48 setuptools-rust
49 setuptools-scm
50 ];
51
52 nativeBuildInputs = [
53 rustPlatform.cargoSetupHook
54 cargo
55 rustc
56 ];
57
58 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
59
60 dependencies = [
61 (if pythonOlder "3.13" then pyyaml else pyyaml-ft)
62 ];
63
64 nativeCheckInputs = [
65 hypothesmith
66 pytestCheckHook
67 ufmt
68 ];
69
70 preCheck = ''
71 # import from $out instead
72 rm libcst/__init__.py
73 '';
74
75 disabledTests = [
76 # FIXME package pyre-test
77 "TypeInferenceProviderTest"
78 # we'd need to run `python -m libcst.codegen.generate all` but shouldn't modify $out
79 "test_codegen_clean_visitor_functions"
80 ];
81
82 # circular dependency on hypothesmith and ufmt
83 doCheck = false;
84
85 passthru.tests = {
86 pytest = libcst.overridePythonAttrs { doCheck = true; };
87 };
88
89 pythonImportsCheck = [ "libcst" ];
90
91 meta = {
92 description = "Concrete Syntax Tree (CST) parser and serializer library for Python";
93 homepage = "https://github.com/Instagram/LibCST";
94 changelog = "https://github.com/Instagram/LibCST/blob/${src.tag}/CHANGELOG.md";
95 license = with lib.licenses; [
96 mit
97 asl20
98 psfl
99 ];
100 maintainers = with lib.maintainers; [ dotlambda ];
101 };
102}