2021-03-09 03:18:52 +00:00
|
|
|
{ lib
|
2022-04-27 09:35:20 +00:00
|
|
|
, stdenv
|
2021-03-09 03:18:52 +00:00
|
|
|
, buildPythonPackage
|
|
|
|
, fetchFromGitHub
|
2024-01-13 08:15:51 +00:00
|
|
|
, fetchpatch
|
2023-05-24 13:37:59 +00:00
|
|
|
, cargo
|
2021-03-09 03:18:52 +00:00
|
|
|
, hypothesis
|
2022-04-27 09:35:20 +00:00
|
|
|
, libiconv
|
2022-03-30 09:31:56 +00:00
|
|
|
, pytestCheckHook
|
2021-06-28 23:13:55 +00:00
|
|
|
, python
|
|
|
|
, pythonOlder
|
2021-03-09 03:18:52 +00:00
|
|
|
, pyyaml
|
2022-04-15 01:41:22 +00:00
|
|
|
, rustPlatform
|
2023-05-24 13:37:59 +00:00
|
|
|
, rustc
|
2022-04-15 01:41:22 +00:00
|
|
|
, setuptools-rust
|
2021-12-26 17:43:05 +00:00
|
|
|
, setuptools-scm
|
2021-03-09 03:18:52 +00:00
|
|
|
, typing-extensions
|
|
|
|
, typing-inspect
|
|
|
|
}:
|
2020-10-11 12:50:04 +00:00
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "libcst";
|
2023-10-19 13:55:26 +00:00
|
|
|
version = "1.1.0";
|
2022-04-15 01:41:22 +00:00
|
|
|
format = "pyproject";
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2022-06-26 10:26:21 +00:00
|
|
|
disabled = pythonOlder "3.7";
|
2020-10-11 12:50:04 +00:00
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "instagram";
|
2023-08-04 22:07:22 +00:00
|
|
|
repo = "libcst";
|
2022-08-12 12:06:08 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2023-10-19 13:55:26 +00:00
|
|
|
hash = "sha256-kFs7edBWz0GRbgbLDmtpUVi5R+6mYXsJSvceOoPW9ck=";
|
2020-10-11 12:50:04 +00:00
|
|
|
};
|
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
|
|
|
inherit src;
|
2023-08-04 22:07:22 +00:00
|
|
|
sourceRoot = "${src.name}/${cargoRoot}";
|
2022-04-15 01:41:22 +00:00
|
|
|
name = "${pname}-${version}";
|
2023-10-19 13:55:26 +00:00
|
|
|
hash = "sha256-fhaHiz64NH6S61fSXj4gNxxcuB+ECxWSSmG5StiFr1k=";
|
2022-04-15 01:41:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cargoRoot = "native";
|
|
|
|
|
2024-01-13 08:15:51 +00:00
|
|
|
patches = [
|
|
|
|
# https://github.com/Instagram/LibCST/pull/1042
|
|
|
|
(fetchpatch {
|
|
|
|
name = "remove-distutils.patch";
|
|
|
|
url = "https://github.com/Instagram/LibCST/commit/a6834aa0e6eb78e41549fd1087d7ba60ca4dd237.patch";
|
|
|
|
hash = "sha256-lyIXJhm4UMwdCOso6McDslIvtK7Ar8sF5Zy7qo1nicQ=";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2021-12-26 17:43:05 +00:00
|
|
|
postPatch = ''
|
2023-08-04 22:07:22 +00:00
|
|
|
# avoid infinite recursion by not formatting the release files
|
|
|
|
substituteInPlace libcst/codegen/generate.py \
|
|
|
|
--replace '"ufmt"' '"true"'
|
2021-12-26 17:43:05 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2022-04-15 01:41:22 +00:00
|
|
|
setuptools-rust
|
2021-12-26 17:43:05 +00:00
|
|
|
setuptools-scm
|
2022-04-15 01:41:22 +00:00
|
|
|
rustPlatform.cargoSetupHook
|
2023-05-24 13:37:59 +00:00
|
|
|
cargo
|
|
|
|
rustc
|
|
|
|
];
|
2021-12-26 17:43:05 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
propagatedBuildInputs = [
|
|
|
|
typing-extensions
|
|
|
|
typing-inspect
|
|
|
|
pyyaml
|
|
|
|
];
|
2021-03-09 03:18:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [
|
2022-06-26 10:26:21 +00:00
|
|
|
hypothesis
|
2022-03-30 09:31:56 +00:00
|
|
|
pytestCheckHook
|
2021-06-28 23:13:55 +00:00
|
|
|
];
|
2020-10-16 20:44:37 +00:00
|
|
|
|
|
|
|
preCheck = ''
|
2023-08-04 22:07:22 +00:00
|
|
|
# otherwise import libcst.native fails
|
|
|
|
cp build/lib.*/libcst/native.* libcst/
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
${python.interpreter} -m libcst.codegen.generate visitors
|
|
|
|
${python.interpreter} -m libcst.codegen.generate return_types
|
2023-08-04 22:07:22 +00:00
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
# Can't run all tests due to circular dependency on hypothesmith -> libcst
|
|
|
|
rm -r {libcst/tests,libcst/codegen/tests,libcst/m*/tests}
|
2020-10-16 20:44:37 +00:00
|
|
|
'';
|
2020-10-11 12:50:04 +00:00
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
disabledTests = [
|
|
|
|
# No files are generated
|
|
|
|
"test_codemod_formatter_error_input"
|
|
|
|
];
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
pythonImportsCheck = [
|
|
|
|
"libcst"
|
|
|
|
];
|
2020-10-11 12:50:04 +00:00
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
meta = with lib; {
|
2021-06-28 23:13:55 +00:00
|
|
|
description = "Concrete Syntax Tree (CST) parser and serializer library for Python";
|
2020-10-16 20:44:37 +00:00
|
|
|
homepage = "https://github.com/Instagram/libcst";
|
2023-10-19 13:55:26 +00:00
|
|
|
changelog = "https://github.com/Instagram/LibCST/blob/v${version}/CHANGELOG.md";
|
2020-10-16 20:44:37 +00:00
|
|
|
license = with licenses; [ mit asl20 psfl ];
|
2023-08-04 22:07:22 +00:00
|
|
|
maintainers = with maintainers; [ ];
|
2020-10-11 12:50:04 +00:00
|
|
|
};
|
|
|
|
}
|