|
| 1 | +############ |
| 2 | +Contributing |
| 3 | +############ |
| 4 | + |
| 5 | +#. **Please sign one of the contributor license agreements below.** |
| 6 | +#. ``python-ndb`` is undergoing heavy development right now, so if you plan to |
| 7 | + implement a feature, please create an issue to discuss your idea first. That |
| 8 | + way we can coordinate and avoid possibly duplicating ongoing work. |
| 9 | +#. Fork the repo, develop and test your code changes, add docs. |
| 10 | +#. Make sure that your commit messages clearly describe the changes. |
| 11 | +#. Send a pull request. (Please Read: `Faster Pull Request Reviews`_) |
| 12 | + |
| 13 | +.. _Faster Pull Request Reviews: https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#best-practices-for-faster-reviews |
| 14 | + |
| 15 | +.. contents:: Here are some guidelines for hacking on ``python-ndb``. |
| 16 | + |
| 17 | +*************** |
| 18 | +Adding Features |
| 19 | +*************** |
| 20 | + |
| 21 | +In order to add a feature to ``python-ndb``: |
| 22 | + |
| 23 | +- The feature must be documented in both the API and narrative |
| 24 | + documentation (in ``docs/``). |
| 25 | + |
| 26 | +- The feature must work fully on the following CPython versions: |
| 27 | + 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 and 3.14 on both UNIX and Windows. |
| 28 | + |
| 29 | +- The feature must not add unnecessary dependencies (where |
| 30 | + "unnecessary" is of course subjective, but new dependencies should |
| 31 | + be discussed). |
| 32 | + |
| 33 | +**************************** |
| 34 | +Using a Development Checkout |
| 35 | +**************************** |
| 36 | + |
| 37 | +You'll have to create a development environment to hack on |
| 38 | +``python-ndb``, using a Git checkout: |
| 39 | + |
| 40 | +- While logged into your GitHub account, navigate to the |
| 41 | + ``python-ndb`` `repo`_ on GitHub. |
| 42 | + |
| 43 | +- Fork and clone the ``python-ndb`` repository to your GitHub account by |
| 44 | + clicking the "Fork" button. |
| 45 | + |
| 46 | +- Clone your fork of ``python-ndb`` from your GitHub account to your local |
| 47 | + computer, substituting your account username and specifying the destination |
| 48 | + as ``hack-on-google-cloud-python``. E.g.:: |
| 49 | + |
| 50 | + $ cd ${HOME} |
| 51 | + $ git clone git@github.com:USERNAME/google-cloud-python.git hack-on-google-cloud-python |
| 52 | + $ cd hack-on-google-cloud-python |
| 53 | + # Configure remotes such that you can pull changes from the python-ndb |
| 54 | + # repository into your local repository. |
| 55 | + $ git remote add upstream git@github.com:googleapis/google-cloud-python.git |
| 56 | + # fetch and merge changes from upstream into main |
| 57 | + $ git fetch upstream |
| 58 | + $ git merge upstream/main |
| 59 | + |
| 60 | +Now your local repo is set up such that you will push changes to your GitHub |
| 61 | +repo, from which you can submit a pull request. |
| 62 | + |
| 63 | +To work on the codebase and run the tests, we recommend using ``nox``, |
| 64 | +but you can also use a ``virtualenv`` of your own creation. |
| 65 | + |
| 66 | +.. _repo: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-ndb |
| 67 | + |
| 68 | +Using ``nox`` |
| 69 | +============= |
| 70 | + |
| 71 | +We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests. |
| 72 | + |
| 73 | +- To test your changes, run unit tests with ``nox``:: |
| 74 | + |
| 75 | + $ nox -s unit-3.10 |
| 76 | + $ nox -s unit-3.7 |
| 77 | + $ ... |
| 78 | + |
| 79 | +.. nox: https://pypi.org/project/nox-automation/ |
| 80 | +
|
| 81 | +- To run unit tests that use Memcached or Redis, you must have them running and set the appropriate environment variables: |
| 82 | + |
| 83 | + $ export MEMCACHED_HOSTS=localhost:11211 |
| 84 | + $ export REDIS_CACHE_URL=redis://localhost:6379 |
| 85 | + |
| 86 | + |
| 87 | +Note on Editable Installs / Develop Mode |
| 88 | +======================================== |
| 89 | + |
| 90 | +- As mentioned previously, using ``setuptools`` in `develop mode`_ |
| 91 | + or a ``pip`` `editable install`_ is not possible with this |
| 92 | + library. This is because this library uses `namespace packages`_. |
| 93 | + For context see `Issue #2316`_ and the relevant `PyPA issue`_. |
| 94 | + |
| 95 | + Since ``editable`` / ``develop`` mode can't be used, packages |
| 96 | + need to be installed directly. Hence your changes to the source |
| 97 | + tree don't get incorporated into the **already installed** |
| 98 | + package. |
| 99 | + |
| 100 | +.. _namespace packages: https://www.python.org/dev/peps/pep-0420/ |
| 101 | +.. _Issue #2316: https://github.com/googleapis/google-cloud-python/issues/2316 |
| 102 | +.. _PyPA issue: https://github.com/pypa/packaging-problems/issues/12 |
| 103 | +.. _develop mode: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode |
| 104 | +.. _editable install: https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs |
| 105 | + |
| 106 | +***************************************** |
| 107 | +I'm getting weird errors... Can you help? |
| 108 | +***************************************** |
| 109 | + |
| 110 | +If the error mentions ``Python.h`` not being found, |
| 111 | +install ``python-dev`` and try again. |
| 112 | +On Debian/Ubuntu:: |
| 113 | + |
| 114 | + $ sudo apt-get install python-dev |
| 115 | + |
| 116 | +************ |
| 117 | +Coding Style |
| 118 | +************ |
| 119 | + |
| 120 | +- PEP8 compliance, with exceptions defined in the linter configuration. |
| 121 | + If you have ``nox`` installed, you can test that you have not introduced |
| 122 | + any non-compliant code via:: |
| 123 | + |
| 124 | + $ nox -s lint |
| 125 | + |
| 126 | +- In order to make ``nox -s lint`` run faster, you can set some environment |
| 127 | + variables:: |
| 128 | + |
| 129 | + export GOOGLE_CLOUD_TESTING_REMOTE="upstream" |
| 130 | + export GOOGLE_CLOUD_TESTING_BRANCH="main" |
| 131 | + |
| 132 | + By doing this, you are specifying the location of the most up-to-date |
| 133 | + version of ``python-ndb``. The the suggested remote name ``upstream`` |
| 134 | + should point to the official ``googleapis`` checkout and the |
| 135 | + the branch should be the main branch on that remote (``main``). |
| 136 | + |
| 137 | +Exceptions to PEP8: |
| 138 | + |
| 139 | +- Many unit tests use a helper method, ``_call_fut`` ("FUT" is short for |
| 140 | + "Function-Under-Test"), which is PEP8-incompliant, but more readable. |
| 141 | + Some also use a local variable, ``MUT`` (short for "Module-Under-Test"). |
| 142 | + |
| 143 | +******************** |
| 144 | +Running System Tests |
| 145 | +******************** |
| 146 | + |
| 147 | +- To run system tests for a given package, you can execute:: |
| 148 | + |
| 149 | + $ export SYSTEM_TESTS_DATABASE=system-tests-named-db |
| 150 | + $ nox -e system |
| 151 | + |
| 152 | + .. note:: |
| 153 | + |
| 154 | + System tests are only configured to run under Python 3.14. For |
| 155 | + expediency, we do not run them in older versions of Python 3. |
| 156 | + |
| 157 | + This alone will not run the tests. You'll need to change some local |
| 158 | + auth settings and change some configuration in your project to |
| 159 | + run all the tests. |
| 160 | + |
| 161 | +- System tests may be run against the emulator. To do this, set the |
| 162 | + ``DATASTORE_EMULATOR_HOST`` environment variable. Alternatively, |
| 163 | + system tests with the emulator can run with |
| 164 | + `nox -e emulator-system-PYTHON_VERSION` |
| 165 | + |
| 166 | +- System tests will be run against an actual project and |
| 167 | + so you'll need to provide some environment variables to facilitate |
| 168 | + authentication to your project: |
| 169 | + |
| 170 | + - ``GOOGLE_APPLICATION_CREDENTIALS``: The path to a JSON key file; |
| 171 | + see ``system_tests/app_credentials.json.sample`` as an example. Such a file |
| 172 | + can be downloaded directly from the developer's console by clicking |
| 173 | + "Generate new JSON key". See private key |
| 174 | + `docs <https://cloud.google.com/storage/docs/authentication#generating-a-private-key>`__ |
| 175 | + for more details. |
| 176 | + |
| 177 | + - In order for Logging system tests to work, the Service Account |
| 178 | + will also have to be made a project ``Owner``. This can be changed under |
| 179 | + "IAM & Admin". Additionally, ``cloud-logs@google.com`` must be given |
| 180 | + ``Editor`` permissions on the project. |
| 181 | + |
| 182 | +- For datastore tests, you'll need to create composite |
| 183 | + `indexes <https://cloud.google.com/datastore/docs/tools/indexconfig>`__ |
| 184 | + with the ``gcloud`` command line |
| 185 | + `tool <https://developers.google.com/cloud/sdk/gcloud/>`__:: |
| 186 | + |
| 187 | + # Install the app (App Engine Command Line Interface) component. |
| 188 | + $ gcloud components install app-engine-python |
| 189 | + |
| 190 | + # Authenticate the gcloud tool with your account. |
| 191 | + $ GOOGLE_APPLICATION_CREDENTIALS="path/to/app_credentials.json" |
| 192 | + $ gcloud auth activate-service-account \ |
| 193 | + > --key-file=${GOOGLE_APPLICATION_CREDENTIALS} |
| 194 | + |
| 195 | + # Create the indexes |
| 196 | + $ gcloud datastore indexes create tests/system/index.yaml |
| 197 | + $ gcloud alpha datastore indexes create --database=$SYSTEM_TESTS_DATABASE tests/system/index.yaml |
| 198 | + |
| 199 | + |
| 200 | +************* |
| 201 | +Test Coverage |
| 202 | +************* |
| 203 | + |
| 204 | +- The codebase *must* have 100% test statement coverage after each commit. |
| 205 | + You can test coverage via ``nox -s cover``. |
| 206 | + |
| 207 | +****************************************************** |
| 208 | +Documentation Coverage and Building HTML Documentation |
| 209 | +****************************************************** |
| 210 | + |
| 211 | +If you fix a bug, and the bug requires an API or behavior modification, all |
| 212 | +documentation in this package which references that API or behavior must be |
| 213 | +changed to reflect the bug fix, ideally in the same commit that fixes the bug |
| 214 | +or adds the feature. |
| 215 | + |
| 216 | +To build and review docs (where ``${VENV}`` refers to the virtualenv you're |
| 217 | +using to develop ``python-ndb``): |
| 218 | + |
| 219 | +#. After following the steps above in "Using a Development Checkout", install |
| 220 | + Sphinx and all development requirements in your virtualenv:: |
| 221 | + |
| 222 | + $ cd ${HOME}/hack-on-google-cloud-python |
| 223 | + $ ${VENV}/bin/pip install Sphinx |
| 224 | + |
| 225 | +#. Change into the ``docs`` directory within your ``python-ndb`` checkout and |
| 226 | + execute the ``make`` command with some flags:: |
| 227 | + |
| 228 | + $ cd ${HOME}/hack-on-google-cloud-python/docs |
| 229 | + $ make clean html SPHINXBUILD=${VENV}/bin/sphinx-build |
| 230 | + |
| 231 | + The ``SPHINXBUILD=...`` argument tells Sphinx to use the virtualenv Python, |
| 232 | + which will have both Sphinx and ``python-ndb`` (for API documentation |
| 233 | + generation) installed. |
| 234 | + |
| 235 | +#. Open the ``docs/_build/html/index.html`` file to see the resulting HTML |
| 236 | + rendering. |
| 237 | + |
| 238 | +As an alternative to 1. and 2. above, if you have ``nox`` installed, you |
| 239 | +can build the docs via:: |
| 240 | + |
| 241 | + $ nox -s docs |
| 242 | + |
| 243 | +******************************************** |
| 244 | +Note About ``README`` as it pertains to PyPI |
| 245 | +******************************************** |
| 246 | + |
| 247 | +The `description on PyPI`_ for the project comes directly from the |
| 248 | +``README``. Due to the reStructuredText (``rst``) parser used by |
| 249 | +PyPI, relative links which will work on GitHub (e.g. ``CONTRIBUTING.rst`` |
| 250 | +instead of |
| 251 | +``https://github.com/googleapis/google-cloud-python/blob/main/packages/google-cloud-ndb/CONTRIBUTING.rst``) |
| 252 | +may cause problems creating links or rendering the description. |
| 253 | + |
| 254 | +.. _description on PyPI: https://pypi.org/project/google-cloud/ |
| 255 | + |
| 256 | + |
| 257 | +************************* |
| 258 | +Supported Python Versions |
| 259 | +************************* |
| 260 | + |
| 261 | +We support: |
| 262 | + |
| 263 | +- `Python 3.7`_ |
| 264 | +- `Python 3.8`_ |
| 265 | +- `Python 3.9`_ |
| 266 | +- `Python 3.10`_ |
| 267 | +- `Python 3.11`_ |
| 268 | +- `Python 3.12`_ |
| 269 | +- `Python 3.13`_ |
| 270 | +- `Python 3.14`_ |
| 271 | + |
| 272 | +.. _Python 3.7: https://docs.python.org/3.7/ |
| 273 | +.. _Python 3.8: https://docs.python.org/3.8/ |
| 274 | +.. _Python 3.9: https://docs.python.org/3.9/ |
| 275 | +.. _Python 3.10: https://docs.python.org/3.10/ |
| 276 | +.. _Python 3.11: https://docs.python.org/3.11/ |
| 277 | +.. _Python 3.12: https://docs.python.org/3.12/ |
| 278 | +.. _Python 3.13: https://docs.python.org/3.13/ |
| 279 | +.. _Python 3.14: https://docs.python.org/3.14/ |
| 280 | + |
| 281 | + |
| 282 | +Supported versions can be found in our ``noxfile.py`` `config`_. |
| 283 | + |
| 284 | +.. _config: https://github.com/googleapis/google-cloud-python/blob/main/packages/google-cloud-ndb/noxfile.py |
| 285 | + |
| 286 | + |
| 287 | +********** |
| 288 | +Versioning |
| 289 | +********** |
| 290 | + |
| 291 | +This library follows `Semantic Versioning`_. |
| 292 | + |
| 293 | +.. _Semantic Versioning: http://semver.org/ |
| 294 | + |
| 295 | +Some packages are currently in major version zero (``0.y.z``), which means that |
| 296 | +anything may change at any time and the public API should not be considered |
| 297 | +stable. |
| 298 | + |
| 299 | +****************************** |
| 300 | +Contributor License Agreements |
| 301 | +****************************** |
| 302 | + |
| 303 | +Before we can accept your pull requests you'll need to sign a Contributor |
| 304 | +License Agreement (CLA): |
| 305 | + |
| 306 | +- **If you are an individual writing original source code** and **you own the |
| 307 | + intellectual property**, then you'll need to sign an |
| 308 | + `individual CLA <https://developers.google.com/open-source/cla/individual>`__. |
| 309 | +- **If you work for a company that wants to allow you to contribute your work**, |
| 310 | + then you'll need to sign a |
| 311 | + `corporate CLA <https://developers.google.com/open-source/cla/corporate>`__. |
| 312 | + |
| 313 | +You can sign these electronically (just scroll to the bottom). After that, |
| 314 | +we'll be able to accept your pull requests. |
0 commit comments