chore: use nox and release-please; drop 3.4 (#852)



Co-authored-by: Kamil Breguła <mik-laj@users.noreply.github.com>
Co-authored-by: Christopher Wilcox <crwilcox@google.com>
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 3d44f3e..7d35265 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -11,23 +11,33 @@
 Please run down the following list and make sure you've tried the usual "quick fixes":
 
   - Search the issues already opened: https://github.com/googleapis/google-api-python-client/issues
-  - If you have a question, post on Stackoverflow under the `google-api` tag.
-  - If you are reporting an issue or requesting a feature for a G Suite API, please use their [public issue tracker](https://gsuite-developers.googleblog.com/2017/03/a-new-issue-tracker-for-g-suite.html)
+  - Search StackOverflow: https://stackoverflow.com/questions/tagged/google-cloud-platform+python
 
 If you are still having issues, please be sure to include as much information as possible:
 
 #### Environment details
 
-  - OS:
-  - Python version:
-  - pip version:
-  - `google-api-python-client` version:
+  - OS type and version:
+  - Python version: `python --version`
+  - pip version: `pip --version`
+  - `google-api-python-client` version: `pip show google-api-python-client`
 
 #### Steps to reproduce
 
   1. ?
   2. ?
 
+#### Code example
+
+```python
+# example
+```
+
+#### Stack trace
+```
+# example
+```
+
 Making sure to follow these steps will guarantee the quickest resolution possible.
 
 Thanks!
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..24c6fa8
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,7 @@
+Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
+- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-api-python-client/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
+- [ ] Ensure the tests and linter pass
+- [ ] Code coverage does not decrease (if any source code was changed)
+- [ ] Appropriate docs were updated (if necessary)
+
+Fixes #<issue_number_goes_here> 🦕
diff --git a/.github/release-please.yml b/.github/release-please.yml
new file mode 100644
index 0000000..4507ad0
--- /dev/null
+++ b/.github/release-please.yml
@@ -0,0 +1 @@
+releaseType: python
diff --git a/.gitignore b/.gitignore
index cf2c4a6..1637b1d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,7 +5,7 @@
 dist/
 
 # Test files
-.tox/
+.nox/
 
 # Coverage files
 .coverage
diff --git a/.kokoro/build.sh b/.kokoro/build.sh
index e0c966b..ab8cebb 100755
--- a/.kokoro/build.sh
+++ b/.kokoro/build.sh
@@ -1,4 +1,17 @@
 #!/bin/bash
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
 
 set -eo pipefail
 
@@ -7,7 +20,20 @@
 # Disable buffering, so that the logs stream through.
 export PYTHONUNBUFFERED=1
 
-python3 -m pip install --upgrade tox
+# Debug: show build environment
+env | grep KOKORO
 
-# Run tests
-tox
+# Setup service account credentials.
+export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json
+
+# Setup project id.
+export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
+
+# Remove old nox
+python3.6 -m pip uninstall --yes --quiet nox-automation
+
+# Install nox
+python3.6 -m pip install --upgrade --quiet nox
+python3.6 -m nox --version
+
+python3.6 -m nox
diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg
deleted file mode 100644
index c21dc6d..0000000
--- a/.kokoro/common.cfg
+++ /dev/null
@@ -1,19 +0,0 @@
-# Format: //devtools/kokoro/config/proto/build.proto
-
-# Download trampoline resources.
-gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
-
-# Use the trampoline script to run in docker.
-build_file: "google-api-python-client/.kokoro/trampoline.sh"
-
-# Configure the docker image for kokoro-trampoline.
-env_vars: {
-    key: "TRAMPOLINE_IMAGE"
-    value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
-}
-
-# Tell the trampoline which build file to use.
-env_vars: {
-    key: "TRAMPOLINE_BUILD_FILE"
-    value: "github/google-api-python-client/.kokoro/build.sh"
-}
diff --git a/.kokoro/continuous/continuous.cfg b/.kokoro/continuous/continuous.cfg
index 18a4c35..8f43917 100644
--- a/.kokoro/continuous/continuous.cfg
+++ b/.kokoro/continuous/continuous.cfg
@@ -1 +1 @@
-# Format: //devtools/kokoro/config/proto/build.proto
+# Format: //devtools/kokoro/config/proto/build.proto
\ No newline at end of file
diff --git a/.kokoro/presubmit/presubmit.cfg b/.kokoro/presubmit/presubmit.cfg
index 18a4c35..8f43917 100644
--- a/.kokoro/presubmit/presubmit.cfg
+++ b/.kokoro/presubmit/presubmit.cfg
@@ -1 +1 @@
-# Format: //devtools/kokoro/config/proto/build.proto
+# Format: //devtools/kokoro/config/proto/build.proto
\ No newline at end of file
diff --git a/.kokoro/release.sh b/.kokoro/release.sh
new file mode 100755
index 0000000..b4756d0
--- /dev/null
+++ b/.kokoro/release.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/bin/bash
+
+set -eo pipefail
+
+# Start the releasetool reporter
+python3 -m pip install gcp-releasetool
+python3 -m releasetool publish-reporter-script > /tmp/publisher-script; source /tmp/publisher-script
+
+# Ensure that we have the latest versions of Twine, Wheel, and Setuptools.
+python3 -m pip install --upgrade twine wheel setuptools
+
+# Disable buffering, so that the logs stream through.
+export PYTHONUNBUFFERED=1
+
+# Move into the package, build the distribution and upload.
+TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google_cloud_pypi_password")
+cd github/google-api-python-client
+python3 setup.py sdist bdist_wheel
+twine upload --username gcloudpypi --password "${TWINE_PASSWORD}" dist/*
diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg
new file mode 100644
index 0000000..6a8864b
--- /dev/null
+++ b/.kokoro/release/common.cfg
@@ -0,0 +1,64 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Build logs will be here
+action {
+  define_artifacts {
+    regex: "**/*sponge_log.xml"
+  }
+}
+
+# Download trampoline resources.
+gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
+
+# Use the trampoline script to run in docker.
+build_file: "google-api-python-client/.kokoro/trampoline.sh"
+
+# Configure the docker image for kokoro-trampoline.
+env_vars: {
+    key: "TRAMPOLINE_IMAGE"
+    value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
+}
+env_vars: {
+    key: "TRAMPOLINE_BUILD_FILE"
+    value: "github/google-api-python-client/.kokoro/release.sh"
+}
+
+# Fetch the token needed for reporting release status to GitHub
+before_action {
+  fetch_keystore {
+    keystore_resource {
+      keystore_config_id: 73713
+      keyname: "yoshi-automation-github-key"
+    }
+  }
+}
+
+# Fetch PyPI password
+before_action {
+  fetch_keystore {
+    keystore_resource {
+      keystore_config_id: 73713
+      keyname: "google_cloud_pypi_password"
+    }
+  }
+}
+
+# Fetch magictoken to use with Magic Github Proxy 
+before_action {
+  fetch_keystore {
+    keystore_resource {
+      keystore_config_id: 73713
+      keyname: "releasetool-magictoken"
+    }
+  }
+}
+
+# Fetch api key to use with Magic Github Proxy 
+before_action {
+  fetch_keystore {
+    keystore_resource {
+      keystore_config_id: 73713
+      keyname: "magic-github-proxy-api-key"
+    }
+  }
+}
diff --git a/.kokoro/release/release.cfg b/.kokoro/release/release.cfg
new file mode 100644
index 0000000..8f43917
--- /dev/null
+++ b/.kokoro/release/release.cfg
@@ -0,0 +1 @@
+# Format: //devtools/kokoro/config/proto/build.proto
\ No newline at end of file
diff --git a/.kokoro/trampoline.sh b/.kokoro/trampoline.sh
index 0efc3be..e8c4251 100755
--- a/.kokoro/trampoline.sh
+++ b/.kokoro/trampoline.sh
@@ -12,13 +12,12 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 set -eo pipefail
-# Always run the cleanup script, regardless of the success of bouncing into
-# the container.
-function cleanup() {
-    chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
-    ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
-    echo "cleanup";
-}
-trap cleanup EXIT
-python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"
+
+python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"  || ret_code=$?
+
+chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
+${KOKORO_GFILE_DIR}/trampoline_cleanup.sh || true
+
+exit ${ret_code}
diff --git a/.repo-metadata.json b/.repo-metadata.json
new file mode 100644
index 0000000..1b810b0
--- /dev/null
+++ b/.repo-metadata.json
@@ -0,0 +1,11 @@
+  
+{
+    "name": "google-api-python-client",
+    "name_pretty": "Google API Python Client",
+    "client_documentation": "https://github.com/googleapis/google-api-python-client/tree/master/docs#google-api-client-library-for-python-docs",
+    "issue_tracker": "https://github.com/googleapis/google-api-python-client/issues",
+    "release_level": "ga",
+    "language": "python",
+    "repo": "googleapis/google-api-python-client",
+    "distribution_name": "google-api-python-client"
+  }
\ No newline at end of file
diff --git a/googleapiclient/__init__.py b/googleapiclient/__init__.py
index b9db848..c9218dd 100644
--- a/googleapiclient/__init__.py
+++ b/googleapiclient/__init__.py
@@ -12,8 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-__version__ = "1.8.0"
-
 # Set default logging handler to avoid "No handler found" warnings.
 import logging
 
diff --git a/googleapiclient/model.py b/googleapiclient/model.py
index 7255ecf..f58549c 100644
--- a/googleapiclient/model.py
+++ b/googleapiclient/model.py
@@ -27,12 +27,13 @@
 import json
 import logging
 import platform
+import pkg_resources
 
 from six.moves.urllib.parse import urlencode
 
-from googleapiclient import __version__
 from googleapiclient.errors import HttpError
 
+_LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
 _PY_VERSION = platform.python_version()
 
 LOGGER = logging.getLogger(__name__)
@@ -152,7 +153,7 @@
         else:
             headers["x-goog-api-client"] = ""
         headers["x-goog-api-client"] += "gdcl/%s gl-python/%s" % (
-            __version__,
+            _LIBRARY_VERSION,
             _PY_VERSION,
         )
 
diff --git a/noxfile.py b/noxfile.py
new file mode 100644
index 0000000..438ff41
--- /dev/null
+++ b/noxfile.py
@@ -0,0 +1,78 @@
+
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import nox
+
+test_dependencies = [
+    "google-auth",
+    "google-auth-httplib2",
+    "mox",
+    "pyopenssl",
+    "pytest",
+    "pytest-cov",
+    "webtest",
+    "coverage",
+    "unittest2",
+    "mock",
+]
+
+
+@nox.session(python=["3.7"])
+def lint(session):
+    session.install("flake8")
+    session.run(
+        "flake8",
+        "googleapiclient",
+        "tests",
+        "--count",
+        "--select=E9,F63,F7,F82",
+        "--show-source",
+        "--statistics",
+    )
+
+
+@nox.parametrize(
+    "oauth2client",
+    [
+        "oauth2client<2dev",
+        "oauth2client>=2,<=3dev",
+        "oauth2client>=3,<=4dev",
+        "oauth2client>=4,<=5dev",
+    ],
+)
+@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
+def unit(session, oauth2client):
+    session.install(*test_dependencies)
+    session.install(oauth2client)
+    if session.python < "3.0":
+        session.install("django<2.0.0")
+    else:
+        session.install("django>=2.0.0")
+
+    session.install('.')
+
+    # Run py.test against the unit tests.
+    session.run(
+        "py.test",
+        "--quiet",
+        "--cov=googleapiclient",
+        "--cov=tests",
+        "--cov-append",
+        "--cov-config=.coveragerc",
+        "--cov-report=",
+        "--cov-fail-under=85",
+        "tests",
+        *session.posargs,
+    )
\ No newline at end of file
diff --git a/setup.py b/setup.py
index cf135a9..4174362 100644
--- a/setup.py
+++ b/setup.py
@@ -28,6 +28,8 @@
     print("google-api-python-client requires python3 version >= 3.4.", file=sys.stderr)
     sys.exit(1)
 
+import io
+import os
 from setuptools import setup
 
 packages = ["apiclient", "googleapiclient", "googleapiclient/discovery_cache"]
@@ -44,19 +46,22 @@
     "uritemplate>=3.0.0,<4dev",
 ]
 
-long_desc = """The Google API Client for Python is a client library for
-accessing the Plus, Moderator, and many other Google APIs."""
+package_root = os.path.abspath(os.path.dirname(__file__))
 
-import googleapiclient
+readme_filename = os.path.join(package_root, "README.md")
+with io.open(readme_filename, encoding="utf-8") as readme_file:
+    readme = readme_file.read()
 
-version = googleapiclient.__version__
+version = "1.8.0"
 
 setup(
     name="google-api-python-client",
     version=version,
     description="Google API Client Library for Python",
-    long_description=long_desc,
-    author="Google Inc.",
+    long_description=readme,
+    long_description_content_type='text/markdown',
+    author="Google LLC",
+    author_email="googleapis-packages@google.com",
     url="http://github.com/google/google-api-python-client/",
     install_requires=install_requires,
     python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
@@ -68,7 +73,6 @@
         "Programming Language :: Python :: 2",
         "Programming Language :: Python :: 2.7",
         "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.4",
         "Programming Language :: Python :: 3.5",
         "Programming Language :: Python :: 3.6",
         "Programming Language :: Python :: 3.7",
diff --git a/synth.metadata b/synth.metadata
new file mode 100644
index 0000000..d06a0f1
--- /dev/null
+++ b/synth.metadata
@@ -0,0 +1,12 @@
+{
+  "updateTime": "2020-03-30T20:47:31.469660Z",
+  "sources": [
+    {
+      "git": {
+        "name": "synthtool",
+        "remote": "https://github.com/googleapis/synthtool.git",
+        "sha": "f5e8c88d9870d8aa4eb43fa0b39f07e02bfbe4df"
+      }
+    }
+  ]
+}
\ No newline at end of file
diff --git a/synth.py b/synth.py
new file mode 100644
index 0000000..017717d
--- /dev/null
+++ b/synth.py
@@ -0,0 +1,30 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import synthtool as s
+from synthtool import gcp
+
+common = gcp.CommonTemplates()
+
+# ----------------------------------------------------------------------------
+# Add templated files
+# ----------------------------------------------------------------------------
+templated_files = common.py_library()
+
+# Copy kokoro configs.
+# Docs are excluded as repo docs cannot currently be generated using sphinx.
+s.move(templated_files / '.kokoro', excludes=['**/docs/*', 'publish-docs.sh'])
+
+# Also move issue templates
+s.move(templated_files / '.github')
\ No newline at end of file
diff --git a/tests/test_json_model.py b/tests/test_json_model.py
index 0064f3f..6857803 100644
--- a/tests/test_json_model.py
+++ b/tests/test_json_model.py
@@ -26,17 +26,19 @@
 import copy
 import json
 import os
+import pkg_resources
 import platform
 import unittest2 as unittest
 import httplib2
 import googleapiclient.model
 
-from googleapiclient import __version__
 from googleapiclient.errors import HttpError
 from googleapiclient.model import JsonModel
 
 from six.moves.urllib.parse import parse_qs
 
+_LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
+
 
 class Model(unittest.TestCase):
     def test_json_no_body(self):
@@ -171,7 +173,7 @@
             headers["x-goog-api-client"],
             "gccl/1.23.4"
             + " gdcl/"
-            + __version__
+            + _LIBRARY_VERSION
             + " gl-python/"
             + platform.python_version(),
         )
diff --git a/tox.ini b/tox.ini
deleted file mode 100644
index 1d9bc13..0000000
--- a/tox.ini
+++ /dev/null
@@ -1,24 +0,0 @@
-[tox]
-envlist = py{27,34,35,36,37}-oauth2client{1,2,3,4}
-
-[testenv]
-deps =
-       oauth2client1: oauth2client<2dev
-       oauth2client2: oauth2client>=2,<=3dev
-       oauth2client3: oauth2client>=3,<=4dev
-       oauth2client4: oauth2client>=4,<=5dev
-       google-auth
-       google-auth-httplib2
-       mox
-       pyopenssl
-       django<2.0.0; python_version < '3.0.0'
-       django>=2.0.0; python_version > '3.0.0'
-       flake8
-       webtest
-       nose
-       coverage>=3.6,<3.99
-       unittest2
-       mock
-commands =
-       flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
-       nosetests --with-coverage --cover-package=googleapiclient --nocapture --cover-erase --cover-tests --cover-branches --cover-min-percentage=85 []