at 24.05-pre 2.2 kB view raw
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 = "1.1.0"; 23 format = "pyproject"; 24 25 disabled = pythonOlder "3.7"; 26 27 src = fetchFromGitHub { 28 owner = "instagram"; 29 repo = "libcst"; 30 rev = "refs/tags/v${version}"; 31 hash = "sha256-kFs7edBWz0GRbgbLDmtpUVi5R+6mYXsJSvceOoPW9ck="; 32 }; 33 34 cargoDeps = rustPlatform.fetchCargoTarball { 35 inherit src; 36 sourceRoot = "${src.name}/${cargoRoot}"; 37 name = "${pname}-${version}"; 38 hash = "sha256-fhaHiz64NH6S61fSXj4gNxxcuB+ECxWSSmG5StiFr1k="; 39 }; 40 41 cargoRoot = "native"; 42 43 postPatch = '' 44 # avoid infinite recursion by not formatting the release files 45 substituteInPlace libcst/codegen/generate.py \ 46 --replace '"ufmt"' '"true"' 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 # otherwise import libcst.native fails 74 cp build/lib.*/libcst/native.* libcst/ 75 76 ${python.interpreter} -m libcst.codegen.generate visitors 77 ${python.interpreter} -m libcst.codegen.generate return_types 78 79 # Can't run all tests due to circular dependency on hypothesmith -> libcst 80 rm -r {libcst/tests,libcst/codegen/tests,libcst/m*/tests} 81 ''; 82 83 disabledTests = [ 84 # No files are generated 85 "test_codemod_formatter_error_input" 86 ]; 87 88 pythonImportsCheck = [ 89 "libcst" 90 ]; 91 92 meta = with lib; { 93 description = "Concrete Syntax Tree (CST) parser and serializer library for Python"; 94 homepage = "https://github.com/Instagram/libcst"; 95 changelog = "https://github.com/Instagram/LibCST/blob/v${version}/CHANGELOG.md"; 96 license = with licenses; [ mit asl20 psfl ]; 97 maintainers = with maintainers; [ ]; 98 }; 99}