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