Skip to content

Commit 04fc652

Browse files
committed
docs: centralize CONTRIBUTING.rst for handwritten packages
1 parent fc6b861 commit 04fc652

36 files changed

Lines changed: 342 additions & 5742 deletions

File tree

CONTRIBUTING.rst

Lines changed: 145 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,157 @@ Contributing
77
#. Make sure that your commit messages clearly describe the changes.
88
#. Send a pull request. (Please Read: `Faster Pull Request Reviews`_)
99

10-
**Note:** All client libraries are automatically generated using `gapic-generator-python`_. Open source contributions for autogenerated code should be made in `gapic-generator-python`_.
11-
12-
.. _gapic-generator-python: https://github.com/googleapis/gapic-generator-python
1310
.. _Faster Pull Request Reviews: https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
1411

12+
.. contents:: Guidelines for hacking on the Google Cloud Client libraries.
13+
14+
***************
15+
Adding Features
16+
***************
17+
18+
In order to add a feature:
19+
20+
- The feature must be documented in both the API and narrative documentation.
21+
22+
- The feature must work fully on all supported Python versions across macOS, Linux, and Windows.
23+
*(See the package's ``noxfile.py`` or ``setup.py`` for the definitive list of supported Python versions).*
24+
25+
- The feature must not add unnecessary dependencies (where "unnecessary" is subjective, but new dependencies should be discussed).
26+
27+
****************************
28+
Using a Development Checkout
29+
****************************
30+
31+
You'll have to create a development environment using a Git checkout:
32+
33+
- While logged into your GitHub account, navigate to the ``google-cloud-python`` `repo`_ on GitHub.
34+
35+
- Fork and clone the ``google-cloud-python`` repository to your GitHub account by clicking the "Fork" button.
36+
37+
- Clone your fork of ``google-cloud-python`` from your GitHub account to your local computer, substituting your account username::
38+
39+
$ cd ${HOME}
40+
$ git clone git@github.com:USERNAME/google-cloud-python.git hack-on-google-cloud-python
41+
$ cd hack-on-google-cloud-python
42+
# Configure remotes such that you can pull changes from the googleapis/google-cloud-python
43+
# repository into your local repository.
44+
$ git remote add upstream git@github.com:googleapis/google-cloud-python.git
45+
# fetch and merge changes from upstream into main
46+
$ git fetch upstream
47+
# merge or rebase depending on your preference
48+
$ git merge upstream/main
49+
50+
Now your local repo is set up such that you will push changes to your GitHub repo, from which you can submit a pull request.
51+
52+
To work on the codebase and run the tests, we recommend using ``nox``, but you can also use a ``virtualenv`` of your own creation.
53+
54+
.. _repo: https://github.com/googleapis/google-cloud-python
55+
56+
Using ``nox``
57+
=============
58+
59+
We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.
60+
61+
- To test your changes, run unit tests with ``nox``::
62+
63+
$ nox -s unit
64+
65+
- To run a single unit test (replace `<python_version>` with a supported version, e.g., ``3.10``)::
66+
67+
$ nox -s unit-<python_version> -- -k <name of test>
68+
69+
.. note::
70+
71+
The unit tests and system tests are described in the ``noxfile.py`` files in each package directory.
72+
73+
.. nox: https://pypi.org/project/nox/
74+
75+
*****************************************
76+
I'm getting weird errors... Can you help?
77+
*****************************************
78+
79+
If the error mentions ``Python.h`` not being found, install ``python-dev`` and try again.
80+
On Debian/Ubuntu::
81+
82+
$ sudo apt-get install python-dev
83+
84+
************
85+
Coding Style
86+
************
87+
88+
- We use automatic code formatters and linters (e.g., ``black``, ``ruff``, ``pylint``) to maintain code quality.
89+
Refer to the specific package's ``noxfile.py`` for the exact sessions available (e.g., ``nox -s blacken``, ``nox -s format``, or ``nox -s lint``).
90+
91+
- PEP8 compliance is required, with exceptions defined in the linter configuration of each package.
92+
93+
- This repository contains configuration for the `pre-commit <https://pre-commit.com/>`__ tool, which automates checking our linters during a commit. If you have it installed on your ``$PATH``, you can enable enforcing those checks via:
94+
95+
.. code-block:: bash
96+
97+
$ pre-commit install
98+
pre-commit installed at .git/hooks/pre-commit
99+
100+
Exceptions to PEP8:
101+
102+
- Many unit tests use a helper method, ``_call_fut`` ("FUT" is short for "Function-Under-Test"), which is PEP8-incompliant, but more readable. Some also use a local variable, ``MUT`` (short for "Module-Under-Test").
103+
104+
********************
105+
Running System Tests
106+
********************
107+
108+
- To run system tests, you can execute::
109+
110+
# Run all system tests
111+
$ nox -s system
112+
113+
- System tests will be run against an actual project. You should use local credentials from gcloud when possible. See `Best practices for application authentication <https://cloud.google.com/docs/authentication/best-practices-applications#local_development_and_testing_with_the>`__. Some tests require a service account. For those tests see `Authenticating as a service account <https://cloud.google.com/docs/authentication/production>`__.
114+
115+
.. note::
116+
117+
Some packages have highly specific system test requirements or setup steps. Refer to the package's local documentation or comments in ``noxfile.py`` if applicable.
118+
119+
*************
120+
Test Coverage
121+
*************
122+
123+
- The codebase *must* have 100% test statement coverage after each commit. You can test coverage via ``nox -s cover``.
124+
125+
******************************************************
126+
Documentation Coverage and Building HTML Documentation
127+
******************************************************
128+
129+
If you fix a bug, and the bug requires an API or behavior modification, all documentation in this package which references that API or behavior must be changed to reflect the bug fix, ideally in the same commit that fixes the bug or adds the feature.
130+
131+
Build the docs via::
132+
133+
$ nox -s docs
134+
135+
*************************
136+
Samples and code snippets
137+
*************************
138+
139+
Code samples and snippets live in the ``samples/`` directory of relevant packages. Feel free to provide more examples, but make sure to write tests for those examples.
140+
Each folder containing example code requires its own ``noxfile.py`` script which automates testing.
141+
142+
The tests will run against a real Google Cloud Project, so you should configure them just like the System Tests.
143+
144+
**********
145+
Versioning
146+
**********
147+
148+
This library follows `Semantic Versioning`_.
149+
150+
.. _Semantic Versioning: http://semver.org/
151+
152+
Some packages are currently in major version zero (``0.y.z``), which means that anything may change at any time and the public API should not be considered stable.
15153

16154
******************************
17155
Contributor License Agreements
18156
******************************
19157

20-
Before we can accept your pull requests you'll need to sign a Contributor
21-
License Agreement (CLA):
158+
Before we can accept your pull requests you'll need to sign a Contributor License Agreement (CLA):
22159

23-
- **If you are an individual writing original source code** and **you own the
24-
intellectual property**, then you'll need to sign an
25-
`individual CLA <https://developers.google.com/open-source/cla/individual>`__.
26-
- **If you work for a company that wants to allow you to contribute your work**,
27-
then you'll need to sign a
28-
`corporate CLA <https://developers.google.com/open-source/cla/corporate>`__.
160+
- **If you are an individual writing original source code** and **you own the intellectual property**, then you'll need to sign an `individual CLA <https://developers.google.com/open-source/cla/individual>`__.
161+
- **If you work for a company that wants to allow you to contribute your work**, then you'll need to sign a `corporate CLA <https://developers.google.com/open-source/cla/corporate>`__.
29162

30-
You can sign these electronically (just scroll to the bottom). After that,
31-
we'll be able to accept your pull requests.
163+
You can sign these electronically (just scroll to the bottom). After that, we'll be able to accept your pull requests.

0 commit comments

Comments
 (0)