)]}'
{
  "commit": "990a0538e796f86dcb9a86e0276b7fdf1bf44c18",
  "tree": "50860250c5fa59e2c80eca1eb9a8f16565246ee3",
  "parents": [
    "9ff6ab7905f79079766c69ff8735542ebf9894bb"
  ],
  "author": {
    "name": "Zhongpeng Lin",
    "email": "zplin@uber.com",
    "time": "Fri Jul 19 00:49:29 2024 -0700"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Fri Jul 19 07:49:29 2024 +0000"
  },
  "message": "feat!: Following generation mode when generating test targets (#2044)\n\nWhen `python_generation_mode` is `project` or `file` , the generated\n`py_test` targets are consistent with `py_library`. However, when\n`python_generation_mode` is `package`, it becomes inconsistent: it\nrequires either `__test__` target or `__test__.py` file to generate\n`py_test` in package mode, otherwise it will fall back to file mode.\n\nThis PR relaxes this requirement with a new directive\n`gazelle:python_generation_mode_per_package_require_test_entry_point`.\nWhent it\u0027s set to false, Gazelle and generates one `py_test` target per\npackage in package mode even without entry points.\n\nThis allows people to use `gazelle:map_kind` to map `py_test` to a macro\nthat sets a default test runner, such as\n[rules_python_pytest](https://github.com/caseyduquettesc/rules_python_pytest)\nor [pytest-bazel](https://pypi.org/project/pytest-bazel/), and generate\none test target per package. The behavior when\n`gazelle:python_generation_mode` is \"file\" or \"project\" remains the\nsame.\n\nThis fixes #1972 for supporting pytest from Gazelle. With this approach,\npeople can define a thin macro like this to use py_pytest_main:\n\n```\nload(\"@aspect_rules_py//py:defs.bzl\", \"py_pytest_main\")\n\ndef py_test(name, **kwargs):\n    py_pytest_main(\n        name \u003d \"__test__\",\n        deps \u003d [\"@pip_pytest//:pkg\"],  # change this to the pytest target in your repo.\n    )\n\n    deps \u003d kwargs.pop(\"deps\", [])\n    deps.append(\":__test__\")\n\n    py_test(\n        name \u003d name,\n        main \u003d \":__test__.py\",\n        deps \u003d deps,\n        **kwargs,\n)\n```\n\nBREAKING CHANGES:\nWithout `gazelle:map_kind` or `__test__` target or `__test__.py`, the\npackage mode will now generate `py_test` without `main` attribute, which\nmay not be runnable. However, this is already an issue with\n\"python_generation_mode:project\" before this PR.\n\nThe default value of\n`gazelle:python_generation_mode_per_package_require_test_entry_point` is\ntrue to preserve the current behavior. We will flip that default value\nin the future.\n\n---------\n\nCo-authored-by: aignas \u003c240938+aignas@users.noreply.github.com\u003e",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "d924f650ca02be882a9c6efa28cd78c25f4fd140",
      "old_mode": 33188,
      "old_path": "CHANGELOG.md",
      "new_id": "560c04ea8a7783e77c1770f7cdadd9cbf310fcea",
      "new_mode": 33188,
      "new_path": "CHANGELOG.md"
    },
    {
      "type": "modify",
      "old_id": "d68b94de2630ca9e13e4b0e6904d01ba23b67a2b",
      "old_mode": 33188,
      "old_path": "gazelle/README.md",
      "new_id": "c0494d141b645e8f678d01a81b2ebddb5c0cf365",
      "new_mode": 33188,
      "new_path": "gazelle/README.md"
    },
    {
      "type": "modify",
      "old_id": "b82dd81f8f3851d9341bdbf0ffd643ca83ffbb75",
      "old_mode": 33188,
      "old_path": "gazelle/python/configure.go",
      "new_id": "a369a64b8e44514bf8e4e874b98502c1f8a939f8",
      "new_mode": 33188,
      "new_path": "gazelle/python/configure.go"
    },
    {
      "type": "modify",
      "old_id": "ef49dd74c4a9095bb013f93377da85b8859ddc6c",
      "old_mode": 33188,
      "old_path": "gazelle/python/generate.go",
      "new_id": "c563b47bf3a44ce1fb0123c7af6c7a411260fd5c",
      "new_mode": 33188,
      "new_path": "gazelle/python/generate.go"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "27120f32555c780470b030936120504d42187e54",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/BUILD.in"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "c4ec331583a2786f8205c97bf4d358d053ab9670",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/BUILD.out"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "8decb00cfa5e1136c040996a1042a532810cbe35",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/README.md"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "faff6af87ac0ef60c3f9dacae80ca00b08118b58",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/WORKSPACE"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/__init__.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9948f1ccd46269dea5939b748eb74fccee213d03",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/bar_test.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "a128adf67f994544b91ef65664a42418cdaaf0d2",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/foo_test.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "2410223e5999e8b2ef1720863d19e2012a0974eb",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/per_package_test_target_without_entry_point/test.yaml"
    },
    {
      "type": "modify",
      "old_id": "41a470a9402219ec9c3a2631f3aa4acffce83b0c",
      "old_mode": 33188,
      "old_path": "gazelle/pythonconfig/pythonconfig.go",
      "new_id": "a24a90efeb8faddcbac6a6867a583e79392fe848",
      "new_mode": 33188,
      "new_path": "gazelle/pythonconfig/pythonconfig.go"
    }
  ]
}
