Skip to content

Commit 2e5aaa7

Browse files
authored
Add templates for flake8, coveragerc, noxfile, and black. (#6642)
1 parent d3da661 commit 2e5aaa7

File tree

5 files changed

+79
-42
lines changed

5 files changed

+79
-42
lines changed

.coveragerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ exclude_lines =
99
pragma: NO COVER
1010
# Ignore debug-only repr
1111
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

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[flake8]
2+
ignore = E203, E266, E501, W503
23
exclude =
34
# Exclude generated code.
45
**/proto/**

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include README.rst LICENSE
22
recursive-include google *.json *.proto
33
recursive-include tests *
4-
global-exclude *.pyc __pycache__
4+
global-exclude *.py[co]
5+
global-exclude __pycache__

noxfile.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,54 @@
3333
'webob',
3434
)
3535

36+
@nox.session(python="3.7")
37+
def blacken(session):
38+
"""Run black.
39+
40+
Format code to uniform standard.
41+
"""
42+
session.install("black")
43+
session.run(
44+
"black",
45+
"google",
46+
"tests",
47+
"docs",
48+
"--exclude",
49+
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
50+
)
51+
52+
53+
@nox.session(python="3.7")
54+
def lint(session):
55+
"""Run linters.
56+
57+
Returns a failure if the linters find linting errors or sufficiently
58+
serious code quality issues.
59+
"""
60+
session.install("flake8", "black", *LOCAL_DEPS)
61+
session.run(
62+
"black",
63+
"--check",
64+
"google",
65+
"tests",
66+
"docs",
67+
"--exclude",
68+
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
69+
)
70+
session.run("flake8", "google", "tests")
71+
72+
73+
@nox.session(python="3.7")
74+
def lint_setup_py(session):
75+
"""Verify that setup.py is valid (including RST check)."""
76+
session.install("docutils", "pygments")
77+
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
78+
3679

3780
def default(session, django_dep=('django',)):
3881
"""Default unit test session.
3982
"""
40-
83+
4184
# Install all test dependencies, then install this package in-place.
4285
deps = UNIT_TEST_DEPS
4386
deps += django_dep
@@ -114,34 +157,14 @@ def system(session):
114157
*session.posargs)
115158

116159

117-
@nox.session(python='3.6')
118-
def lint(session):
119-
"""Run linters.
120-
121-
Returns a failure if the linters find linting errors or sufficiently
122-
serious code quality issues.
123-
"""
124-
session.install('flake8', *LOCAL_DEPS)
125-
session.install('.')
126-
session.run('flake8', 'google', 'tests')
127-
128-
129-
@nox.session(python='3.6')
130-
def lint_setup_py(session):
131-
"""Verify that setup.py is valid (including RST check)."""
132-
133-
session.install('docutils', 'Pygments')
134-
session.run(
135-
'python', 'setup.py', 'check', '--restructuredtext', '--strict')
136-
137-
138-
@nox.session(python='3.6')
160+
@nox.session(python="3.7")
139161
def cover(session):
140162
"""Run the final coverage report.
141163
142164
This outputs the coverage report aggregating coverage from the unit
143165
test runs (not system test runs), and then erases coverage data.
144166
"""
145-
session.install('coverage', 'pytest-cov')
146-
session.run('coverage', 'report', '--show-missing', '--fail-under=100')
147-
session.run('coverage', 'erase')
167+
session.install("coverage", "pytest-cov")
168+
session.run("coverage", "report", "--show-missing", "--fail-under=100")
169+
170+
session.run("coverage", "erase")

synth.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,29 @@
1717
from synthtool import gcp
1818

1919
gapic = gcp.GAPICGenerator()
20+
common = gcp.CommonTemplates()
2021

21-
22-
#----------------------------------------------------------------------------
23-
# Generate logging client
24-
#----------------------------------------------------------------------------
22+
# ----------------------------------------------------------------------------
23+
# Generate logging GAPIC layer
24+
# ----------------------------------------------------------------------------
2525
library = gapic.py_library(
26-
'logging',
27-
'v2',
28-
config_path='/google/logging/artman_logging.yaml',
29-
artman_output_name='logging-v2')
26+
"logging",
27+
"v2",
28+
config_path="/google/logging/artman_logging.yaml",
29+
artman_output_name="logging-v2",
30+
)
3031

31-
s.move(library / 'google/cloud/logging_v2/proto')
32-
s.move(library / 'google/cloud/logging_v2/gapic')
33-
s.move(library / 'tests/unit/gapic/v2')
32+
s.move(library / "google/cloud/logging_v2/proto")
33+
s.move(library / "google/cloud/logging_v2/gapic")
34+
s.move(library / "tests/unit/gapic/v2")
3435

3536
# Issues exist where python files should define the source encoding
3637
# https://github.com/googleapis/gapic-generator/issues/2097
37-
s.replace(
38-
'google/**/proto/*_pb2.py',
39-
r"(^.*$\n)*",
40-
r"# -*- coding: utf-8 -*-\n\g<0>")
38+
s.replace("google/**/proto/*_pb2.py", r"(^.*$\n)*", r"# -*- coding: utf-8 -*-\n\g<0>")
39+
40+
# ----------------------------------------------------------------------------
41+
# Add templated files
42+
# ----------------------------------------------------------------------------
43+
templated_files = common.py_library(unit_cov_level=95, cov_level=100)
44+
# Don't move noxfile. logging has special testing setups for django, etc
45+
s.move(templated_files, exclude="noxfile.py")

0 commit comments

Comments
 (0)