Pull Requests β Let's Squash Bugs & Build Features!¶
Note
- Pull Requests (PRs) are for code contributions
- Further reading: Github Docs of Pull Requests
Scenarios of Submitting a PR¶
- Fix bugs
- Add new feature
- Update documentation
- Performance optimizations
- Test coverage enhancements
- CI/CD pipeline improvements
- Code improvements / refactoring
Step-by-Step Guide¶
Prerequisite Knowledge
-
torchmeter
is hosted on GitHub , so youβll need a GitHub Account to begin contributing. -
torchmeter
uses Git for version control. If you're unfamiliar withGit basics
orGitHub PR workflows
, we recommend these resources: -
Our contribution process draw inspiration from projects like
numpy
,pandas
,polars
, andrich
. For reference:
A. Claim Your Mission¶
Section Overview
This section will guide you through:
- Discovering beginner-friendly start points
- Properly claiming unassigned issues
- Collaborating on existing development efforts
By following these protocols, you'll establish clear ownership while respecting community norms. We're excited to help you find meaningful work that aligns with project needs and your interests!
-
Finding Beginner-Friendly Issues: New to
torchmeter
or open-source? We recommend:-
Start by searching for
good-first-issue
labeled issues on the Issues page . These are specially marked for beginners and often have clear scopes. -
Look for issues without existing assignees to avoid duplication of effort.
-
-
Claiming an Issue
To take ownership of an unassigned issue: Leave a polite comment like:
"Iβd try to work on this!"
or just a single"take"
. This signals your intent and allows maintainers to assign it to you.Responsibility Note
Claiming an issue means youβll be responsible for following up and resolving it. If circumstances prevent you from continuing, please update the thread promptly so others can help.
-
Joining Existing Efforts
-
Politely ask current assignee via comment: For example,
"Hi @username, may I collaborate on this?"
-
Wait patiently: If the current contributor hasnβt updated the issue for 7+ days, you may gently ask if they need help or if you can take over.
-
B. Environment Setup¶
Section Overview
This section will help you configure a development environment for torchmeter
. We'll walk through essential steps including:
Git
configuration for version controlPython
environment setup with required dependencies- Local repository initialization and remote tracking
By completing these steps, you'll have a fully functional setup to make contribution efficiently. Let's begin now!
B.a Download & Install Git¶
-
Download
Git
through its download page β https://git-scm.com/downloads -
Verify Installation: Open your terminal and run the following command.
A successful installation will display the Git
version (e.g., git version 2.49.0
).
B.b Create a Fork Repository¶
What is a fork repository?
- A fork repo is a copy of the original repository, allowing you to make changes without affecting the original project.
- Learn more: GitHub Forking Guide
-
Go to the official
torchmeter
repository page β https://github.com/TorchMeter/torchmeter -
Click the
Fork
button in the top-right corner -
Configure your fork:
- Select your
GitHub Account
as the owner - Keep the default repository name unless you want to customize it
- (Optional) Uncheck
Copy the master branch only
to include all branches
- Select your
-
Click
Create fork
. You'll now have a personal sandbox repository athttps://github.com/<your-username>/torchmeter
if you have not changed the default repository name.
B.c Clone Your Fork to Local Machine¶
-
Go to your GitHub account's Repositories page and navigate to your newly created fork of
torchmeter
. -
Copy the repository URL:
- Click the green
Code
button on your fork's page - Select the
Local-HTTPS
tab and copy the URL (i.e.,https://github.com/<your-username>/torchmeter.git
if you kept the default repository name)
- Click the green
-
Clone to your local system
Bashcd path/to/store/your/project git clone <paste-the-url-copied-in-last-step-here> torchmeter-yourname # (1)
- πββοΈ Replace
torchmeter-yourname
with any string you want. This will be the directory name for the local copy of your fork repository.
- πββοΈ Replace
-
Verify: A new directory
torchmeter-yourname
will be created containing:- Working directory: Your local copy of the project files
- Local repository: The
.git
folder managing version control (contains commit history, branches, etc.)
What is the difference between the working directory (aka workspace) and the local repository?
- What: Your project folder (i.e.,
torchmeter-yourname
in the last step) where you edit files directly. - Contains: Live files (e.g., modified
python
scripts). - Actions:
manual edits
,git add
- What: The
.git
folder (hidden) in the project root. - Contains: Full
Git
history (commits, branches). - Actions:
git commit
,git log
B.d Link to Official Repository (Upstream)¶
-
Set up upstream tracking to sync with the latest changes:
Bash# pwd: path/to/store/your/project cd torchmeter-yourname # (1) # Add the official repository as upstream git remote add upstream https://github.com/TorchMeter/torchmeter.git # Fetch the latest updates git fetch upstream
- πββοΈ Replace
torchmeter-yourname
with the directory name you set in step B.c.3.
- πββοΈ Replace
-
Verify remote & upstream tracking:
Ensure the output contains the highlighted lines below. If you uncheck "Copy the master branch only" (1) when forking, you might see info of additional branches like
v0.1.x
(2) - these can be safely ignored as we ultimately create PRs against the master branch.- πββοΈ refer to step B.b.3.
- πββοΈ lines 7-8
Why we do this?
After this step, your local repository now has two remote references, both are critical to the contribution process:
- The repo it points to: Your fork on GitHub, i.e.,
https://github.com/<your-username>/torchmeter
if you kept the default repository name in forking. - Purpose: To receive local changes for future PR submissions to the official repository
- The repo it points to: The official
torchmeter
repository, i.e.,https://github.com/TorchMeter/torchmeter
- Purpose: To keep your local repository synchronized with the official repository's updates to avoid merge conflicts when submitting PRs
If you're unfamiliar with these concepts or the open-source contribution process, don't worry! We'll walk you through the entire workflow step-by-step in the following sections.
B.e Configure Python Environment¶
About Python Environment
- We highly recommend creating a dedicated
Python
virtual environment fortorchmeter
development. - You can use virtual environment management tools like
venv
,uv
,poetry
, orconda
, etc. - Here we'll use
conda
as an example; other tools can be configured via their official documentation.
-
Install
Miniconda
:-
Official guide: Miniconda Installation
-
Verify installation:
Expected output: conda version (e.g.,
conda 24.1.2
) -
-
Create virtual environment with
Python 3.8
(minimum required version):- πββοΈ
torchmeter-dev
is customizable, is the virtual environment name
- πββοΈ
-
Install
torchmeter
as well as its dependencies in editable mode:Bash# pwd: path/to/your/working/directory conda activate torchmeter-dev # (1) pip install -e ".[test]" # (2)
- πββοΈ Replace
torchmeter-dev
with your virtual environment name. - πββοΈ The
-e
flag is required to enable coverage tracking in testing. Omitting it may cause coverage calculation errors.
- πββοΈ Replace
For Windows Users with NVIDIA GPUs
On Windows systems,
pip
may default to installing theCPU
version ofPyTorch
, which prevents leveragingGPU
acceleration. Please follow these steps to manually verify and install theGPU-enabled PyTorch
version:
-
Verify
Pytorch
'sCUDA
compatibility:PowerShell# pwd: anywhere conda activate torchmeter-dev # (1) python -c "import torch; print(torch.cuda.is_available())"
- πββοΈ Replace
torchmeter-dev
with your virtual environment name
If you have installed the
CUDA-enabled Pytorch
version, the output of the command should beTrue
.If it is, you can skip this part and proceed to section C.
- πββοΈ Replace
-
If the command return
False
, manually installGPU-enabled Pytorch
:-
Determine
CUDA
version:- πββοΈ Check the version number, e.g.
CUDA Version: 12.4
- πββοΈ Check the version number, e.g.
-
Download appropriate
Pytorch
wheel:Pytorch
binaries β https://download.pytorch.org/whl/torch. Note thattorchmeter
supportsPytorch
versions β₯1.7.0
.- Match
Python
version (e.g.,cp38
forPython 3.8
),CUDA
version (e.g.,cu124
), andOS
. Example:torch-2.4.1+cu124-cp38-cp38-win_amd64.whl
-
Install
torch
bywhl
file:PowerShell# pwd: anywhere conda activate torchmeter-dev # (1) pip install path/to/downloaded/torch.whl
- πββοΈ Replace
torchmeter-dev
with your virtual environment name
- πββοΈ Replace
-
-
Validate
GPU
support: re-execute the command instep 1
to confirmGPU
support.
C. Making Code Changes¶
Section Overview
This section will guide you through:
- Understanding code architecture and implementing changes
- Maintaining code quality through type-checking, linting and testing
- Following proper version control practices for local/remote submissions
By completing these steps, your code will not only adhere to project standards and remain robust and maintainable, but also be properly prepared for official review.
C.a Understanding Code & Getting started¶
Recommended Tools for this Step
- Purpose: For code debugging
- Quickstart Guide: PDB Tutorial
- Documentation: Python PDB Docs
- Purpose: For rapid logic validation (powerful REPL)
- Documentation: IPython Official Site
-
Fetch Latest Code of
torchmeter
-
Create Your Development Branch
Bash# pwd: path/to/your/local/copy/of/your/fork/ # Replace `<your-branch-name>` with your branch name git checkout -b <your-branch-name> upstream/master # (1)
- πββοΈ Replace
<your-branch-name>
with your branch name. When naming a branch, please follow our branch naming conventions .
Branch Name conventions
When naming a branch, please follow our branch naming conventions .
- πββοΈ Replace
-
Dive into the code
-
You can start by reviewing the annotated project tree for a quick understanding of the project layout.
-
Based on your insights, locate the specific files/classes/functions to modify. You can make it via the
IDE
's file tree, text searching orIDE
navigation (Ctrl/Cmd+Click
to jump to definitions). -
If you successfully find the parts you need to modify, you can start reading the source code in combination with the annotation document to figure out its logic and working principle.
-
If youβre stuck, there are 2 ways to move on:
-
Use
pdb
breakpoints: insertimport pdb; pdb.set_trace()
at the problematic part of the code, then run the code and it will stop at the breakpoint and allow you to inspect the variables. -
For persistent confusion, kindly start a Discussion to seek assistance.
-
-
-
Start implementing your modifications after fully grasping the existing logic. Note that it's highly recommended to focus your changes on one issue or feature. This will make the review process easier.
-
You can verify your modifications through debugging or custom scripts, but we recommend using
IPython
for rapid testing:-
Install
Ipython
: -
Open the terminal and type
ipython
to start the interactive environment. You can then import and test your modified code directly. For example, if you added a new functionnew_func()
intorchmeter.core
:
-
-
Finally, update contributors list:
- Open
CONTRIBUTORS.md
in the project root directory -
Add your information at the end following the format below:
- Open
C.b Lint, Format and Test your Code¶
Recommended Tools for this Step
For VSCode
users, we recommend installing these extensions:
- Plugin page
- Highlight: This plugin uses underlines to highlight code snippets that do not conform to the predefined rules and allows you to automatically fix some common errors.
- Plugin page
- Highlight: This plugin also works with underlines to highlight code snippets that has wrong type annotations or lacks required ones.
To ensure your code meets torchmeter
's standards, please complete these 3 critical steps in order.
-
Type Checking
-
torchmeter
usesmypy
for static type checking (already installed in step B.e.3). -
You'll need to add type annotations to your changes. Please refer to
mypy
documentation for best practices. -
After completing the type annotations, make sure to pass the following type checking commands:
Bash# pwd: path/to/your/local/copy/of/your/fork/ conda activate torchmeter-dev # (1) mypy ./torchmeter
- πββοΈ Replace
torchmeter-dev
with your virtual environment name.
- πββοΈ Replace
You should promise output is something like
Success: no issues found in <number-of-files> source files
-
-
Linting and Formatting
-
torchmeter
uses ruff for linting and formatting (already installed in step B.e.3). -
Our style rules are defined in
ruff.toml
at project root. Please respect these configurations, if you find any rules unreasonable, please start a Discussions . -
Ensure the code format of your changes meets the project requirements by running the following formating commands:
Bash# pwd: path/to/your/local/copy/of/your/fork/ conda activate torchmeter-dev # (1) ruff format \ --preview \ --target-version=py38
- πββοΈ Replace
torchmeter-dev
with your virtual environment name.
You should promise the command ends successfully
- πββοΈ Replace
-
After that, ensure your changes comply with the project's code style with the following commands:
Bash# pwd: path/to/your/local/copy/of/your/fork/ conda activate torchmeter-dev # (1) ruff check \ --fix \ --unsafe-fixes \ --preview \ --target-version=py38
- πββοΈ Replace
torchmeter-dev
with your virtual environment name.
You should promise output is
All checks passed!
and no errors are reported. - πββοΈ Replace
-
If any step fails, please modify the code according to the terminal output and re-execute the above steps until all steps are successful.
-
-
Testing
-
torchmeter
usespytest
for testing code. Yes,pytest
and the related plugins have also been installed in step B.e.3. -
torchmeter
has written thepytest
running configuration inpytest.ini
file at project root. This file defines how the tests are run, including the test directory, test filters, test configuration, etc. Specifically,pytest
will only discover tests in thetests
directory at project root, and requires a test coverage rate of > 90%. -
Therefore, if you add new functions or classes, please ensure that corresponding test cases are added. Regarding the writing of test cases, you can refer to the official documentation of
pytest
or quickly get started through the projectpython_testing_tutorial
. During the process of writing test cases, we recommend usingfixture
andparametrize
for parameterized testing, so as to reduce duplicate code. -
After you've completed the above steps (i.e.
type annotation
,linting and formatting
), please make sure to run the following commands to ensure the logical correctness and stability of the code.- πββοΈ Replace
torchmeter-dev
with your virtual environment name
- πββοΈ Replace
You should promise there is no error reported in the output. If all tests passed, you will see the coverage report in the terminal.
-
C.c Add Documentation for Your Code¶
Why should I do this?
- Your expertise
-
Your first-hand knowledge makes your documentation the most authoritative and comprehensive source.
- Enhance readability
-
Clear documentation helps maintainers quickly grasp your code's logic and intent during PR reviews.
- Faster iteration
- Consistent documentation practices reduce redundant efforts for maintainers, allowing
torchmeter
to evolve more efficiently.
How torchmeter builds docs
-
The documentation of
torchmeter
is built based onmkdocs
. For theAPI Reference
section ,mkdocstrings[python]
is used to extract multi-level annotations of modules, classes, functions, etc. and generate the relevant docs content automatically. -
To identify the structure in the extracted annotation text,
mkdocstrings[python]
requires a clear annotation format. Intorchmeter
, we follow Google's Python docstring style guide to write annotation documents. -
Put simply, you just need to write
google
-style docstrings for your modifications, the automated documentation build process will take care of the rest! You can refer to the existing work as a reference, seeAPI Reference
section for examples.
Recommended Tools for this Step
For VSCode
users, we recommend installing the autDocstring
extension:
- Plugin page .
- Configure format: Open
VSCode
settings ( Ctrl+, / Cmd+, ) β search forautodocstring.docstringFormat
β selectgoogle
.
-
For new/modified functions or class methods
-
Add function-level documentation following Googleβs function-level guidelines .
-
Example:
Pythondef example_function(arg1: int, arg2: str) -> bool: """Short description of the function's purpose. Args: arg1 (int): Description of argument 1. arg2 (str): Description of argument 2. Raises: ValueError: If `arg1` is not an integer, or `arg2` is not a string. Returns: bool: Description of return value. """ if not isinstance(arg1, int): raise ValueError("arg1 must be an integer") if not isinstance(arg2, str): raise ValueError("arg2 must be a string") # Your implementation here return True if arg1 > 0 and args.startswith('a') else False
-
-
For new/modified classes:
-
Add class-level documentation following the Google class guidelines.
-
If you add a brand new class, you need to add both class-level documentation for the class and function-level documentation for each method.
-
Example:
Pythonclass ExampleClass: """Class description and purpose. Attributes: attr1 (int): Description of class attribute. Methods: method1: Method description and purpose. """ attr1 : int = 0 def method1(self, arg1: int) -> bool: """Method description and purpose. Args: arg1 (int): Description of argument 1. Raises: ValueError: If `arg1` is not an integer. Returns: bool: Description of return value. """ if not isinstance(arg1, int): raise ValueError("arg1 must be an integer") # Your implementation here return True if arg1 > 0 else False # other methods here
-
Acknowledgement
Document writing can be rather dull and requires clear expression skills.
We sincerely appreciate every contributor who is willing to add to the documentation!
Thank you π
C.d Commit Changes to Local Repository¶
Recommended Tools for this Step
For VSCode
users, we recommend installing the Git Graph
extension:
- Plugin page .
- Highlight: Visualize commit history and repository state through an interactive interface.
Once you feel that your changes have made phased progress, you can incorporate them into version management by committing the changes to the local repository. Please follow these steps:
-
Make sure you are on your development branch
-
Check your current branch
-
You should ensure that the branch output by the above command is consistent with the branch set in step C.a.2. Otherwise, use the following command to switch branches:
- πββοΈ Replace
<branch_name>
with your development branch name set in step C.a.2.
- πββοΈ Replace
-
-
Review Your Changes
-
List modified files
You may see something like this
On branch <your-development-branch-name> Changed but not updated: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: xxx.py Untracked files: (use "git add <file>..." to include in what will be committed) zzz.py no changes added to commit (use "git add" and/or "git commit -a")
-
Please ensure that all your changes appear in the output of the above command. If there are unexpected changes, you can execute the following command to view it:
-
If there are any changes you don't want, you can use the following command to undo them. Otherwise, you can skip this step.
-
-
When all changes have been confirmed, you can optionally commit them to the staging area1.
-
When all the changes you desire have been staged, you can use the following command to commit the staged changes to the local repository:
-
The above command will open a text editor in the terminal (it will be opened with
vim
ornano
), and you need to fill in the commit message in it.- We recommend describing what and why of the changes in the simplest possible way. If this commit is related to an
issue
orPR
, please ensure that you have associated this commit with them by usingcloses #<issue-number>
,fixes #<issue-number>
orrefs: <PR-number>
etc. - Refer to our commit message conventions for specific requirements.
- We recommend describing what and why of the changes in the simplest possible way. If this commit is related to an
-
After editing, save and close the editor. Then the changes in the staging area will be committed to the local repository. You can use the following command to view your commit history. If you are a
VSCode
user, you can use theGit Graph
extension to view the commit history more conveniently and intuitively.
While multiple commits are acceptable before pushing to the remote repository (i.e. your fork repository), it is highly recommended to keep your commit history concise (e.g., 3β6 commits).
That is because large batches of changes may complicate review processes. For extensive refactors, consider splitting work into separate PRs addressing individual features/fixes.
C.e Push Changes to Your Fork Repository¶
Enable GitHub Actions in your fork repository
-
What is GitHub Actions in forks?
GitHub Actions
is GitHub's CI/CD service that automates workflows throughYAML
configurations.torchmeter
uses predefined workflows for compatibility testing, automated releases, PR management, and README updates, etc. See all our workflow files
-
Why enable it?
- Your fork inherits the original repo's workflows but defaults to disabled for security2.
- Enabling it allows you to simulate the CI process triggered when a PR is submitted to the official repo, which helps you find problems as early as possible.
- In
torchmeter
, compatibility testing is mandatory for PR merging. Therefore, it is necessary to enable it for simulating the CI process.
-
How to enable: Go to your fork's
Actions
tab β click theI understand my workflows, go ahead and enable them
button.
-
When you believe you've completed all your changes or need to save your progress temporarily, you can push the current commit history of your local repository to the remote repository (i.e., your
fork
repository). Execute the following commands.Bash# pwd: path/to/your/local/copy/of/your/fork/ git push -u origin <your-branch-name>:<remote-branch-name> # (1) (2)
- πββοΈ You need to replace
<your-branch-name>
with the branch name created in step C.a.2. You also need to replace<remote-branch-name>
with one that will receive the changes in remote repository. Generally, we keep it the same as<your-branch-name>
. - πββοΈ The
-u
parameter indicates that the<your-branch-name>
branch in local repository will track the<remote-branch-name>
branch in remote repository. Thus, when you make new commits on<your-branch-name>
in local repository, you can easily push them to the<remote-branch-name>
branch in remote repository with a simplegit push
command, no need to re-type the remote repository's target branch name.
- πββοΈ You need to replace
-
If you have enabled the
Github Actions
for yourfork
repository, you can submit a PR to themaster
branch of the remote repository (i.e., yourfork
repository) to automatically trigger the compatibility test we've prepared for you:- Open the page of your fork repository. Shortly after pushing your changes, you'll find a prominent
Compare & pull request
button. (1)(Illustration) - Click this button. In the pop-up page, select the
base
branch as themaster
branch of your fork repository, and select thehead
branch as the<remote-branch-name>
branch you just pushed. Please double-check that thebase
branch is themaster
branch of yourfork
repository, not themaster
branch of the officialtorchmeter
repository. - Fill in the PR title. See PR Title Convention .
- Fill in the PR description. Since you are just testing, the description can be brief, no need to fill it in according to the predefined template.
- Click the
Create Pull Request
button below, and you have created a PR targeting themaster
branch in your fork repository. - Click on the
Actions
tab. You will see a task namedβ Compatibility Test β
is running. It is the compatibility test workflow of thetorchmeter
project. - Wait for the task to finish running. If the task fails, check the error, modify the code locally, and then re-commit to the remote repository. This will update the commit history of the PR and trigger the minimal test
β Minimal Test β
. - If the minimum test is passed, click on the
Actions
tab, selectβ Compatibility Test β
, clickRun workflow
, choose your branch and run. This will re-trigger the compatibility test, do it until it is passed.
- Open the page of your fork repository. Shortly after pushing your changes, you'll find a prominent
D. Contribute to Official Repository¶
Section Overview
Now, your code has been pushed to GitHub
but is not yet part of the official torchmeter
repository. In this section, we'll guide you through the final steps to complete your contribution journey:
- Submit your PR to the official
torchmeter
repository - Collaborate positively with reviewers
- Celebrate your successful contribution
By following these steps, your code will officially merge into torchmeter
's master
branch and become part of the next release to benefit all users. We're thrilled to guide you through this final phase!
D.a Avoiding Protential Merge Conflicts¶
What is this for?
- What is a merge conflict?
-
When two branches make conflicting changes to the same part of a file,
Git
cannot automatically decide which should be kept. This creates a blocking state where your PR cannot be merged until resolved. - When a conflict happens?
- As all contributors work on the
master
base branch, new commits may be added while you develop. Then when you try to merge your PR, your changes may clash with these updates. - Learn more
-
Understanding merge conflicts | Step-by-step conflict resolution guide
-
Check for upstream changes:
Bash# pwd: path/to/your/local/copy/of/your/fork/ git fetch upstream git rev-list --count <your-branch-name>..upstream/master # (1)
- πββοΈ You need to replace
<your-branch-name>
with the branch name created in step C.a.2.
- πββοΈ You need to replace
-
If output is
0
, it indicates that there are no leading commits inupstream/master
. In this case, proceed to step D.b. -
If output
> 0
, it indicates that there are ahead commits inupstream/master
. In this case, you need to resolve the merge conflicts throughrebase
:Bash# pwd: path/to/your/local/copy/of/your/fork/ git checkout <your-branch-name> git branch <your-branch-name>-bak <your-branch-name> # (1) git rebase upstream/master # (2)
- πββοΈ Back up the new branch, you need to replace
<your-branch-name>
with the branch name created in step C.a.2. - πββοΈ Rebase the new branch onto the latest commit of the target branch in
torchmeter
official repo.
- πββοΈ Back up the new branch, you need to replace
-
The above command will attempt to rebase your branch
<your-branch-name>
onto the latest commit of themaster
branch of officialtorchmeter
repo (i.e. theupstream/master
in your local repo). Two scenarios may occur:-
Your changes do not conflict with the latest commit of the target branch. The rebase was successful, and you will see the following output. In this case, you're ready to proceed to step
9
below to delete the backup branch. -
There is a conflict between your changes and the latest commit of the target branch, and the rebase has failed. You will see output similar to the following, which indicates the commit where the conflict occurred and the file(s) involved.
Auto-merging test.py CONFLICT (content): Merge conflict in test.py error: could not apply 5d3f9e2... Add new feature logic hint: Resolve all conflicts manually, mark them as resolved with hint: "git add/rm <conflicted_files>", then run "git rebase --continue". hint: You can instead skip this commit with "git rebase --skip". hint: To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply 5d3f9e2... Add new feature logic
If the rebase fails, you will find conflict markers such as
<<<<<<< HEAD
,=======
,>>>>>>>
in the conflicted files. The conflict content of two branches is divided by=======
, as shown below.
-
-
If there are conflicts, you need to resolve them manually. Discard the old changes and remove all conflict markers3. It should be noted that during the conflict resolution process, you are actually in an interrupted state of the previous
rebase
command. Therefore, you can use the following commands to revert the changes or completely cancel the wholerebase
operation:- Discard the existing changesοΌ
git reset --hard <your-branch-name>
- Cancel rebase:
git rebase --abort
- Discard the existing changesοΌ
-
Once you have resolved all the conflicts, you need to execute the following commands to continue the
rebase
operation: -
Repeat step 6 until the rebase is successful. After that, commit the changes to the local repository with a formatted commit message. Refer to our commit message conventions for specific requirements.
- πββοΈ This will open an editor to edit the commit message. Please follow our commit message conventions to format your writting. Thank you !
-
Execute the following commands to synchronize the changes to your fork repository4.
- πββοΈ You need to replace
<your-branch-name>
with the branch name created in step C.a.2.
- πββοΈ You need to replace
-
Finally, delete the backup branch.
- πββοΈ you need to replace
<your-branch-name>
with the branch name created in step C.a.2.
- πββοΈ you need to replace
D.b Create a Pull Request to torchmeter¶
Prerequisites of Creating PRs
Before creating a PR, kindly ensure the following prerequisites are met:
-
Test coverage: If your changes introduce new functionality or logic, please add corresponding tests (see step C.b.3).
-
Documentation: We highly appreciate contributors who add/update docstrings for their changes (see step C.c).
-
Branch hygiene:
- Your local changes are not on the master branch (
upstream/master
ororigin/master
). - The name of the branch to host your change follows our branch naming conventions . If not, rename it via:
Bash# pwd: path/to/your/local/copy/of/your/fork/ git checkout <your-branch-name> # (1) git branch -m <new-branch-name>
- πββοΈ You need to replace
<your-branch-name>
with the branch name created in step C.a.2.
- Your local changes are not on the master branch (
-
Sync status:
- Your branch has been rebased onto the latest
upstream/master
(see step D.a) - All changes have been pushed to your fork repository. If workflows are enabled, ensure the
β Compatibility Test β
completes successfully (see step C.e.2).
- Your branch has been rebased onto the latest
Once the requirements above are met, create your PR as follows:
-
Open your fork repository β Click
Pull requests
tab βNew pull request
-
Configure the PR source/destination:
- base repository:
TorchMeter/torchmeter
- base:
master
- head repository:
your-github-id/your-fork-repo
- compare:
<your-branch-name>
- base repository:
-
Pay attention to the status prompt. If it shows
Can't automatically merge
(example), there are merge conflicts. In this case, please exit the PR creation page, resolve them following the steps in D.a and retry. -
Review your changes down the page, so as to ensure complete/correct file modifications.
-
Click the green
Create pull request
button, and complete PR details:- Title: Follow our PR title conventions .
- Description: You can see that your "Add a description" field is not empty. That's because we've prepared a content template for you to guide your filling. You just need to use
markdown
syntax to fill it out as completely as possible according to the requirements in the comments. That's all what you need to do. Finally, you can clickPreview
above the input box to preview the rendered content you've filled in.
-
If everything looks good, please check the option
Allow edits and access to secrets by maintainers
. This permission is required to auto-update theREADME.md
coverage badge before your PR is merged5. -
Submit your PR
- For complete implementations (e.g., bug fixes/new features), click
Create pull request
for immediate review. - For in-progress work or consultation requests, choose
Create draft pull request
from the dropdown. Draft PRs won't trigger formal review processes until you mark it Ready for review.
- For complete implementations (e.g., bug fixes/new features), click
D.c Update your PR¶
Once your PR is created (whether draft or final), torchmeter
uses automated workflows to ensure quality and facilitate efficient review/merge processes. If these checks fail, please actively collaborate to update the PR accordingly.
PR Title Linting and Formatting
Once a PR is created, a workflow named π€ PR Auto-Labeler β³
will be automatically triggered. It will determine whether the PR title complies with our PR title conventions .
-
If non-compliant:
- A red
PR-title-needs-formatting
label will be added - You'll need to modify the PR title using the
Edit
button next to it
- A red
-
For compliant titles:
- Category labels are automatically assigned based on title prefixes
- These labels help organize PRs and inform our changelog generation when releasing a new version.
Code Linting, Formatting and Compatibility Testing
Once a PR is created, a workflow named β
Compatibility Test β
will be automatically triggered. It will check whether the code in the PR meets the style and format requirements defined in ruff.toml
.
If both pass, compatibility tests will be conducted across platforms (windows
, macOs
, linux
) and across versions (python 3.8
to python 3.13
). If any step fails, torchmeter
will provide an error report on the workflow run page. Please download it, review it, and try to fix the problem.
You can try to solve the problem by creating a new commit for the fix in your local repository and pushing it to the remote repository. The commit history of the PR will be automatically synchronized with the history of the head
branch.
It should be noted that every time PR is updated like this, an automated test workflow named β
Minimal Test β
will be triggered, which will execute the test in a randomly selected system and python 3.8
. Without consuming a lot of time and resources like compatibility testing, this is beneficial for you to find new problems that may be introduced by new submission as soon as possible.
D.d Waiting for Review & Active Collaboration¶
PR Closure
Kindly note that your pull request (PR) may be manually closed under these circumstances:
- Incorrect target branch: Ensure the
base
branch is set tomaster
- Duplicate contributions: Existing PRs already address the same problem
- CI failures with prolonged inactivity: PRs failing CI checks without updates for
30+
days - Outdated scope: When the code area involved in the PR has been refactored or cancelled
-
After passing compatibility tests, your PR enters formal review . Typical first review occurs within 5-7 business days (may vary with maintainer availability).
-
During the review process, reviewers may leave comments. If any questions arise, please respond patiently and courteously to clarify your implementation rationale:
- Kindly respond to review comments as soon as possible
- Use
Resolve conversation
button when fixes are applied. - For unclear requests, ask clarifying questions like:
"Could you please elaborate on [...]?"
-
Provided everything checks out, maintainers will:
- Manually trigger compatibility tests to verify code standards, correctness, robustness, and cross-environment compatibility again.
- Manually execute the
π€ Update README Badge π°
workflow (as mentioned in step D.b.6) to update the coverage badge inREADME.md
-
If everything goes wellοΌyour PR will be merged into the
master
branch inSquash
orMerge
way. Your contribution will be officially released and acknowledged in the next version announcement.
D.e Celebrate Your Successful Contribution π¶
-
Once your PR is merged, you'll receive a notification email from
GitHub
with a message similar to:Merged #<PR-number> into master.
-
Congratulationsπππ Your contribution is now part of
torchmeter
. We'll announce your changes in our next official release and express our gratitude again on the release page . -
This marks the completion of your contribution journey! Take a well-deserved break, share the achievement with your peers, or celebrate in any way that brings you joy. We sincerely appreciate your time and effort!
Checkout Your Contribution Locally
The merged changes will be visible on the master
branch. To update locally:
This ensures your local environment reflects the latest project state including your contribution.
-
The staging area is a temporary storage area that holds the changes you'll add to your next commit. It's like the shopping cart you use before paying at the supermarket, where the items in the cart are your changes here. It should be noted that when you need to stage an empty folder, please create an empty file named
.gitkeep
in it. ↩ -
You can enable
Github Actions
for your fork repo without worry as we've added repository validation for sensitive operations (like package publishing), so you can rest assured to enable it. ↩ -
Currently, IDEs have mature support for resolving merge conflicts. For example, you can refer to Resolve conflicts in VsCode and Resolve conflicts in PyCharm . ↩
-
If you have created a PR to the
master
branch of your fork repo in step C.e, you will see that the commit history of PR will be updated synchronously and the minimum test workflow will be automatically triggered to verify the correctness and robustness of your changes. ↩ -
The workflow named
π Update README Badge π°
is responsible for updating the coverage badge inREADME.md
and committing the changes to PR history. If you're worried about the security issues brought by enabling this option, you can review the content of this workflow .torchmeter
ensures that only modifications related to the coverage badge inREADME.md
will be made. No other code or sensitive information will be involved. Moreover, all changes will be publicly recorded, and you can review them at any time. Thanks for your trust ! ↩