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 rustPlatform,
16 rustc,
17 setuptools-rust,
18 setuptools-scm,
19 typing-extensions,
20 typing-inspect,
21 ufmt,
22}:
23
24buildPythonPackage rec {
25 pname = "libcst";
26 version = "1.5.1";
27 pyproject = true;
28
29 disabled = pythonOlder "3.9";
30
31 src = fetchFromGitHub {
32 owner = "Instagram";
33 repo = "LibCST";
34 rev = "refs/tags/v${version}";
35 hash = "sha256-fveY4ah94pv9ImI36MNrrxTpZv/DtLb45pXm67L8/GA=";
36 };
37
38 cargoDeps = rustPlatform.fetchCargoTarball {
39 inherit src;
40 sourceRoot = "${src.name}/${cargoRoot}";
41 name = "${pname}-${version}";
42 hash = "sha256-TcWGW1RF2se89BtvQHO+4BwnRMZ8ygqO3du9Q/gZi/Q=";
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 typing-extensions
62 typing-inspect
63 pyyaml
64 ];
65
66 nativeCheckInputs = [
67 hypothesmith
68 pytestCheckHook
69 ufmt
70 ];
71
72 preCheck = ''
73 # import from $out instead
74 rm libcst/__init__.py
75 '';
76
77 disabledTests = [
78 # FIXME package pyre-test
79 "TypeInferenceProviderTest"
80 # we'd need to run `python -m libcst.codegen.generate all` but shouldn't modify $out
81 "test_codegen_clean_visitor_functions"
82 ];
83
84 # circular dependency on hypothesmith and ufmt
85 doCheck = false;
86
87 passthru.tests = {
88 pytest = libcst.overridePythonAttrs { doCheck = true; };
89 };
90
91 pythonImportsCheck = [ "libcst" ];
92
93 meta = {
94 description = "Concrete Syntax Tree (CST) parser and serializer library for Python";
95 homepage = "https://github.com/Instagram/LibCST";
96 changelog = "https://github.com/Instagram/LibCST/blob/v${version}/CHANGELOG.md";
97 license = with lib.licenses; [
98 mit
99 asl20
100 psfl
101 ];
102 maintainers = with lib.maintainers; [ dotlambda ];
103 };
104}