1{ lib
2, stdenv
3, buildPythonPackage
4, fetchFromGitHub
5, cargo
6, hypothesis
7, libiconv
8, pytestCheckHook
9, python
10, pythonOlder
11, pyyaml
12, rustPlatform
13, rustc
14, setuptools-rust
15, setuptools-scm
16, typing-extensions
17, typing-inspect
18}:
19
20buildPythonPackage rec {
21 pname = "libcst";
22 version = "0.4.9";
23 format = "pyproject";
24
25 disabled = pythonOlder "3.7";
26
27 src = fetchFromGitHub {
28 owner = "instagram";
29 repo = pname;
30 rev = "refs/tags/v${version}";
31 hash = "sha256-ikddvKsvXMNHMfA9jUhvyiDXII0tTs/rE97IGI/azgA=";
32 };
33
34 cargoDeps = rustPlatform.fetchCargoTarball {
35 inherit src;
36 sourceRoot = "source/${cargoRoot}";
37 name = "${pname}-${version}";
38 hash = "sha256-FWQGv3E5X+VEnTYD0uKN6W4USth8EQlEGbYgUAWZ5EQ=";
39 };
40
41 cargoRoot = "native";
42
43 postPatch = ''
44 # test try to format files, which isn't necessary when consuming releases
45 sed -i libcst/codegen/generate.py \
46 -e '/ufmt/c\ pass'
47 '';
48
49 SETUPTOOLS_SCM_PRETEND_VERSION = version;
50
51 nativeBuildInputs = [
52 setuptools-rust
53 setuptools-scm
54 rustPlatform.cargoSetupHook
55 cargo
56 rustc
57 ];
58
59 buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
60
61 propagatedBuildInputs = [
62 typing-extensions
63 typing-inspect
64 pyyaml
65 ];
66
67 nativeCheckInputs = [
68 hypothesis
69 pytestCheckHook
70 ];
71
72 preCheck = ''
73 ${python.interpreter} -m libcst.codegen.generate visitors
74 ${python.interpreter} -m libcst.codegen.generate return_types
75 # Can't run all tests due to circular dependency on hypothesmith -> libcst
76 rm -r {libcst/tests,libcst/codegen/tests,libcst/m*/tests}
77 '';
78
79 disabledTests = [
80 # No files are generated
81 "test_codemod_formatter_error_input"
82 ];
83
84 pythonImportsCheck = [
85 "libcst"
86 ];
87
88 meta = with lib; {
89 description = "Concrete Syntax Tree (CST) parser and serializer library for Python";
90 homepage = "https://github.com/Instagram/libcst";
91 license = with licenses; [ mit asl20 psfl ];
92 maintainers = with maintainers; [ SuperSandro2000 ];
93 };
94}