| 1 |
****************** |
| 2 |
Contributing guide |
| 3 |
****************** |
| 4 |
|
| 5 |
Thanks for your interest in contributing to cpplint. |
| 6 |
|
| 7 |
Any kinds of contributions are welcome: Bug reports, Documentation, Patches. However, here are some contributions you probably shouldn't make: |
| 8 |
|
| 9 |
* Drastic reorganization |
| 10 |
* Making the code conform to Google's Python style guidelines |
| 11 |
* Features that could be regarded as a security vulnerability |
| 12 |
|
| 13 |
If you need some ideas, you may check out some of the tasks in our `issue tracker <https://github.com/cpplint/cpplint/issues>`_. |
| 14 |
|
| 15 |
Development |
| 16 |
=========== |
| 17 |
|
| 18 |
For many tasks, it is okay to just develop using a single installed python version. But if you need to test/debug the project in multiple python versions, you need to install those versions: |
| 19 |
|
| 20 |
1. (Optional) Install multiple python versions |
| 21 |
|
| 22 |
1. (Optional) Install `pyenv <https://github.com/pyenv/pyenv-installer>`_ to manage python versions |
| 23 |
2. (Optional) Using pyenv, install the python versions used in testing:: |
| 24 |
|
| 25 |
pyenv install 3.<version> |
| 26 |
# ... |
| 27 |
pyenv local 3.<version> ... |
| 28 |
|
| 29 |
It may be okay to run and test python against locally installed libraries, but if you need to have a consistent build, it is recommended to manage your environment using virtualenv: `virtualenv <https://virtualenv.pypa.io/en/latest/>`_, `virtualenvwrapper <https://pypi.org/project/virtualenvwrapper/>`_:: |
| 30 |
|
| 31 |
mkvirtualenv cpplint [-p /usr/bin/python3] |
| 32 |
pip install .[dev] |
| 33 |
|
| 34 |
Alternatively, you can locally install patches like this:: |
| 35 |
|
| 36 |
pip install -e .[dev] |
| 37 |
# for usage without virtualenv, add --user |
| 38 |
|
| 39 |
Please install pre-commit locally to run the linters before committing:: |
| 40 |
|
| 41 |
pipx install pre-commit |
| 42 |
pre-commit install |
| 43 |
|
| 44 |
Pull requests |
| 45 |
------------- |
| 46 |
|
| 47 |
When you're finished with a pull request, please: |
| 48 |
|
| 49 |
* add a relevant test case to cpplint_unittest.py |
| 50 |
* add a summary of what your changes do to CHANGELOG.rst |
| 51 |
* specify the problem solved in the pull request |
| 52 |
* make sure that your code passes the tests and lints |
| 53 |
* don't force-push to the branch. These make the commit history messy, and we squash all commits when merging anyways. |
| 54 |
|
| 55 |
.. _testing: |
| 56 |
|
| 57 |
Testing |
| 58 |
------- |
| 59 |
|
| 60 |
You can test your changes under your local python environment by running the tests and lints below: |
| 61 |
|
| 62 |
.. code-block:: bash |
| 63 |
|
| 64 |
# install test requirements |
| 65 |
pip install .[test] |
| 66 |
# run a single test |
| 67 |
pytest --no-cov cpplint_unittest.py -k testName |
| 68 |
# run a single CLI integration test |
| 69 |
pytest --no-cov cpplint_clitest.py -k testSillySample |
| 70 |
# run all tests. you don't have to run the above tests separately |
| 71 |
pytest |
| 72 |
# lint the code |
| 73 |
pylint cpplint.py |
| 74 |
pre-commit run --all-files |
| 75 |
|
| 76 |
Alternatively, you can run `tox` to automatically run all tests and lints. Use `-e ` followed by the python runner and version (which you must have installed) to automatically generate the testing environment and run the above tests and lints in it. For example, `tox -e py39` does the steps in Python 3.9, `tox -e py313` does the steps in Python 3.13, and `tox -e pypy3` does the steps using the latest version of the pypy interpreter. |
| 77 |
|
| 78 |
Releasing |
| 79 |
========= |
| 80 |
|
| 81 |
The release process first prepares the documentation, then publishes to testpypi to verify, then releases to real pypi. Testpypi acts like real pypi, so broken releases cannot be deleted. For a typical bugfixing release, no special issue on testpypi is expected (but it's still good practice). The commands are documented below, and assume you've went through the testing steps above. |
| 82 |
|
| 83 |
.. code-block:: bash |
| 84 |
|
| 85 |
# prepare files for release |
| 86 |
$EDITOR cpplint.py # increment the version |
| 87 |
$EDITOR CHANGELOG.rst # log changes |
| 88 |
git add cpplint.py CHANGELOG.rst |
| 89 |
git commit -m "Releasing x.y.z" |
| 90 |
# Build |
| 91 |
pip install --upgrade build wheel twine |
| 92 |
rm -rf dist |
| 93 |
python -m build --sdist --wheel |
| 94 |
# Test release, requires account on testpypi |
| 95 |
twine upload --repository testpypi dist/* |
| 96 |
# ... Check website and downloads from https://test.pypi.org/project/cpplint/ |
| 97 |
# Actual release |
| 98 |
twine upload dist/* |
| 99 |
git tag x.y.z |
| 100 |
git push --tags |
| 101 |
|
| 102 |
After releasing, it is be good practice to comment on completed GitHub issues to notify authors. |
| 103 |
|
| 104 |
Catching up with Upstream |
| 105 |
========================= |
| 106 |
|
| 107 |
For maintainers, it is a regular duty to look at what cpplint changes were merged upstream and include them in this fork (though these updates happen rarely). |
| 108 |
|
| 109 |
Checkout here and upstream google: |
| 110 |
|
| 111 |
.. code-block:: bash |
| 112 |
|
| 113 |
git clone [email protected]:cpplint/cpplint.git |
| 114 |
cd cpplint |
| 115 |
git remote add google https://github.com/google/styleguide |
| 116 |
|
| 117 |
To incorporate google's changes: |
| 118 |
|
| 119 |
.. code-block:: bash |
| 120 |
|
| 121 |
git fetch google gh-pages |
| 122 |
|
| 123 |
## Merge workflow (clean, no new commits) |
| 124 |
git checkout develop -b updates |
| 125 |
git merge google/gh-pages # this will have a lot of conflicts |
| 126 |
# ... solve conflicts |
| 127 |
git merge -- continue |
| 128 |
|
| 129 |
## Rebase workflow (dirty, creates new commits) |
| 130 |
git checkout -b updates FETCH_HEAD |
| 131 |
git rebase develop # this will have a lot of conflicts, most of which can be solved with the next command (run repeatedly) |
| 132 |
# solve conflicts with files deleted in our fork (this is idempotent and safe to be called. when cpplint.py has conflicts, it will do nothing) |
| 133 |
git status | grep 'new file:' | awk '{print $3}' | xargs -r git rm --cached ; git status | grep 'deleted by us' | awk '{print $4}' | xargs -r git rm |
| 134 |
git status --untracked-files=no | grep 'nothing to commit' && git rebase --skip |
| 135 |
|
| 136 |
git push -u origin updates |
| 137 |
# check github action |
| 138 |
git push origin --delete updates |
| 139 |
|
| 140 |
git rebase updates develop |
| 141 |
git branch -D updates |
| 142 |
git push |
| 143 |
|
| 144 |
Setup fetching of pull requests in .git/config: |
| 145 |
|
| 146 |
.. code-block:: bash |
| 147 |
|
| 148 |
[remote "origin"] |
| 149 |
url = [email protected]:cpplint/cpplint.git |
| 150 |
fetch = +refs/heads/*:refs/remotes/origin/* |
| 151 |
# following line should be new, fetches PRs from cpplint |
| 152 |
fetch = +refs/pull/*/head:refs/remotes/origin/pr/* |
| 153 |
[remote "google"] |
| 154 |
url = https://github.com/google/styleguide |
| 155 |
fetch = +refs/heads/*:refs/remotes/google/* |
| 156 |
# following line should be new, fetches PRs from google/styleguides |
| 157 |
fetch = +refs/pull/*/head:refs/remotes/google/pr/* |
| 158 |
|
| 159 |
|
| 160 |
To compare this for with upstream (after git fetch): |
| 161 |
|
| 162 |
.. code-block:: bash |
| 163 |
|
| 164 |
git diff google/gh-pages:cpplint/cpplint.py develop:cpplint.py |
| 165 |
git diff google/gh-pages:cpplint/cpplint_unittest.py develop:cpplint_unittest.py |