Merge pull request #307098 from r-ryantm/auto-update/cilium-cli
[NixPkgs.git] / pkgs / development / python-modules / libcst / default.nix
blobd1fc8ec75e33c92b1175e208f438cc109ce3259e
1 { lib
2 , stdenv
3 , buildPythonPackage
4 , fetchFromGitHub
5 , fetchpatch
6 , cargo
7 , hypothesis
8 , libiconv
9 , pytestCheckHook
10 , python
11 , pythonOlder
12 , pyyaml
13 , rustPlatform
14 , rustc
15 , setuptools-rust
16 , setuptools-scm
17 , typing-extensions
18 , typing-inspect
21 buildPythonPackage rec {
22   pname = "libcst";
23   version = "1.1.0";
24   format = "pyproject";
26   disabled = pythonOlder "3.7";
28   src = fetchFromGitHub {
29     owner = "instagram";
30     repo = "libcst";
31     rev = "refs/tags/v${version}";
32     hash = "sha256-kFs7edBWz0GRbgbLDmtpUVi5R+6mYXsJSvceOoPW9ck=";
33   };
35   cargoDeps = rustPlatform.fetchCargoTarball {
36     inherit src;
37     sourceRoot = "${src.name}/${cargoRoot}";
38     name = "${pname}-${version}";
39     hash = "sha256-fhaHiz64NH6S61fSXj4gNxxcuB+ECxWSSmG5StiFr1k=";
40   };
42   cargoRoot = "native";
44   patches = [
45     # https://github.com/Instagram/LibCST/pull/1042
46     (fetchpatch {
47       name = "remove-distutils.patch";
48       url = "https://github.com/Instagram/LibCST/commit/a6834aa0e6eb78e41549fd1087d7ba60ca4dd237.patch";
49       hash = "sha256-lyIXJhm4UMwdCOso6McDslIvtK7Ar8sF5Zy7qo1nicQ=";
50     })
51   ];
53   postPatch = ''
54     # avoid infinite recursion by not formatting the release files
55     substituteInPlace libcst/codegen/generate.py \
56       --replace '"ufmt"' '"true"'
57   '';
59   nativeBuildInputs = [
60     setuptools-rust
61     setuptools-scm
62     rustPlatform.cargoSetupHook
63     cargo
64     rustc
65   ];
67   buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
69   propagatedBuildInputs = [
70     typing-extensions
71     typing-inspect
72     pyyaml
73   ];
75   nativeCheckInputs = [
76     hypothesis
77     pytestCheckHook
78   ];
80   preCheck = ''
81     # otherwise import libcst.native fails
82     cp build/lib.*/libcst/native.* libcst/
84     ${python.interpreter} -m libcst.codegen.generate visitors
85     ${python.interpreter} -m libcst.codegen.generate return_types
87     # Can't run all tests due to circular dependency on hypothesmith -> libcst
88     rm -r {libcst/tests,libcst/codegen/tests,libcst/m*/tests}
89   '';
91   disabledTests = [
92     # No files are generated
93     "test_codemod_formatter_error_input"
94   ];
96   pythonImportsCheck = [
97     "libcst"
98   ];
100   meta = with lib; {
101     description = "Concrete Syntax Tree (CST) parser and serializer library for Python";
102     homepage = "https://github.com/Instagram/libcst";
103     changelog = "https://github.com/Instagram/LibCST/blob/v${version}/CHANGELOG.md";
104     license = with licenses; [ mit asl20 psfl ];
105     maintainers = with maintainers; [ ];
106   };