Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a2b64d

Browse filesBrowse files
authored
Add templates for flake8, coveragerc, noxfile, and black. (googleapis#6642)
1 parent 4c8184a commit 8a2b64d
Copy full SHA for 8a2b64d

147 files changed

+4,088-2,132Lines changed: 4088 additions & 2132 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎asset/.coveragerc‎

Copy file name to clipboard
+18Lines 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
Collapse file

‎asset/.flake8‎

Copy file name to clipboardExpand all lines: asset/.flake8
+1Lines 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/**
Collapse file

‎asset/noxfile.py‎

Copy file name to clipboardExpand all lines: asset/noxfile.py
+55-50Lines 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")
Collapse file

‎asset/synth.py‎

Copy file name to clipboardExpand all lines: asset/synth.py
+11-12Lines 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)
Collapse file

‎automl/.coveragerc‎

Copy file name to clipboardExpand all lines: automl/.coveragerc
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ exclude_lines =
99
pragma: NO COVER
1010
# Ignore debug-only repr
1111
def __repr__
12+
# Ignore abstract methods
13+
raise NotImplementedError
1214
omit =
1315
*/gapic/*.py
1416
*/proto/*.py
17+
*/google-cloud-python/core/*.py
18+
*/site-packages/*.py
Collapse file

‎automl/.flake8‎

Copy file name to clipboardExpand all lines: automl/.flake8
+1Lines 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/**
Collapse file

‎automl/noxfile.py‎

Copy file name to clipboard
+106-14Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,31 +20,121 @@
1820
import nox
1921

2022

21-
LOCAL_DEPS = (
22-
os.path.join('..', 'api_core'),
23-
)
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):
2770
# Install all test dependencies, then install this package in-place.
28-
session.install('pytest', 'mock')
71+
session.install("mock", "pytest", "pytest-cov")
2972
for local_dep in LOCAL_DEPS:
30-
session.install('-e', local_dep)
31-
session.install('-e', '.')
73+
session.install("-e", local_dep)
74+
session.install("-e", ".")
3275

3376
# Run py.test against the unit tests.
34-
session.run('py.test', '--quiet', os.path.join('tests', 'unit'))
77+
session.run(
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=82",
86+
os.path.join("tests", "unit"),
87+
*session.posargs,
88+
)
3589

3690

37-
@nox.session(python=['2.7', '3.5', '3.6', '3.7'])
91+
@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
3892
def unit(session):
3993
"""Run the unit test suite."""
4094
default(session)
4195

4296

43-
@nox.session(python='3.6')
44-
def lint_setup_py(session):
45-
"""Verify that setup.py is valid (including RST check)."""
46-
session.install('docutils', 'pygments')
47-
session.run('python', 'setup.py', 'check', '--restructuredtext',
48-
'--strict')
97+
@nox.session(python=["2.7", "3.7"])
98+
def system(session):
99+
"""Run the system test suite."""
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")
111+
112+
# Use pre-release gRPC for system tests.
113+
session.install("--pre", "grpcio")
114+
115+
# Install all test dependencies, then install this package into the
116+
# virtualenv's dist-packages.
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", ".")
122+
123+
# Run py.test against the system tests.
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=83")
139+
140+
session.run("coverage", "erase")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.