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