Skip to content

Commit 28cee5a

Browse files
authored
Add templates for flake8, coveragerc, noxfile, and black. (#6642)
1 parent c38f32e commit 28cee5a

File tree

4 files changed

+157
-63
lines changed

4 files changed

+157
-63
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
fail_under = 100
6+
show_missing = True
7+
exclude_lines =
8+
# Re-enable the standard pragma
9+
pragma: NO COVER
10+
# Ignore debug-only repr
11+
def __repr__
12+
# Ignore abstract methods
13+
raise NotImplementedError
14+
omit =
15+
*/gapic/*.py
16+
*/proto/*.py
17+
*/google-cloud-python/core/*.py
18+
*/site-packages/*.py
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
ignore = E203, E266, E501, W503
3+
exclude =
4+
# Exclude generated code.
5+
**/proto/**
6+
**/gapic/**
7+
*_pb2.py
8+
9+
# Standard linting exemptions.
10+
__pycache__,
11+
.git,
12+
*.pyc,
13+
conf.py
Lines changed: 97 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Copyright 2017, Google LLC All rights reserved.
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
46
# you may not use this file except in compliance with the License.
57
# You may obtain a copy of the License at
68
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
9+
# https://www.apache.org/licenses/LICENSE-2.0
810
#
911
# Unless required by applicable law or agreed to in writing, software
1012
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,74 +15,126 @@
1315
# limitations under the License.
1416

1517
from __future__ import absolute_import
16-
1718
import os
1819

1920
import nox
2021

2122

22-
LOCAL_DEPS = (
23-
os.path.join('..', 'api_core'),
24-
)
23+
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))
2524

25+
@nox.session(python="3.7")
26+
def blacken(session):
27+
"""Run black.
28+
29+
Format code to uniform standard.
30+
"""
31+
session.install("black")
32+
session.run(
33+
"black",
34+
"google",
35+
"tests",
36+
"docs",
37+
"--exclude",
38+
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
39+
)
2640

27-
def default(session):
28-
"""Default unit test session.
2941

30-
This is intended to be run **without** an interpreter set, so
31-
that the current ``python`` (on the ``PATH``) or the version of
32-
Python corresponding to the ``nox`` binary on the ``PATH`` can
33-
run the tests.
42+
@nox.session(python="3.7")
43+
def lint(session):
44+
"""Run linters.
45+
46+
Returns a failure if the linters find linting errors or sufficiently
47+
serious code quality issues.
3448
"""
49+
session.install("flake8", "black", *LOCAL_DEPS)
50+
session.run(
51+
"black",
52+
"--check",
53+
"google",
54+
"tests",
55+
"docs",
56+
"--exclude",
57+
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
58+
)
59+
session.run("flake8", "google", "tests")
60+
61+
62+
@nox.session(python="3.7")
63+
def lint_setup_py(session):
64+
"""Verify that setup.py is valid (including RST check)."""
65+
session.install("docutils", "pygments")
66+
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
67+
68+
69+
def default(session):
3570
# Install all test dependencies, then install this package in-place.
36-
session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS)
37-
session.install('-e', '.')
71+
session.install("mock", "pytest", "pytest-cov")
72+
for local_dep in LOCAL_DEPS:
73+
session.install("-e", local_dep)
74+
session.install("-e", ".")
3875

3976
# Run py.test against the unit tests.
4077
session.run(
41-
'py.test',
42-
'--quiet',
43-
'--cov=google.cloud.bigquery_datatransfer',
44-
'--cov=google.cloud.bigquery_datatransfer_v1',
45-
'--cov=tests.unit',
46-
'--cov-append',
47-
'--cov-config=.coveragerc',
48-
'--cov-report=',
49-
os.path.join('tests', 'unit', 'gapic', 'v1'),
50-
*session.posargs
78+
"py.test",
79+
"--quiet",
80+
"--cov=google.cloud",
81+
"--cov=tests.unit",
82+
"--cov-append",
83+
"--cov-config=.coveragerc",
84+
"--cov-report=",
85+
"--cov-fail-under=80",
86+
os.path.join("tests", "unit"),
87+
*session.posargs,
5188
)
5289

5390

54-
@nox.session(python=['2.7', '3.5', '3.6', '3.7'])
91+
@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
5592
def unit(session):
5693
"""Run the unit test suite."""
5794
default(session)
5895

5996

60-
@nox.session(python='3.6')
61-
def lint_setup_py(session):
62-
"""Verify that setup.py is valid (including RST check)."""
63-
session.install('docutils', 'pygments')
64-
session.run('python', 'setup.py', 'check', '--restructuredtext',
65-
'--strict')
66-
67-
68-
@nox.session(python=['2.7', '3.6'])
97+
@nox.session(python=["2.7", "3.7"])
6998
def system(session):
7099
"""Run the system test suite."""
71-
72-
# Sanity check: Only run system tests if the environment variable is set.
73-
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
74-
session.skip('Credentials must be set via environment variable.')
100+
system_test_path = os.path.join("tests", "system.py")
101+
system_test_folder_path = os.path.join("tests", "system")
102+
# Sanity check: Only run tests if the environment variable is set.
103+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
104+
session.skip("Credentials must be set via environment variable")
105+
106+
system_test_exists = os.path.exists(system_test_path)
107+
system_test_folder_exists = os.path.exists(system_test_folder_path)
108+
# Sanity check: only run tests if found.
109+
if not system_test_exists and not system_test_folder_exists:
110+
session.skip("System tests were not found")
75111

76112
# Use pre-release gRPC for system tests.
77-
session.install('--pre', 'grpcio')
113+
session.install("--pre", "grpcio")
78114

79115
# Install all test dependencies, then install this package into the
80116
# virtualenv's dist-packages.
81-
session.install('mock', 'pytest')
82-
session.install('../test_utils/')
83-
session.install('.')
117+
session.install("mock", "pytest")
118+
for local_dep in LOCAL_DEPS:
119+
session.install("-e", local_dep)
120+
session.install("-e", "../test_utils/")
121+
session.install("-e", ".")
84122

85123
# Run py.test against the system tests.
86-
session.run('py.test', '--quiet', 'tests/system/')
124+
if system_test_exists:
125+
session.run("py.test", "--quiet", system_test_path, *session.posargs)
126+
if system_test_folder_exists:
127+
session.run("py.test", "--quiet", system_test_folder_path, *session.posargs)
128+
129+
130+
@nox.session(python="3.7")
131+
def cover(session):
132+
"""Run the final coverage report.
133+
134+
This outputs the coverage report aggregating coverage from the unit
135+
test runs (not system test runs), and then erases coverage data.
136+
"""
137+
session.install("coverage", "pytest-cov")
138+
session.run("coverage", "report", "--show-missing", "--fail-under=80")
139+
140+
session.run("coverage", "erase")

packages/google-cloud-bigquery-datatransfer/synth.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,48 @@
1818
from synthtool import gcp
1919

2020
gapic = gcp.GAPICGenerator()
21+
common = gcp.CommonTemplates()
22+
version = "v1"
2123

22-
version = 'v1'
23-
24+
# ----------------------------------------------------------------------------
25+
# Generate bigquery_datatransfer GAPIC layer
26+
# ----------------------------------------------------------------------------
2427
library = gapic.py_library(
25-
'bigquery-datatransfer',
28+
"bigquery-datatransfer",
2629
version,
27-
config_path='/google/cloud/bigquery/datatransfer/'
28-
'artman_bigquerydatatransfer.yaml',
29-
artman_output_name='bigquerydatatransfer-v1'
30+
config_path="/google/cloud/bigquery/datatransfer/"
31+
"artman_bigquerydatatransfer.yaml",
32+
artman_output_name="bigquerydatatransfer-v1",
3033
)
3134

3235
s.move(
3336
library,
34-
excludes=['docs/conf.py', 'docs/index.rst', 'README.rst',
35-
'nox.py', 'setup.py']
37+
excludes=["docs/conf.py", "docs/index.rst", "README.rst", "nox.py", "setup.py"],
3638
)
3739

3840
s.replace(
39-
['google/cloud/bigquery_datatransfer_v1/proto/datatransfer_pb2.py',
40-
'google/cloud/bigquery_datatransfer_v1/proto/datatransfer_pb2_grpc.py'],
41-
'from google.cloud.bigquery.datatransfer_v1.proto',
42-
'from google.cloud.bigquery_datatransfer_v1.proto'
41+
[
42+
"google/cloud/bigquery_datatransfer_v1/proto/datatransfer_pb2.py",
43+
"google/cloud/bigquery_datatransfer_v1/proto/datatransfer_pb2_grpc.py",
44+
],
45+
"from google.cloud.bigquery.datatransfer_v1.proto",
46+
"from google.cloud.bigquery_datatransfer_v1.proto",
4347
)
4448

4549
s.replace(
46-
'google/cloud/bigquery_datatransfer_v1/gapic/'
47-
'data_transfer_service_client.py',
48-
'google-cloud-bigquerydatatransfer',
49-
'google-cloud-bigquery-datatransfer')
50+
"google/cloud/bigquery_datatransfer_v1/gapic/" "data_transfer_service_client.py",
51+
"google-cloud-bigquerydatatransfer",
52+
"google-cloud-bigquery-datatransfer",
53+
)
5054

5155
s.replace(
52-
'google/cloud/bigquery_datatransfer_v1/gapic/'
53-
'data_transfer_service_client.py',
54-
'import google.api_core.gapic_v1.method\n',
55-
'\g<0>import google.api_core.path_template\n'
56+
"google/cloud/bigquery_datatransfer_v1/gapic/" "data_transfer_service_client.py",
57+
"import google.api_core.gapic_v1.method\n",
58+
"\g<0>import google.api_core.path_template\n",
5659
)
60+
61+
# ----------------------------------------------------------------------------
62+
# Add templated files
63+
# ----------------------------------------------------------------------------
64+
templated_files = common.py_library(unit_cov_level=80, cov_level=80)
65+
s.move(templated_files)

0 commit comments

Comments
 (0)