Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Black. Template noxfile + flake8. #6642

Merged
merged 26 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b55e4e8
add templating to synth.py
crwilcox Nov 21, 2018
9f3eb87
synth'd noxfile .flake8 changes
crwilcox Nov 21, 2018
a3c7ee5
Flake8: ignore E501, W503
crwilcox Nov 21, 2018
d6bebcf
synth, flake8, coverage numbers
crwilcox Nov 22, 2018
b1f1556
blacken synth.py scripts
crwilcox Nov 22, 2018
5bda739
flake8 ignore from black
crwilcox Nov 22, 2018
a2f28e3
Merge branch 'master' into templating
crwilcox Nov 22, 2018
ac77ae1
update coveragerc across libraries
crwilcox Nov 26, 2018
3dee30b
Merge branch 'templating' of github.com:crwilcox/google-cloud-python …
crwilcox Nov 26, 2018
da853a5
revert errant change to core
crwilcox Nov 26, 2018
6e723cb
add coveragerc to all synth.py libraries and adjust coverage stats
crwilcox Nov 27, 2018
63a3f56
Merge branch 'master' of https://github.com/googleapis/google-cloud-p…
crwilcox Nov 27, 2018
03b6c43
also scan for system tests folder
crwilcox Nov 27, 2018
1f59f72
rerun templates
crwilcox Nov 27, 2018
1a34e9e
Merge branch 'master' into templating
crwilcox Nov 27, 2018
2bcf0ca
add core to omit list
crwilcox Nov 27, 2018
76ce7d8
exclude other modules (site-packages) from coverage
crwilcox Nov 27, 2018
d133c43
Use old version of logging noxfile
crwilcox Nov 27, 2018
743fc1c
install storage for vision sys tests
crwilcox Nov 28, 2018
cb5911f
Update vision synth to have storage installed for systests
crwilcox Nov 28, 2018
adb564c
update coverage stats
crwilcox Nov 28, 2018
93ee3c6
Merge branch 'master' of https://github.com/googleapis/google-cloud-p…
crwilcox Nov 28, 2018
d54c460
format job.py to fix linting errors
crwilcox Nov 28, 2018
5384600
format storage files to pass linting
crwilcox Nov 28, 2018
f80694e
bigquery linting fixes
crwilcox Nov 28, 2018
61f95c3
linting fixes
crwilcox Nov 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions asset/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[run]
branch = True

[report]
fail_under = 100
show_missing = True
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
# Ignore debug-only repr
def __repr__
# Ignore abstract methods
raise NotImplementedError
omit =
*/gapic/*.py
*/proto/*.py
*/google-cloud-python/core/*.py
*/site-packages/*.py
1 change: 1 addition & 0 deletions asset/.flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503

This comment was marked as spam.

This comment was marked as spam.

exclude =
# Exclude generated code.
**/proto/**
Expand Down
105 changes: 55 additions & 50 deletions asset/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,50 @@
import nox


LOCAL_DEPS = (os.path.join("..", "api_core"),)
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))

@nox.session(python="3.7")
def blacken(session):
"""Run black.

Format code to uniform standard.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)


@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", *LOCAL_DEPS)
session.run(
"black",
"--check",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)
session.run("flake8", "google", "tests")


@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):
Expand All @@ -39,7 +82,7 @@ def default(session):
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=86",
"--cov-fail-under=79",
os.path.join("tests", "unit"),
*session.posargs,
)
Expand All @@ -55,11 +98,15 @@ def unit(session):
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 the environment variable is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials 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 os.path.exists(system_test_path):
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.
Expand All @@ -74,52 +121,10 @@ def system(session):
session.install("-e", ".")

# Run py.test against the system tests.
session.run("py.test", "--quiet", system_test_path, *session.posargs)


@nox.session(python="3.7")
def blacken(session):
"""Run black.

Format code to uniform standard.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)


@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", *LOCAL_DEPS)
session.install(".")
session.run(
"black",
"--check",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)
session.run("flake8", "google", "tests")


@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")
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")
Expand All @@ -130,6 +135,6 @@ def cover(session):
test runs (not system test runs), and then erases coverage data.
"""
session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=85")
session.run("coverage", "report", "--show-missing", "--fail-under=80")

session.run("coverage", "erase")
23 changes: 11 additions & 12 deletions asset/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
from synthtool import gcp

gapic = gcp.GAPICGenerator()

common = gcp.CommonTemplates()
versions = ["v1beta1"]

excludes = [
'setup.py',
'nox*.py',
'README.rst',
'docs/conf.py',
'docs/index.rst',
]
excludes = ["setup.py", "nox*.py", "README.rst", "docs/conf.py", "docs/index.rst"]

# ----------------------------------------------------------------------------
# Generate asset GAPIC layer
# ----------------------------------------------------------------------------
for version in versions:
library = gapic.py_library(
"asset",
Expand All @@ -39,10 +36,6 @@

s.move(library, excludes=excludes)

templated_files = gcp.CommonTemplates().py_library(
unit_cov_level=86, cov_level=85)
s.move(templated_files)

s.replace(
"google/cloud/asset_v1beta1/proto/assets_pb2.py",
"from google.iam.v1 import policy_pb2 as",
Expand Down Expand Up @@ -85,3 +78,9 @@
_BORKED_ASSET_DOCSTRING,
_FIXED_ASSET_DOCSTRING,
)

# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
templated_files = gcp.CommonTemplates().py_library(unit_cov_level=79, cov_level=80)
s.move(templated_files)
4 changes: 4 additions & 0 deletions automl/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ exclude_lines =
pragma: NO COVER
# Ignore debug-only repr
def __repr__
# Ignore abstract methods
raise NotImplementedError
omit =
*/gapic/*.py
*/proto/*.py
*/google-cloud-python/core/*.py
*/site-packages/*.py
1 change: 1 addition & 0 deletions automl/.flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503
exclude =
# Exclude generated code.
**/proto/**
Expand Down
120 changes: 106 additions & 14 deletions automl/noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,31 +20,121 @@
import nox


LOCAL_DEPS = (
os.path.join('..', 'api_core'),
)
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))

@nox.session(python="3.7")
def blacken(session):
"""Run black.

Format code to uniform standard.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)


@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", *LOCAL_DEPS)
session.run(
"black",
"--check",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)
session.run("flake8", "google", "tests")


@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('pytest', 'mock')
session.install("mock", "pytest", "pytest-cov")
for local_dep in LOCAL_DEPS:
session.install('-e', local_dep)
session.install('-e', '.')
session.install("-e", local_dep)
session.install("-e", ".")

# Run py.test against the unit tests.
session.run('py.test', '--quiet', os.path.join('tests', 'unit'))
session.run(
"py.test",
"--quiet",
"--cov=google.cloud",
"--cov=tests.unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=82",
os.path.join("tests", "unit"),
*session.posargs,
)


@nox.session(python=['2.7', '3.5', '3.6', '3.7'])
@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
def unit(session):
"""Run the unit test suite."""
default(session)


@nox.session(python='3.6')
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')
@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 the environment variable is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials 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")
for local_dep in LOCAL_DEPS:
session.install("-e", local_dep)
session.install("-e", "../test_utils/")
session.install("-e", ".")

# 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=83")

session.run("coverage", "erase")
Loading