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