Skip to content

Commit 4e4ecf8

Browse files
authored
Add templates for flake8, coveragerc, noxfile, and black. (#6642)
1 parent b89814c commit 4e4ecf8

File tree

4 files changed

+85
-62
lines changed

4 files changed

+85
-62
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

packages/google-cloud-asset/.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/**

packages/google-cloud-asset/noxfile.py

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,50 @@
2020
import nox
2121

2222

23-
LOCAL_DEPS = (os.path.join("..", "api_core"),)
23+
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))
24+
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+
)
40+
41+
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.
48+
"""
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")
2467

2568

2669
def default(session):
@@ -39,7 +82,7 @@ def default(session):
3982
"--cov-append",
4083
"--cov-config=.coveragerc",
4184
"--cov-report=",
42-
"--cov-fail-under=86",
85+
"--cov-fail-under=79",
4386
os.path.join("tests", "unit"),
4487
*session.posargs,
4588
)
@@ -55,11 +98,15 @@ def unit(session):
5598
def system(session):
5699
"""Run the system test suite."""
57100
system_test_path = os.path.join("tests", "system.py")
101+
system_test_folder_path = os.path.join("tests", "system")
58102
# Sanity check: Only run tests if the environment variable is set.
59103
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
60104
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)
61108
# Sanity check: only run tests if found.
62-
if not os.path.exists(system_test_path):
109+
if not system_test_exists and not system_test_folder_exists:
63110
session.skip("System tests were not found")
64111

65112
# Use pre-release gRPC for system tests.
@@ -74,52 +121,10 @@ def system(session):
74121
session.install("-e", ".")
75122

76123
# Run py.test against the system tests.
77-
session.run("py.test", "--quiet", system_test_path, *session.posargs)
78-
79-
80-
@nox.session(python="3.7")
81-
def blacken(session):
82-
"""Run black.
83-
84-
Format code to uniform standard.
85-
"""
86-
session.install("black")
87-
session.run(
88-
"black",
89-
"google",
90-
"tests",
91-
"docs",
92-
"--exclude",
93-
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
94-
)
95-
96-
97-
@nox.session(python="3.7")
98-
def lint(session):
99-
"""Run linters.
100-
101-
Returns a failure if the linters find linting errors or sufficiently
102-
serious code quality issues.
103-
"""
104-
session.install("flake8", "black", *LOCAL_DEPS)
105-
session.install(".")
106-
session.run(
107-
"black",
108-
"--check",
109-
"google",
110-
"tests",
111-
"docs",
112-
"--exclude",
113-
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
114-
)
115-
session.run("flake8", "google", "tests")
116-
117-
118-
@nox.session(python="3.7")
119-
def lint_setup_py(session):
120-
"""Verify that setup.py is valid (including RST check)."""
121-
session.install("docutils", "pygments")
122-
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
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)
123128

124129

125130
@nox.session(python="3.7")
@@ -130,6 +135,6 @@ def cover(session):
130135
test runs (not system test runs), and then erases coverage data.
131136
"""
132137
session.install("coverage", "pytest-cov")
133-
session.run("coverage", "report", "--show-missing", "--fail-under=85")
138+
session.run("coverage", "report", "--show-missing", "--fail-under=80")
134139

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

packages/google-cloud-asset/synth.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818
from synthtool import gcp
1919

2020
gapic = gcp.GAPICGenerator()
21-
21+
common = gcp.CommonTemplates()
2222
versions = ["v1beta1"]
2323

24-
excludes = [
25-
'setup.py',
26-
'nox*.py',
27-
'README.rst',
28-
'docs/conf.py',
29-
'docs/index.rst',
30-
]
24+
excludes = ["setup.py", "nox*.py", "README.rst", "docs/conf.py", "docs/index.rst"]
3125

26+
# ----------------------------------------------------------------------------
27+
# Generate asset GAPIC layer
28+
# ----------------------------------------------------------------------------
3229
for version in versions:
3330
library = gapic.py_library(
3431
"asset",
@@ -39,10 +36,6 @@
3936

4037
s.move(library, excludes=excludes)
4138

42-
templated_files = gcp.CommonTemplates().py_library(
43-
unit_cov_level=86, cov_level=85)
44-
s.move(templated_files)
45-
4639
s.replace(
4740
"google/cloud/asset_v1beta1/proto/assets_pb2.py",
4841
"from google.iam.v1 import policy_pb2 as",
@@ -85,3 +78,9 @@
8578
_BORKED_ASSET_DOCSTRING,
8679
_FIXED_ASSET_DOCSTRING,
8780
)
81+
82+
# ----------------------------------------------------------------------------
83+
# Add templated files
84+
# ----------------------------------------------------------------------------
85+
templated_files = gcp.CommonTemplates().py_library(unit_cov_level=79, cov_level=80)
86+
s.move(templated_files)

0 commit comments

Comments
 (0)