From b04f959916523361e56b51b645fcedcdcbc11207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Fri, 30 Aug 2024 16:48:43 -0700 Subject: [PATCH 1/4] python312Packages.libcst: move tests to passthru.tests That resolves their circular dependency on hypothesmith and ufmt. --- .../python-modules/libcst/default.nix | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/pkgs/development/python-modules/libcst/default.nix b/pkgs/development/python-modules/libcst/default.nix index ab176fd8252f..447848d8afab 100644 --- a/pkgs/development/python-modules/libcst/default.nix +++ b/pkgs/development/python-modules/libcst/default.nix @@ -3,8 +3,10 @@ stdenv, buildPythonPackage, fetchFromGitHub, + callPackage, cargo, - hypothesis, + hypothesmith, + libcst, libiconv, pytestCheckHook, python, @@ -16,6 +18,7 @@ setuptools-scm, typing-extensions, typing-inspect, + ufmt, }: buildPythonPackage rec { @@ -41,12 +44,6 @@ buildPythonPackage rec { cargoRoot = "native"; - postPatch = '' - # avoid infinite recursion by not formatting the release files - substituteInPlace libcst/codegen/generate.py \ - --replace '"ufmt"' '"true"' - ''; - nativeBuildInputs = [ setuptools-rust setuptools-scm @@ -64,26 +61,30 @@ buildPythonPackage rec { ]; nativeCheckInputs = [ - hypothesis + hypothesmith pytestCheckHook + ufmt ]; preCheck = '' - # otherwise import libcst.native fails - cp build/lib.*/libcst/native.* libcst/ - - ${python.interpreter} -m libcst.codegen.generate visitors - ${python.interpreter} -m libcst.codegen.generate return_types - - # Can't run all tests due to circular dependency on hypothesmith -> libcst - rm -r {libcst/tests,libcst/codegen/tests,libcst/m*/tests} + # import from $out instead + rm libcst/__init__.py ''; disabledTests = [ - # No files are generated - "test_codemod_formatter_error_input" + # FIXME package pyre-test + "TypeInferenceProviderTest" + # we'd need to run `python -m libcst.codegen.generate all` but shouldn't modify $out + "test_codegen_clean_visitor_functions" ]; + # circular dependency on hypothesmith and ufmt + doCheck = false; + + passthru.tests = { + pytest = libcst.overridePythonAttrs { doCheck = true; }; + }; + pythonImportsCheck = [ "libcst" ]; meta = with lib; { From 05d6ab0713ddace728b727bcd53618999ca126d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Fri, 30 Aug 2024 17:23:05 -0700 Subject: [PATCH 2/4] python312Packages.libcst: modernize --- .../development/python-modules/libcst/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/development/python-modules/libcst/default.nix b/pkgs/development/python-modules/libcst/default.nix index 447848d8afab..da17f0fb968f 100644 --- a/pkgs/development/python-modules/libcst/default.nix +++ b/pkgs/development/python-modules/libcst/default.nix @@ -24,9 +24,9 @@ buildPythonPackage rec { pname = "libcst"; version = "1.4.0"; - format = "pyproject"; + pyproject = true; - disabled = pythonOlder "3.7"; + disabled = pythonOlder "3.9"; src = fetchFromGitHub { owner = "instagram"; @@ -44,9 +44,12 @@ buildPythonPackage rec { cargoRoot = "native"; - nativeBuildInputs = [ + build-system = [ setuptools-rust setuptools-scm + ]; + + nativeBuildInputs = [ rustPlatform.cargoSetupHook cargo rustc @@ -54,7 +57,7 @@ buildPythonPackage rec { buildInputs = lib.optionals stdenv.isDarwin [ libiconv ]; - propagatedBuildInputs = [ + dependencies = [ typing-extensions typing-inspect pyyaml @@ -87,11 +90,11 @@ buildPythonPackage rec { pythonImportsCheck = [ "libcst" ]; - meta = with lib; { + meta = { description = "Concrete Syntax Tree (CST) parser and serializer library for Python"; homepage = "https://github.com/Instagram/libcst"; changelog = "https://github.com/Instagram/LibCST/blob/v${version}/CHANGELOG.md"; - license = with licenses; [ + license = with lib.licenses; [ mit asl20 psfl From e08e458fb8b686703e7122852aa7bfa3164496e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Fri, 30 Aug 2024 17:26:53 -0700 Subject: [PATCH 3/4] python312Packages.libcst: add dotlambda to maintainers --- pkgs/development/python-modules/libcst/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/libcst/default.nix b/pkgs/development/python-modules/libcst/default.nix index da17f0fb968f..a0863f9bfd1c 100644 --- a/pkgs/development/python-modules/libcst/default.nix +++ b/pkgs/development/python-modules/libcst/default.nix @@ -99,6 +99,6 @@ buildPythonPackage rec { asl20 psfl ]; - maintainers = [ ]; + maintainers = with lib.maintainers; [ dotlambda ]; }; } From 0e0552e789bd6f8da243096cb12bb60fe2ad9f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Fri, 30 Aug 2024 17:34:02 -0700 Subject: [PATCH 4/4] python312Packages.hypothesmith: modernize --- .../python-modules/hypothesmith/default.nix | 33 +++---- .../hypothesmith/remove-black.patch | 87 ------------------- 2 files changed, 10 insertions(+), 110 deletions(-) delete mode 100644 pkgs/development/python-modules/hypothesmith/remove-black.patch diff --git a/pkgs/development/python-modules/hypothesmith/default.nix b/pkgs/development/python-modules/hypothesmith/default.nix index a69c0c08214e..c53c3c2e3670 100644 --- a/pkgs/development/python-modules/hypothesmith/default.nix +++ b/pkgs/development/python-modules/hypothesmith/default.nix @@ -1,5 +1,6 @@ { lib, + black, buildPythonPackage, fetchPypi, hypothesis, @@ -7,59 +8,45 @@ libcst, parso, pytestCheckHook, + pytest-cov-stub, pytest-xdist, pythonOlder, + setuptools, }: buildPythonPackage rec { pname = "hypothesmith"; version = "0.3.3"; - format = "setuptools"; + pyproject = true; - disabled = pythonOlder "3.8"; + disabled = pythonOlder "3.9"; src = fetchPypi { inherit pname version; hash = "sha256-lsFIAtbI6F2JdSZBdoeNtUso0u2SH9v+3C5rjOPIFxY="; }; - patches = [ ./remove-black.patch ]; + build-system = [ setuptools ]; - postPatch = '' - substituteInPlace setup.py \ - --replace "lark-parser" "lark" - - substituteInPlace tox.ini \ - --replace "--cov=hypothesmith" "" \ - --replace "--cov-branch" "" \ - --replace "--cov-report=term-missing:skip-covered" "" \ - --replace "--cov-fail-under=100" "" - ''; - - propagatedBuildInputs = [ + dependencies = [ hypothesis lark libcst ]; nativeCheckInputs = [ + black parso pytestCheckHook + pytest-cov-stub pytest-xdist ]; - pytestFlagsArray = [ "-v" ]; - disabledTests = [ - # https://github.com/Zac-HD/hypothesmith/issues/21 + # super slow "test_source_code_from_libcst_node_type" ]; - disabledTestPaths = [ - # missing blib2to3 - "tests/test_syntactic.py" - ]; - pythonImportsCheck = [ "hypothesmith" ]; meta = with lib; { diff --git a/pkgs/development/python-modules/hypothesmith/remove-black.patch b/pkgs/development/python-modules/hypothesmith/remove-black.patch deleted file mode 100644 index d37222ef4b2c..000000000000 --- a/pkgs/development/python-modules/hypothesmith/remove-black.patch +++ /dev/null @@ -1,87 +0,0 @@ -diff --git a/tests/test_cst.py b/tests/test_cst.py -index 8532240..bdba2d7 100644 ---- a/tests/test_cst.py -+++ b/tests/test_cst.py -@@ -3,7 +3,6 @@ import ast - from inspect import isabstract - from operator import attrgetter - --import black - import libcst - import parso - import pytest -@@ -51,27 +50,6 @@ def test_ast_unparse_from_nodes(source_code): - assert ast.dump(first) == ast.dump(second) - - --@pytest.mark.xfail --@example("A\u2592", black.Mode()) --@given( -- source_code=hypothesmith.from_node(), -- mode=st.builds( -- black.Mode, -- line_length=st.just(88) | st.integers(0, 200), -- string_normalization=st.booleans(), -- is_pyi=st.booleans(), -- ), --) --def test_black_autoformatter_from_nodes(source_code, mode): -- try: -- result = black.format_file_contents(source_code, fast=False, mode=mode) -- except black.NothingChanged: -- pass -- else: -- with pytest.raises(black.NothingChanged): -- black.format_file_contents(result, fast=False, mode=mode) -- -- - @given(source_code=hypothesmith.from_node()) - def test_from_node_always_compilable(source_code): - compile(source_code, "", "exec") -diff --git a/tests/test_syntactic.py b/tests/test_syntactic.py -index 7fe9835..17c4f7c 100644 ---- a/tests/test_syntactic.py -+++ b/tests/test_syntactic.py -@@ -3,7 +3,6 @@ import ast - import io - import tokenize - --import black - import blib2to3 - import parso - import pytest -@@ -58,34 +57,6 @@ def test_ast_unparse_from_grammar(source_code): - assert ast.dump(first) == ast.dump(second) - - --@example("\\", black.Mode()) --@example("A#\r#", black.Mode()) --@given( -- source_code=hypothesmith.from_grammar(), -- mode=st.builds( -- black.Mode, -- line_length=st.just(88) | st.integers(0, 200), -- string_normalization=st.booleans(), -- is_pyi=st.booleans(), -- ), --) --def test_black_autoformatter_from_grammar(source_code, mode): -- try: -- result = black.format_file_contents(source_code, fast=False, mode=mode) -- except black.NothingChanged: -- pass -- except blib2to3.pgen2.tokenize.TokenError: -- # Fails to tokenise e.g. "\\", though compile("\\", "", "exec") works. -- # See https://github.com/psf/black/issues/1012 -- reject() -- except black.InvalidInput: -- # e.g. "A#\r#", see https://github.com/psf/black/issues/970 -- reject() -- else: -- with pytest.raises(black.NothingChanged): -- black.format_file_contents(result, fast=False, mode=mode) -- -- - @given(source_code=hypothesmith.from_grammar("eval_input")) - def test_eval_input_generation(source_code): - compile(source_code, filename="", mode="eval")