| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
Here are some guidelines for hacking on google-cloud-python.
In order to add a feature to google-cloud-python:
You'll have to create a development environment to hack on google-cloud-python, using a Git checkout:
While logged into your GitHub account, navigate to the google-cloud-python repo on GitHub.
Fork and clone the google-cloud-python repository to your GitHub account by clicking the "Fork" button.
Clone your fork of google-cloud-python from your GitHub account to your local computer, substituting your account username and specifying the destination as hack-on-google-cloud-python. E.g.:
$ cd ${HOME}
$ git clone git@github.com:USERNAME/google-cloud-python.git hack-on-google-cloud-python
$ cd hack-on-google-cloud-python
# Configure remotes such that you can pull changes from the google-cloud-python
# repository into your local repository.
$ git remote add upstream git@github.com:GoogleCloudPlatform/google-cloud-python.git
# fetch and merge changes from upstream into master
$ git fetch upstream
$ git merge upstream/master
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.
To work on the codebase and run the tests, we recommend using nox, but you can also use a virtualenv of your own creation.
To create a virtualenv in which to install google-cloud-python:
$ cd ${HOME}/hack-on-google-cloud-python
$ virtualenv --python python3.6 ${ENV_NAME}
You can choose which Python version you want to use by passing a --python flag to virtualenv. For example, virtualenv --python python3.6 chooses the Python 3.6 interpreter to be installed.
Note
We recommend developing in Python 3, and using the test suite to ensure compatibility with Python 2.
From here on in within these instructions, the ${HOME}/hack-on-google-cloud-python/${ENV_NAME} virtual environment you created above will be referred to as ${VENV}. To use the instructions in the steps that follow literally, use:
$ export VENV=${HOME}/hack-on-google-cloud-python/${ENV_NAME}
To install google-cloud-python from your source checkout into ${VENV}, run:
$ # Make sure you are in the same directory as setup.py
$ cd ${HOME}/hack-on-google-cloud-python
$ ${VENV}/bin/python setup.py install
Unfortunately using setup.py develop is not possible with this project, because it uses namespace packages.
We use `nox`_ to instrument our tests.
To test your changes, run unit tests with nox:
$ nox -f datastore/nox.py -s "unit_tests(python_version='2.7')" $ nox -f datastore/nox.py -s "unit_tests(python_version='3.4')" $ ...
Note
The unit tests and system tests are contained in the individual nox.py files in each directory; substitute datastore in the example above with the package of your choice.
Alternatively, you can just navigate directly to the package you are currently developing and run tests there:
$ export GIT_ROOT=$(pwd)
$ cd ${GIT_ROOT}/datastore/
$ nox -s "unit_tests(python_version='3.6')"
As mentioned previously, using setuptools in develop mode or a pip editable install is not possible with this library. This is because this library uses namespace packages. For context see Issue #2316 and the relevant PyPA issue.
Since editable / develop mode can't be used, packages need to be installed directly. Hence your changes to the source tree don't get incorporated into the already installed package.
If the error mentions Python.h not being found, install python-dev and try again. On Debian/Ubuntu:
$ sudo apt-get install python-dev
PEP8 compliance, with exceptions defined in the linter configuration. If you have nox installed, you can test that you have not introduced any non-compliant code via:
$ nox -s lint
In order to make nox -s lint run faster, you can set some environment variables:
export GOOGLE_CLOUD_TESTING_REMOTE="upstream" export GOOGLE_CLOUD_TESTING_BRANCH="master"
By doing this, you are specifying the location of the most up-to-date version of google-cloud-python. The the suggested remote name upstream should point to the official GoogleCloudPlatform checkout and the the branch should be the main branch on that remote (master).
Exceptions to PEP8:
To run system tests for a given package, you can execute:
$ nox -f datastore/nox.py -s "system_tests(python_version='3.6')" $ nox -f datastore/nox.py -s "system_tests(python_version='2.7')"
Note
System tests are only configured to run under Python 2.7 and Python 3.6. For expediency, we do not run them in older versions of Python 3.
This alone will not run the tests. You'll need to change some local auth settings and change some configuration in your project to run all the tests.
System tests will be run against an actual project and so you'll need to provide some environment variables to facilitate authentication to your project:
Examples of these can be found in system_tests/local_test_setup.sample. We recommend copying this to system_tests/local_test_setup, editing the values and sourcing them into your environment:
$ source system_tests/local_test_setup
For datastore tests, you'll need to create composite indexes with the gcloud command line tool:
# Install the app (App Engine Command Line Interface) component.
$ gcloud components install app-engine-python
# Authenticate the gcloud tool with your account.
$ GOOGLE_APPLICATION_CREDENTIALS="path/to/app_credentials.json"
$ gcloud auth activate-service-account \
> --key-file=${GOOGLE_APPLICATION_CREDENTIALS}
# Create the indexes
$ gcloud datastore create-indexes system_tests/data/index.yaml
For datastore query tests, you'll need stored data in your dataset. To populate this data, run:
$ python datastore/tests/system/utils/populate_datastore.py
If you make a mistake during development (i.e. a failing test that prevents clean-up) you can clear all system test data from your datastore instance via:
$ python datastore/tests/system/utils/clear_datastore.py
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.
To build and review docs (where ${VENV} refers to the virtualenv you're using to develop google-cloud-python):
After following the steps above in "Using a Development Checkout", install Sphinx and all development requirements in your virtualenv:
$ cd ${HOME}/hack-on-google-cloud-python
$ ${VENV}/bin/pip install Sphinx
Change into the docs directory within your google-cloud-python checkout and execute the make command with some flags:
$ cd ${HOME}/hack-on-google-cloud-python/google-cloud-python/docs
$ make clean html SPHINXBUILD=${VENV}/bin/sphinx-build
The SPHINXBUILD=... argument tells Sphinx to use the virtualenv Python, which will have both Sphinx and google-cloud-python (for API documentation generation) installed.
Open the docs/_build/html/index.html file to see the resulting HTML rendering.
As an alternative to 1. and 2. above, if you have nox installed, you can build the docs via:
$ nox -s docs
The description on PyPI for the project comes directly from the README. Due to the reStructuredText (rst) parser used by PyPI, relative links which will work on GitHub (e.g. CONTRIBUTING.rst instead of https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/CONTRIBUTING.rst) may cause problems creating links or rendering the description.
All build scripts in the .circleci/config.yml configuration file which have Python dependencies are specified in the nox.py configuration. They are executed in the Travis build via nox -s ${ENV} where ${ENV} is the environment being tested.
We support:
Supported versions can be found in our nox.py config.
We explicitly decided not to support Python 2.5 due to decreased usage and lack of continuous integration support.
We have dropped 2.6 as a supported version as well since Python 2.6 is no longer supported by the core development team.
We also explicitly decided to support Python 3 beginning with version 3.4. Reasons for this include:
This library follows Semantic Versioning.
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.
Before we can accept your pull requests you'll need to sign a Contributor License Agreement (CLA):
You can sign these electronically (just scroll to the bottom). After that, we'll be able to accept your pull requests.
| Back | FazBrowse Home | New Git URL |