)]}'
{
  "commit": "d5945ed2158d1c7a205f278c89520aa4da497442",
  "tree": "7154af1fdc8c1d6e811693a274c308ce55c8de5a",
  "parents": [
    "e86252ffd6d1a1bf32ae99933acc5ab49b78ec1e"
  ],
  "author": {
    "name": "Alex Martani",
    "email": "alexandre.martani@benchling.com",
    "time": "Wed Mar 20 19:10:21 2024 -0700"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Thu Mar 21 02:10:21 2024 +0000"
  },
  "message": "fix(gazelle): Do not create invalid py_test rules in `project` generation mode (#1809)\n\nSince https://github.com/bazelbuild/rules_python/pull/1538, when using\n`gazelle:python_generation_mode project`, a `py_test` rule is created\neven when there are no test files in the project.\nfb673ee47b3268a65a18a154edd574b6509c38c7 (first commit on the PR branch)\nreproduces this issue - it shows that a `py_test` rule is created even\nwhen there is no test entrypoint file (`__test__.py`) nor any test file\nin the entire project. Additionally, test rules created on `project` or\n`package` generation mode will always set `main \u003d \"__test__.py\"`, even\nwhen that file doesn\u0027t exist.\n\nThis PR fixes it by only generating a `py_test` rule if it can find some\ntest file - either an explicit `__test__.py`, or any other file prefixed\nwith `test_` or suffixed with `_test.py`. It also changes the generated\ntest rule to only add `main \u003d \"__test__.py\"` if there is an actual\n`__test__.py` file. Note that, in the case where a `__test__.py` file\ndoesn\u0027t exist, the generated `py_test` rule is likely invalid as-is due\nto the lack of `main`; this can be fixed by mapping to some other\n`py_test` implementation, and I believe the new behavior makes more\nsense than pointing `main` to a non-existing file.\n\nIt may be useful to review per-commit (all tests pass on each commit):\n- First commit reproduces the issue;\n- Second commit fixes the issue and the corresponding tests;\n- Third commit adds additional test cases.",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "9b7ab2554513d29308f829775958ad0a9f622a1e",
      "old_mode": 33188,
      "old_path": "CHANGELOG.md",
      "new_id": "af4c108fd8ab008b19422b74fdea326ea6dc19ba",
      "new_mode": 33188,
      "new_path": "CHANGELOG.md"
    },
    {
      "type": "modify",
      "old_id": "400c25e0b48fcfaf1166757103396405a99b663c",
      "old_mode": 33188,
      "old_path": "gazelle/python/generate.go",
      "new_id": "673076d350cce8d4b2ada542fa15d7ad57bfbfe3",
      "new_mode": 33188,
      "new_path": "gazelle/python/generate.go"
    },
    {
      "type": "modify",
      "old_id": "3a331112e91bf76cb8b0d0612226c102c32f671e",
      "old_mode": 33188,
      "old_path": "gazelle/python/testdata/monorepo/coarse_grained/BUILD.out",
      "new_id": "af014606949956d62c8f397ce8e741638f4fab2f",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/monorepo/coarse_grained/BUILD.out"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "130a6251a70658796ab42f9c2434b81ebd5dc48b",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode/BUILD.in"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "1f30b6d6ab79378e9a35e4c18e2eb1253ee1a313",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode/BUILD.out"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "6d8f1388f6a96fc9d513a1fe7cda543305d3fc9b",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode/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/project_generation_mode/WORKSPACE"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode/__init__.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode/bar/bar.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode/foo/foo.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "fcea77710fc791c34d6a09da4cfd0e38a515fdb0",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode/test.yaml"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "130a6251a70658796ab42f9c2434b81ebd5dc48b",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_test_entrypoint/BUILD.in"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "05cf353abdf2c37aafc51eb79f77b751ffd8d738",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_test_entrypoint/BUILD.out"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "8db5728862935eeabada35e12f85d5e027ec5ba5",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_test_entrypoint/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/project_generation_mode_with_test_entrypoint/WORKSPACE"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_test_entrypoint/__init__.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_test_entrypoint/__test__.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_test_entrypoint/foo/foo_test.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "fcea77710fc791c34d6a09da4cfd0e38a515fdb0",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_test_entrypoint/test.yaml"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "130a6251a70658796ab42f9c2434b81ebd5dc48b",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_tests/BUILD.in"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "8756978b0086cf51981469d5b7409844ee244d02",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_tests/BUILD.out"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "4a5f012d85a43c734bffea060e8d8d30c767cc18",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_tests/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/project_generation_mode_with_tests/WORKSPACE"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_tests/__init__.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_tests/foo/foo_test.py"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "fcea77710fc791c34d6a09da4cfd0e38a515fdb0",
      "new_mode": 33188,
      "new_path": "gazelle/python/testdata/project_generation_mode_with_tests/test.yaml"
    }
  ]
}
