[copybara] Import robotpy examples (#8608)

GitOrigin-RevId: 9ba4bc3040fa7e772f5a594039e78fc6c43d114e
This commit is contained in:
PJ Reiniger
2026-02-20 18:30:35 -05:00
committed by GitHub
parent 1806cd2d78
commit 8f9fc4d1b6
136 changed files with 8989 additions and 3 deletions

79
robotpyExamples/check_header.py Executable file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/env python3
#
# Copyright (c) FIRST and other WPILib contributors.
# Open Source Software; you can modify and/or share it under the terms of
# the WPILib BSD license file in the root directory of this project.
#
from pathlib import Path
def check_file_content(file_path):
with open(file_path, "r") as file:
lines = file.readlines()
if file.name.endswith("robot.py"):
expected_lines = [
"#!/usr/bin/env python3\n",
"#\n",
"# Copyright (c) FIRST and other WPILib contributors.\n",
"# Open Source Software; you can modify and/or share it under the terms of\n",
"# the WPILib BSD license file in the root directory of this project.\n",
"#\n",
"\n",
]
else:
expected_lines = [
"#\n",
"# Copyright (c) FIRST and other WPILib contributors.\n",
"# Open Source Software; you can modify and/or share it under the terms of\n",
"# the WPILib BSD license file in the root directory of this project.\n",
"#\n",
"\n",
]
if lines[: len(expected_lines)] != expected_lines:
print(
"\n".join(
[
f"{file_path}",
"ERROR: File must start with the following lines",
"------------------------------",
"".join(expected_lines[:-1]),
"------------------------------",
"Found:",
"".join(lines[: len(expected_lines)]),
"------------------------------",
]
)
)
return False
return True
def main():
current_directory = Path(__file__).parent
python_files = [
x
for x in current_directory.glob("./**/*.py")
if not x.parent == current_directory and x.stat().st_size != 0
]
non_compliant_files = [
file for file in python_files if not check_file_content(file)
]
non_compliant_files.sort()
if non_compliant_files:
print("Non-compliant files:")
for file in non_compliant_files:
print(f"- {file}")
exit(1) # Exit with an error code
else:
print("All files are compliant.")
if __name__ == "__main__":
main()