Repository: astral-sh/ruff
File: crates/ty_python_semantic/mdtest.py (Python)

Code before:
                        else:
                            new_md_files.add(relative_path)
                    case Change.modified:
                        changed_md_files.add(relative_path)
                    case Change.deleted:
                        # No need to do anything when a Markdown test is deleted
                        pass
                    case _ as unreachable:
                        assert_never(unreachable)

            if rust_code_has_changed:
                if self._recompile_tests("Rust code has changed, recompiling tests..."):
                    self._run_mdtest(self.filters)
            elif vendored_typeshed_has_changed:
                if self._recompile_tests(
                    "Vendored typeshed has changed, recompiling tests..."
                ):
                    self._run_mdtest(self.filters)
            elif new_md_files:
                files = " ".join(file.as_posix() for file in new_md_files)
                self._recompile_tests(
                    f"New Markdown test [yellow]{files}[/yellow] detected, recompiling tests..."
                )

            for path in new_md_files | changed_md_files:
                if self._matches_filter(path):
                    self._run_mdtests_for_file(path)


def main() -> None:
    parser = argparse.ArgumentParser(
        description="A runner for Markdown-based tests for ty"
    )
    parser.add_argument(
        "filters",
        nargs="*",
        help="Partial paths or mangled names, e.g., 'loops/for.md' or 'loops_for'",
    )

    args = parser.parse_args()

    try:
        runner = MDTestRunner(filters=args.filters)
        runner.watch()
    except KeyboardInterrupt:
        print()


if __name__ == "__main__":
    main()


Review comment (suggestion):
I guess one could even argue that the filter shouldn't apply here? That is, if a MD file is changed that doesn't match the filter, maybe it makes sense to still run it for that file.

Code after:
                    case _ as unreachable:
                        assert_never(unreachable)

            if rust_code_has_changed:
                if self._recompile_tests("Rust code has changed, recompiling tests..."):
                    self._run_mdtest(self.filters)
            elif vendored_typeshed_has_changed:
                if self._recompile_tests(
                    "Vendored typeshed has changed, recompiling tests..."
                ):
                    self._run_mdtest(self.filters)
            elif new_md_files:
                files = " ".join(file.as_posix() for file in new_md_files)
                self._recompile_tests(
                    f"New Markdown test [yellow]{files}[/yellow] detected, recompiling tests..."
                )

            for path in new_md_files | changed_md_files:
                self._run_mdtests_for_file(path)


def main() -> None:
    parser = argparse.ArgumentParser(
        description="A runner for Markdown-based tests for ty"
    )
    parser.add_argument(
        "filters",
        nargs="*",
        help="Partial paths or mangled names, e.g., 'loops/for.md' or 'loops_for'",
    )

    args = parser.parse_args()

    try:
        runner = MDTestRunner(filters=args.filters)
        runner.watch()
    except KeyboardInterrupt:
        print()


if __name__ == "__main__":
    main()