This repository contains pre-commit hooks developed by Ultralytics for ensuring code quality and standards in our software development practices. By leveraging these hooks, developers can automate the process of code validation, thus maintaining a high level of code hygiene.
The repository is thoughtfully structured to facilitate easy navigation and understanding:
- A
hooks
directory comprising all the individual Python scripts, each serving as a distinct hook for specific checks or code quality assurances. - The
.pre-commit-hooks.yaml
file located at the root, which specifies the available hooks for easy integration into your projects.
Each script housed within the hooks
directory is a self-contained Python program designed to carry out a particular pre-commit check. For example:
capitalize_comments.py
: This script ensures that the first letter of standalone inline comments begins with a capital letter, fostering readability and a professional codebase demeanor.
Hooks available for installation are declared within the .pre-commit-hooks.yaml
file. An example definition would resemble:
- id: hook-id
name: "A Name Describing What the Hook Does"
entry: hooks/name_of_your_hook_script.py
language: python
types: [python]
Where the elements are as follows:
hook-id
represents a unique identifier for the hook you are configuring.A Name Describing What the Hook Does
: A brief, intuitive name that indicates the functionality of the hook.name_of_your_hook_script.py
is the filename for the Python script that resides in thehooks
directory and codifies the logic for the hook.
If you're interested in contributing a fresh hook, here's how you can add one:
- Craft Your Hook Script: Write a Python script that encapsulates the functionality of your new hook. This script should be placed within the
hooks
directory. For maintainability and ease-of-understanding, ensure your script contains appropriate error handling and outputs useful messages. - Declare Your New Hook: Extend the
.pre-commit-hooks.yaml
with a new block that follows the definition pattern showcased earlier. - Local Testing: Before integrating your hook into the repository, ensure that you have tested it in a local project setting to affirm its operational behavior.
- Sync to Repository: After satisfactory local validation, commit your work to the repository and initiate a push to share your hook with the community.
To harness the power of Ultralytics pre-commit hooks within your project, add their specifications into your .pre-commit-config.yaml
like so:
- repo: https://github.com/ultralytics/pre-commit-hooks
rev: main # You might prefer pinning this to a specific git tag or commit SHA.
hooks:
- id: hook-id
Execute this command within your project's directory to set up the pre-commit framework:
pre-commit install
With this action, the identified pre-commit hooks from Ultralytics will now be a part of your workflow, automatically running during the commit phase.
Ultralytics thrives on community collaboration; we immensely value your involvement! We urge you to peruse our Contributing Guide for detailed insights on how you can participate. Don't forget to share your feedback with us by contributing to our Survey. A heartfelt thank you 🙏 goes out to everyone who has already contributed!
Ultralytics presents two distinct licensing paths to accommodate a variety of scenarios:
- AGPL-3.0 License: This official OSI-approved open-source license is perfectly aligned with the goals of students, enthusiasts, and researchers who believe in the virtues of open collaboration and shared wisdom. Details are available in the LICENSE document.
- Enterprise License: Tailored for commercial deployment, this license authorizes the unfettered integration of Ultralytics software and AI models within commercial goods and services, without the copyleft stipulations of AGPL-3.0. Should your use case demand an enterprise solution, direct your inquiries to Ultralytics Licensing.
For bugs or feature suggestions pertaining to Ultralytics, please lodge an issue via GitHub Issues. You're also invited to participate in our Discord community to engage in discussions and seek advice!