Pull Requests β Let's Squash Bugs & Build Features!ΒΆ
Note
Pull Requests(PRs) - 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
-
torchmeteris hosted on GitHub , so youβll need a GitHub Account to begin contributing. -
torchmeteruses Git for version control. If you're unfamiliar withGit basicsorGitHub 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
torchmeteror open-source? We recommend:-
Start by searching for
good-first-issuelabeled 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:
Gitconfiguration for version controlPythonenvironment 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
Gitthrough 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
torchmeterrepository page β https://github.com/TorchMeter/torchmeter -
Click the
Forkbutton in the top-right corner -
Configure your fork:
- Select your
GitHub Accountas the owner - Keep the default repository name unless you want to customize it
- (Optional) Uncheck
Copy the master branch onlyto include all branches
- Select your
-
Click
Create fork. You'll now have a personal sandbox repository athttps://github.com/<your-username>/torchmeterif 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
Codebutton on your fork's page - Select the
Local-HTTPStab and copy the URL (i.e.,https://github.com/<your-username>/torchmeter.gitif 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-yournamewith any string you want. This will be the directory name for the local copy of your fork repository.
- πββοΈ Replace
-
Verify: A new directory
torchmeter-yournamewill be created containing:- Working directory: Your local copy of the project files
- Local repository: The
.gitfolder 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-yournamein the last step) where you edit files directly. - Contains: Live files (e.g., modified
pythonscripts). - Actions:
manual edits,git add
- What: The
.gitfolder (hidden) in the project root. - Contains: Full
Githistory (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-yournamewith 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>/torchmeterif 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
torchmeterrepository, 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
Pythonvirtual environment fortorchmeterdevelopment. - You can use virtual environment management tools like
venv,uv,poetry, orconda, etc. - Here we'll use
condaas 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-devis customizable, is the virtual environment name
- πββοΈ
-
Install
torchmeteras 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-devwith your virtual environment name. - πββοΈ The
-eflag 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,
pipmay default to installing theCPUversion ofPyTorch, which prevents leveragingGPUacceleration. Please follow these steps to manually verify and install theGPU-enabled PyTorchversion:
-
Verify
Pytorch'sCUDAcompatibility:PowerShell# pwd: anywhere conda activate torchmeter-dev # (1) python -c "import torch; print(torch.cuda.is_available())"- πββοΈ Replace
torchmeter-devwith your virtual environment name
If you have installed the
CUDA-enabled Pytorchversion, 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
CUDAversion:- πββοΈ Check the version number, e.g.
CUDA Version: 12.4
- πββοΈ Check the version number, e.g.
-
Download appropriate
Pytorchwheel:Pytorchbinaries β https://download.pytorch.org/whl/torch. Note thattorchmetersupportsPytorchversions β₯1.7.0.- Match
Pythonversion (e.g.,cp38forPython 3.8),CUDAversion (e.g.,cu124), andOS. Example:torch-2.4.1+cu124-cp38-cp38-win_amd64.whl
-
Install
torchbywhlfile:PowerShell# pwd: anywhere conda activate torchmeter-dev # (1) pip install path/to/downloaded/torch.whl- πββοΈ Replace
torchmeter-devwith your virtual environment name
- πββοΈ Replace
-
-
Validate
GPUsupport: re-execute the command instep 1to confirmGPUsupport.
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 orIDEnavigation (Ctrl/Cmd+Clickto 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
pdbbreakpoints: 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
IPythonfor rapid testing:-
Install
Ipython: -
Open the terminal and type
ipythonto 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.mdin 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
-
torchmeterusesmypyfor static type checking (already installed in step B.e.3). -
You'll need to add type annotations to your changes. Please refer to
mypydocumentation 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-devwith 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
-
torchmeteruses ruff for linting and formatting (already installed in step B.e.3). -
Our style rules are defined in
ruff.tomlat 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-devwith 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-devwith 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
-
torchmeterusespytestfor testing code. Yes,pytestand the related plugins have also been installed in step B.e.3. -
torchmeterhas written thepytestrunning configuration inpytest.inifile at project root. This file defines how the tests are run, including the test directory, test filters, test configuration, etc. Specifically,pytestwill only discover tests in thetestsdirectory 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
pytestor quickly get started through the projectpython_testing_tutorial. During the process of writing test cases, we recommend usingfixtureandparametrizefor 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-devwith 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
torchmeterto evolve more efficiently.
How torchmeter builds docs
-
The documentation of
torchmeteris built based onmkdocs. For theAPI Referencesection ,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 Referencesection for examples.
Recommended Tools for this Step
For VSCode users, we recommend installing the autDocstring extension:
- Plugin page .
- Configure format: Open
VSCodesettings ( 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
vimornano), 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
issueorPR, 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
VSCodeuser, you can use theGit Graphextension 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 Actionsis GitHub's CI/CD service that automates workflows throughYAMLconfigurations.torchmeteruses 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
Actionstab β click theI understand my workflows, go ahead and enable thembutton.
-
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
forkrepository). 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
-uparameter 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 pushcommand, no need to re-type the remote repository's target branch name.
- πββοΈ You need to replace
-
If you have enabled the
Github Actionsfor yourforkrepository, you can submit a PR to themasterbranch of the remote repository (i.e., yourforkrepository) 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 requestbutton. (1)(Illustration) - Click this button. In the pop-up page, select the
basebranch as themasterbranch of your fork repository, and select theheadbranch as the<remote-branch-name>branch you just pushed. Please double-check that thebasebranch is themasterbranch of yourforkrepository, not themasterbranch of the officialtorchmeterrepository. - 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 Requestbutton below, and you have created a PR targeting themasterbranch in your fork repository. - Click on the
Actionstab. You will see a task namedβ Compatibility Test βis running. It is the compatibility test workflow of thetorchmeterproject. - 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
Actionstab, 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
torchmeterrepository - 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,
Gitcannot 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
masterbase 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
torchmeterofficial 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 themasterbranch of officialtorchmeterrepo (i.e. theupstream/masterin 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
9below 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 logicIf 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
rebasecommand. Therefore, you can use the following commands to revert the changes or completely cancel the wholerebaseoperation:- 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
rebaseoperation: -
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/masterororigin/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 requeststab β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 requestbutton, 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
markdownsyntax 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 clickPreviewabove 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.mdcoverage badge before your PR is merged5. -
Submit your PR
- For complete implementations (e.g., bug fixes/new features), click
Create pull requestfor immediate review. - For in-progress work or consultation requests, choose
Create draft pull requestfrom 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-formattinglabel will be added - You'll need to modify the PR title using the
Editbutton 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
basebranch 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 conversationbutton 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
masterbranch inSquashorMergeway. 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
GitHubwith 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
.gitkeepin it. β© -
You can enable
Github Actionsfor 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
masterbranch 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.mdand 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 .torchmeterensures that only modifications related to the coverage badge inREADME.mdwill 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 ! β©
