From b7707c58ae47a7af5a35289226e22040725eeff2 Mon Sep 17 00:00:00 2001 From: "STATION\\mf" Date: Tue, 25 Aug 2020 17:42:23 -0400 Subject: [PATCH 1/5] feat: 1st stage of `nox` implementation --- .gitignore | 16 ++++-- noxfile.py | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 noxfile.py diff --git a/.gitignore b/.gitignore index 10e8061ef3..b429d66666 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,16 @@ -*.egg-info *.py[co] -build/ *.sw[op] -.tox/ + +# Packages +*.egg-info +build MANIFEST -dist/ +dist django_tests + +# Unit test / coverage reports +.coverage +.tox + +# JetBrains +.idea diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000000..64db6440dd --- /dev/null +++ b/noxfile.py @@ -0,0 +1,152 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2020 Google LLC +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + + +from __future__ import absolute_import + +import nox +import os +# import shutil + + +BLACK_VERSION = "black==19.3b0" +BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] + +if os.path.exists("samples"): + BLACK_PATHS.append("samples") + + +# @nox.session(python="3.7") +# def lint(session): +# """Run linters. +# +# Returns a failure if the linters find linting errors or sufficiently +# serious code quality issues. +# """ +# session.install("flake8", BLACK_VERSION) +# session.run("black", "--check", *BLACK_PATHS) +# session.run("flake8", "google", "tests") + + +# @nox.session(python="3.6") +# def blacken(session): +# """Run black. +# +# Format code to uniform standard. +# +# This currently uses Python 3.6 due to the automated Kokoro run of synthtool. +# That run uses an image that doesn't have 3.6 installed. Before updating this +# check the state of the `gcp_ubuntu_config` we use for that Kokoro run. +# """ +# session.install(BLACK_VERSION) +# session.run("black", *BLACK_PATHS) + + +# @nox.session(python="3.7") +# def lint_setup_py(session): +# """Verify that setup.py is valid (including RST check).""" +# session.install("docutils", "pygments") +# session.run("python", "setup.py", "check", "--restructuredtext", "--strict") + + +def default(session): + # Install all test dependencies, then install this package in-place. + session.install("mock", "pytest", "pytest-cov") + session.install("-e", ".") + + # Run py.test against the unit tests. + session.run( + "py.test", + # "--quiet", + # "--cov=google.cloud", + # "--cov=tests.unit", + # "--cov-append", + # "--cov-config=.coveragerc", + # "--cov-report=", + # "--cov-fail-under=0", + # os.path.join("tests", "unit"), + os.path.join("tests", "spanner_dbapi"), + *session.posargs, + ) + + +@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"]) +def unit(session): + """Run the unit test suite.""" + default(session) + + +# @nox.session(python=["2.7", "3.7"]) +# def system(session): +# """Run the system test suite.""" +# system_test_path = os.path.join("tests", "system.py") +# system_test_folder_path = os.path.join("tests", "system") +# # Sanity check: Only run tests if either credentials or emulator host is set. +# if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") and not os.environ.get( +# "SPANNER_EMULATOR_HOST", "" +# ): +# session.skip( +# "Credentials or emulator host must be set via environment variable" +# ) +# +# system_test_exists = os.path.exists(system_test_path) +# system_test_folder_exists = os.path.exists(system_test_folder_path) +# # Sanity check: only run tests if found. +# if not system_test_exists and not system_test_folder_exists: +# session.skip("System tests were not found") +# +# # Use pre-release gRPC for system tests. +# session.install("--pre", "grpcio") +# +# # Install all test dependencies, then install this package into the +# # virtualenv's dist-packages. +# session.install("mock", "pytest") +# +# session.install("-e", ".") +# session.install("-e", "test_utils/") +# +# # Run py.test against the system tests. +# if system_test_exists: +# session.run("py.test", "--quiet", system_test_path, *session.posargs) +# if system_test_folder_exists: +# session.run("py.test", "--quiet", system_test_folder_path, *session.posargs) + + +# @nox.session(python="3.7") +# def cover(session): +# """Run the final coverage report. +# +# This outputs the coverage report aggregating coverage from the unit +# test runs (not system test runs), and then erases coverage data. +# """ +# session.install("coverage", "pytest-cov") +# session.run("coverage", "report", "--show-missing", "--fail-under=99") +# +# session.run("coverage", "erase") + + +# @nox.session(python="3.7") +# def docs(session): +# """Build the docs for this library.""" +# +# session.install("-e", ".") +# session.install("sphinx", "alabaster", "recommonmark") +# +# shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) +# session.run( +# "sphinx-build", +# "-W", # warnings as errors +# "-T", # show full traceback on exception +# "-N", # no colors +# "-b", +# "html", +# "-d", +# os.path.join("docs", "_build", "doctrees", ""), +# os.path.join("docs", ""), +# os.path.join("docs", "_build", "html", ""), +# ) From 1857f0f1dc42e53e4f7e21f30dc5766cbf125c4a Mon Sep 17 00:00:00 2001 From: "STATION\\mf" Date: Tue, 25 Aug 2020 18:36:20 -0400 Subject: [PATCH 2/5] cleanup: Commented lines removed --- noxfile.py | 121 +---------------------------------------------------- 1 file changed, 1 insertion(+), 120 deletions(-) diff --git a/noxfile.py b/noxfile.py index 64db6440dd..39c7f210c0 100644 --- a/noxfile.py +++ b/noxfile.py @@ -11,47 +11,6 @@ import nox import os -# import shutil - - -BLACK_VERSION = "black==19.3b0" -BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] - -if os.path.exists("samples"): - BLACK_PATHS.append("samples") - - -# @nox.session(python="3.7") -# def lint(session): -# """Run linters. -# -# Returns a failure if the linters find linting errors or sufficiently -# serious code quality issues. -# """ -# session.install("flake8", BLACK_VERSION) -# session.run("black", "--check", *BLACK_PATHS) -# session.run("flake8", "google", "tests") - - -# @nox.session(python="3.6") -# def blacken(session): -# """Run black. -# -# Format code to uniform standard. -# -# This currently uses Python 3.6 due to the automated Kokoro run of synthtool. -# That run uses an image that doesn't have 3.6 installed. Before updating this -# check the state of the `gcp_ubuntu_config` we use for that Kokoro run. -# """ -# session.install(BLACK_VERSION) -# session.run("black", *BLACK_PATHS) - - -# @nox.session(python="3.7") -# def lint_setup_py(session): -# """Verify that setup.py is valid (including RST check).""" -# session.install("docutils", "pygments") -# session.run("python", "setup.py", "check", "--restructuredtext", "--strict") def default(session): @@ -62,14 +21,7 @@ def default(session): # Run py.test against the unit tests. session.run( "py.test", - # "--quiet", - # "--cov=google.cloud", - # "--cov=tests.unit", - # "--cov-append", - # "--cov-config=.coveragerc", - # "--cov-report=", - # "--cov-fail-under=0", - # os.path.join("tests", "unit"), + "--quiet", os.path.join("tests", "spanner_dbapi"), *session.posargs, ) @@ -79,74 +31,3 @@ def default(session): def unit(session): """Run the unit test suite.""" default(session) - - -# @nox.session(python=["2.7", "3.7"]) -# def system(session): -# """Run the system test suite.""" -# system_test_path = os.path.join("tests", "system.py") -# system_test_folder_path = os.path.join("tests", "system") -# # Sanity check: Only run tests if either credentials or emulator host is set. -# if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") and not os.environ.get( -# "SPANNER_EMULATOR_HOST", "" -# ): -# session.skip( -# "Credentials or emulator host must be set via environment variable" -# ) -# -# system_test_exists = os.path.exists(system_test_path) -# system_test_folder_exists = os.path.exists(system_test_folder_path) -# # Sanity check: only run tests if found. -# if not system_test_exists and not system_test_folder_exists: -# session.skip("System tests were not found") -# -# # Use pre-release gRPC for system tests. -# session.install("--pre", "grpcio") -# -# # Install all test dependencies, then install this package into the -# # virtualenv's dist-packages. -# session.install("mock", "pytest") -# -# session.install("-e", ".") -# session.install("-e", "test_utils/") -# -# # Run py.test against the system tests. -# if system_test_exists: -# session.run("py.test", "--quiet", system_test_path, *session.posargs) -# if system_test_folder_exists: -# session.run("py.test", "--quiet", system_test_folder_path, *session.posargs) - - -# @nox.session(python="3.7") -# def cover(session): -# """Run the final coverage report. -# -# This outputs the coverage report aggregating coverage from the unit -# test runs (not system test runs), and then erases coverage data. -# """ -# session.install("coverage", "pytest-cov") -# session.run("coverage", "report", "--show-missing", "--fail-under=99") -# -# session.run("coverage", "erase") - - -# @nox.session(python="3.7") -# def docs(session): -# """Build the docs for this library.""" -# -# session.install("-e", ".") -# session.install("sphinx", "alabaster", "recommonmark") -# -# shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) -# session.run( -# "sphinx-build", -# "-W", # warnings as errors -# "-T", # show full traceback on exception -# "-N", # no colors -# "-b", -# "html", -# "-d", -# os.path.join("docs", "_build", "doctrees", ""), -# os.path.join("docs", ""), -# os.path.join("docs", "_build", "html", ""), -# ) From 397283c6add190e78cc7d764327c222a9f2399c9 Mon Sep 17 00:00:00 2001 From: "STATION\\mf" Date: Tue, 25 Aug 2020 18:48:28 -0400 Subject: [PATCH 3/5] cleanup: Removed deprecated `tox.ini` and `runtests.py` as superseded by `noxfile.py` --- runtests.py | 30 ------------------------------ tox.ini | 24 ------------------------ 2 files changed, 54 deletions(-) delete mode 100644 runtests.py delete mode 100644 tox.ini diff --git a/runtests.py b/runtests.py deleted file mode 100644 index c0ae9c3121..0000000000 --- a/runtests.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 Google LLC -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -import sys -import unittest - - -def run_unittests(module): - test_suite = unittest.TestLoader().discover(module) - result = unittest.TextTestRunner(verbosity=1).run(test_suite) - sys.exit(any(result.failures or result.errors)) - - -def run_parse_util_tests(): - pass - - -def run_django_tests(): - raise Exception('Unimplemented') - - -def main(): - run_unittests('tests.spanner_dbapi') - - -if __name__ == '__main__': - main() diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 94d9bbe241..0000000000 --- a/tox.ini +++ /dev/null @@ -1,24 +0,0 @@ -[tox] -envlist = - py3{7}-django{22} - flake8 - -[testenv] -setenv = - PYTHONDONTWRITEBYTECODE = 1 - PYTHONWARNINGS = all -deps = - django21: Django>=2.1,<2.2 - django22: Django>=2.2,<3.0 - six -commands = - python runtests.py - -[testenv:flake8] -skip_install = True -deps = - flake8 - isort -commands = - flake8 - isort --recursive --check-only --diff From 43b186ee4d8fe746730aeb1dc8bd202d1df5c7c0 Mon Sep 17 00:00:00 2001 From: "STATION\\mf" Date: Tue, 25 Aug 2020 19:26:19 -0400 Subject: [PATCH 4/5] fix: updated `.kokoro/build.sh` for `nox` usage --- .kokoro/build.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 077b737c5b..8d7113079a 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -29,13 +29,20 @@ export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json # Setup project id. export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json") -# Install tox -python3.6 -m pip install --upgrade --quiet tox flake8 isort -python3.6 -m tox --version +# Remove old nox +python3.6 -m pip uninstall --yes --quiet nox-automation -python3.6 -m tox -python3.6 -m isort --recursive --check-only --diff -python3.6 -m flake8 +# Install nox +python3.6 -m pip install --upgrade --quiet nox +python3.6 -m nox --version + +# If NOX_SESSION is set, it only runs the specified session, +# otherwise run all the sessions. +if [[ -n "${NOX_SESSION:-}" ]]; then + python3.6 -m nox -s "${NOX_SESSION:-}" +else + python3.6 -m nox +fi # Export essential environment variables for Django tests. export RUNNING_SPANNER_BACKEND_TESTS=1 From c59213cf54260376e335ceb9fb2436574037f44f Mon Sep 17 00:00:00 2001 From: "STATION\\mf" Date: Tue, 25 Aug 2020 19:40:31 -0400 Subject: [PATCH 5/5] cleanup: removed "2.7" from `nox` session targets. --- .gitignore | 2 +- noxfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b429d66666..863e1d3d77 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ django_tests # Unit test / coverage reports .coverage -.tox +.nox # JetBrains .idea diff --git a/noxfile.py b/noxfile.py index 39c7f210c0..1f6b4df1e5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -27,7 +27,7 @@ def default(session): ) -@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"]) +@nox.session(python=["3.5", "3.6", "3.7", "3.8"]) def unit(session): """Run the unit test suite.""" default(session)