Skip to content

Commit 23b9499

Browse files
authored
docs(handwritten): centralize CONTRIBUTING.rst pointers (#17642)
### Problem 1. Each package has a `CONTRIBUTING.rst` file and each file contained references to supported Python runtimes and specific dependency versions, etc. 2. The references to supported runtimes and needed dependencies needed to be updated every time we changed the install environment, which was unnecessary toil. ### Solution 1. Package-level `CONTRIBUTING.rst` files in handwritten libraries simply point to a centralized file in the repository root. 2. Removed all references from both the package-level mini-files and the repository's centralized file that used to spell out which Python runtime versions apply to this package. Instead we now point users to the `noxfile.py`, `setup.py`, and `pyproject.toml` as sources of truth for runtimes and other dependencies. ### Out of Scope/Future work 1. Update GAPIC templates to point at the central `CONTRIBUTING.rst` file. 2. Failing packages that are being processed independently: * #18041 * #18142 * #18157
1 parent 9884ca9 commit 23b9499

32 files changed

Lines changed: 329 additions & 4335 deletions

File tree

CONTRIBUTING.rst

Lines changed: 145 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,155 @@ Contributing
1212
.. _gapic-generator-python: https://github.com/googleapis/gapic-generator-python
1313
.. _Faster Pull Request Reviews: https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
1414

15+
.. contents:: Guidelines for hacking on the Google Cloud Client libraries.
16+
17+
***************
18+
Adding Features
19+
***************
20+
21+
In order to add a feature:
22+
23+
- The feature must be documented in both the API and narrative documentation.
24+
25+
- The feature must work fully on all supported Python versions across macOS, Linux, and Windows.
26+
*(See the package's ``setup.py`` or ``pyproject.toml`` for the definitive list of supported Python versions).*
27+
28+
- The feature must not add unnecessary dependencies (where "unnecessary" is subjective, but new dependencies should be discussed).
29+
30+
****************************
31+
Using a Development Checkout
32+
****************************
33+
34+
You'll have to create a development environment using a Git checkout:
35+
36+
- While logged into your GitHub account, navigate to the ``google-cloud-python`` `repo`_ on GitHub.
37+
38+
- Fork and clone the ``google-cloud-python`` repository to your GitHub account by clicking the "Fork" button.
39+
40+
- Clone your fork of ``google-cloud-python`` from your GitHub account to your local computer, substituting your account username::
41+
42+
$ cd ${HOME}
43+
$ git clone git@github.com:USERNAME/google-cloud-python.git hack-on-google-cloud-python
44+
$ cd hack-on-google-cloud-python
45+
# Configure remotes such that you can pull changes from the googleapis/google-cloud-python
46+
# repository into your local repository.
47+
$ git remote add upstream git@github.com:googleapis/google-cloud-python.git
48+
# fetch and merge changes from upstream into main
49+
$ git fetch upstream
50+
# merge or rebase depending on your preference
51+
$ git merge upstream/main
52+
53+
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.
54+
55+
To work on the codebase and run the tests, we recommend using ``nox``, but you can also use a ``virtualenv`` of your own creation.
56+
57+
.. _repo: https://github.com/googleapis/google-cloud-python
58+
59+
Using ``nox``
60+
=============
61+
62+
We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.
63+
64+
- To test your changes, run unit tests with ``nox``::
65+
66+
$ nox -s unit
67+
68+
- To run a single unit test (replace `<python_version>` with a supported version, e.g., ``3.10``)::
69+
70+
$ nox -s unit-<python_version> -- -k <name of test>
71+
72+
.. note::
73+
74+
The unit tests and system tests are described in the ``noxfile.py`` files in each package directory.
75+
76+
.. _nox: https://pypi.org/project/nox/
77+
78+
*****************************************
79+
I'm getting weird errors... Can you help?
80+
*****************************************
81+
82+
If the error mentions ``Python.h`` not being found, install ``python-dev`` and try again.
83+
On Debian/Ubuntu::
84+
85+
$ sudo apt-get install python-dev
86+
87+
************
88+
Coding Style
89+
************
90+
91+
- We use automatic code formatters and linters (e.g., ``black``, ``ruff``, ``pylint``) to maintain code quality.
92+
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``).
93+
94+
- PEP8 compliance is required, with exceptions defined in the linter configuration of each package.
95+
96+
- 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:
97+
98+
.. code-block:: bash
99+
100+
$ pre-commit install
101+
pre-commit installed at .git/hooks/pre-commit
102+
103+
Exceptions to PEP8:
104+
105+
- 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").
106+
107+
********************
108+
Running System Tests
109+
********************
110+
111+
- To run system tests, you can execute::
112+
113+
# Run all system tests
114+
$ nox -s system
115+
116+
- 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>`__.
117+
118+
.. note::
119+
120+
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.
121+
122+
*************
123+
Test Coverage
124+
*************
125+
126+
- The codebase *must* have 100% test statement coverage after each commit. You can test coverage via ``nox -s cover``.
127+
128+
******************************************************
129+
Documentation Coverage and Building HTML Documentation
130+
******************************************************
131+
132+
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.
133+
134+
Build the docs via::
135+
136+
$ nox -s docs
137+
138+
*************************
139+
Samples and code snippets
140+
*************************
141+
142+
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.
143+
Each folder containing example code requires its own ``noxfile.py`` script which automates testing.
144+
145+
The tests will run against a real Google Cloud Project, so you should configure them just like the System Tests.
146+
147+
**********
148+
Versioning
149+
**********
150+
151+
This library follows `Semantic Versioning`_.
152+
153+
.. _Semantic Versioning: http://semver.org/
154+
155+
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.
15156

16157
******************************
17158
Contributor License Agreements
18159
******************************
19160

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

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>`__.
163+
- **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>`__.
164+
- **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>`__.
29165

30-
You can sign these electronically (just scroll to the bottom). After that,
31-
we'll be able to accept your pull requests.
166+
You can sign these electronically (scroll to the bottom of the CLA form to sign). We will then be able to accept your pull requests.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
############
2+
Contributing
3+
############
4+
5+
This package is part of the ``google-cloud-python`` monorepo.
6+
7+
Please refer to the centralized `Contributing Guide`_ at the repository root for general guidelines on how to contribute, set up your development environment, and submit pull requests.
8+
9+
.. _Contributing Guide: https://github.com/googleapis/google-cloud-python/blob/main/CONTRIBUTING.rst
10+
11+
Package-specific test sessions are defined in this directory's ``noxfile.py``. Dependencies and supported Python versions are defined in ``setup.py`` or ``pyproject.toml``.

packages/gcp-sphinx-docfx-yaml/CONTRIBUTING.md

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
############
2+
Contributing
3+
############
4+
5+
This package is part of the ``google-cloud-python`` monorepo.
6+
7+
Please refer to the centralized `Contributing Guide`_ at the repository root for general guidelines on how to contribute, set up your development environment, and submit pull requests.
8+
9+
.. _Contributing Guide: https://github.com/googleapis/google-cloud-python/blob/main/CONTRIBUTING.rst
10+
11+
Package-specific test sessions are defined in this directory's ``noxfile.py``. Dependencies and supported Python versions are defined in ``setup.py`` or ``pyproject.toml``.
12+
13+
.. note::
14+
This is the forked version of the original repository, which is found on https://github.com/docascode/sphinx-docfx-yaml. Unless the issue applies only to this repository, please also file an issue and/or contribute to the original repository as well.

0 commit comments

Comments
 (0)