Welcome to the Ultralytics pre-commit hooks repository! This collection features hooks developed by Ultralytics to enforce code quality and maintain consistent standards across our software projects. Integrating these hooks into your development workflow automates code validation, ensuring a high level of code hygiene and reducing manual review efforts. Learn more about the pre-commit framework itself on their official website.
This repository is organized for clarity and ease of use:
hooks/
directory: Contains individual Python scripts, each representing a distinct pre-commit hook designed for specific checks or code formatting tasks..pre-commit-hooks.yaml
: The root configuration file defining the available hooks, making them discoverable and easy to integrate into your projects.
Each script within the hooks
directory is a standalone Python program performing a specific pre-commit task. For instance:
capitalize_comments.py
: Ensures that standalone inline comments start with a capital letter, promoting readability and a professional coding style.
The .pre-commit-hooks.yaml
file lists all installable hooks. Here's an example structure for a hook definition:
- id: hook-id # Unique identifier for the hook
name: "A descriptive name for the hook" # User-friendly name
entry: hooks/your_hook_script.py # Path to the hook script
language: python # Specifies the language the script is written in
types: [python] # File types the hook should run on
Interested in contributing a new hook? Follow these steps:
- Create Your Hook Script: Develop a Python script implementing your desired check or formatting logic. Place it in the
hooks/
directory. Ensure your script includes clear error messages and handles potential edge cases. - Declare the Hook: Add a new entry for your hook in the
.pre-commit-hooks.yaml
file, following the structure shown above. - Test Locally: Thoroughly test your hook in a local project environment using
pre-commit run --all-files
to confirm it works as expected before submitting. - Submit Your Contribution: Commit your changes and create a Pull Request to the repository. Adhering to our contribution guidelines is appreciated.
To use Ultralytics pre-commit hooks in your own project, add the following to your project's .pre-commit-config.yaml
file:
repos:
- repo: https://github.com/ultralytics/pre-commit-hooks
rev: main # Pin to 'main' for the latest, or a specific git tag/commit SHA for stability
hooks:
- id: capitalize-comments # Example: Use the ID of the hook you want to include
# Add other hook IDs as needed
After updating your configuration, run this command in your project's root directory to install the hooks:
pre-commit install
Now, the specified Ultralytics hooks will automatically run on your staged files each time you commit, helping maintain code quality effortlessly as part of your Continuous Integration (CI) process.
Ultralytics values community contributions! Your involvement helps us improve and grow. Please review our Contributing Guide for detailed information on how to participate. We also encourage you to share your feedback through our Survey. A big thank you ๐ to all our contributors! Check out some tips on contributing to open-source projects on our blog.
Ultralytics offers two licensing options:
- AGPL-3.0 License: An OSI-approved open-source license ideal for students, researchers, and enthusiasts who value open collaboration. See the LICENSE file for details.
- Enterprise License: Designed for commercial use, this license allows seamless integration of Ultralytics software and AI models into commercial products and services, bypassing the open-source requirements of AGPL-3.0. For inquiries, visit Ultralytics Licensing.
For bug reports or feature requests related to Ultralytics pre-commit hooks, please submit an issue on GitHub Issues. For general questions and discussions, join our vibrant community on Discord!