Skip to content

Commit a5f647b

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

5 files changed

Lines changed: 162 additions & 137 deletions

File tree

.coveragerc

Lines 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

.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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include README.rst LICENSE
2-
recursive-include google *.json *.proto *.config
2+
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: 94 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Copyright 2016 Google LLC
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,102 +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-
os.path.join('..', 'core'),
25-
)
23+
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))
2624

25+
@nox.session(python="3.7")
26+
def blacken(session):
27+
"""Run black.
2728
28-
def default(session):
29-
"""Default unit test session."""
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+
)
3040

31-
# Install all test dependencies, then install local packages in-place.
32-
session.install('mock', 'pytest', 'pytest-cov')
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")
67+
68+
69+
def default(session):
70+
# Install all test dependencies, then install this package in-place.
71+
session.install("mock", "pytest", "pytest-cov")
3372
for local_dep in LOCAL_DEPS:
34-
session.install('-e', local_dep)
35-
session.install('-e', '.')
73+
session.install("-e", local_dep)
74+
session.install("-e", ".")
3675

3776
# Run py.test against the unit tests.
3877
session.run(
39-
'py.test',
40-
'--quiet',
41-
'--cov=google.cloud.spanner',
42-
'--cov=google.cloud.spanner_v1',
43-
'--cov=tests.unit',
44-
'--cov-append',
45-
'--cov-config=.coveragerc',
46-
'--cov-report=',
47-
'--cov-fail-under=97',
48-
'tests/unit',
49-
*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=97",
86+
os.path.join("tests", "unit"),
87+
*session.posargs,
5088
)
5189

5290

53-
@nox.session(python=['2.7', '3.4', '3.5', '3.6', '3.7'])
91+
@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
5492
def unit(session):
5593
"""Run the unit test suite."""
5694
default(session)
5795

5896

59-
def system_common(session):
60-
# Use pre-release gRPC for system tests.
61-
session.install('--pre', 'grpcio')
62-
63-
# Install all test dependencies, then install local packages in-place.
64-
session.install('mock', 'pytest')
65-
for local_dep in LOCAL_DEPS:
66-
session.install('-e', local_dep)
67-
session.install('-e', '../test_utils/')
68-
session.install('-e', '.')
69-
70-
# Run py.test against the system tests.
71-
session.run('py.test', '--quiet', 'tests/system', *session.posargs)
72-
73-
74-
@nox.session(python=['2.7', '3.6'])
97+
@nox.session(python=["2.7", "3.7"])
7598
def system(session):
7699
"""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")
77111

78-
# Sanity check: Only run system tests if the environment variable is set.
79-
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
80-
session.skip('Credentials must be set via environment variable.')
81-
82-
system_common(session)
83-
84-
85-
@nox.session(python='3.6')
86-
def lint(session):
87-
"""Run linters.
88-
89-
Returns a failure if the linters find linting errors or sufficiently
90-
serious code quality issues.
91-
"""
92-
session.install('flake8', *LOCAL_DEPS)
93-
session.install('.')
94-
session.run('flake8', 'google', 'tests')
112+
# Use pre-release gRPC for system tests.
113+
session.install("--pre", "grpcio")
95114

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", ".")
96122

97-
@nox.session(python='3.6')
98-
def lint_setup_py(session):
99-
"""Verify that setup.py is valid (including RST check)."""
100-
session.install('docutils', 'Pygments')
101-
session.run(
102-
'python', 'setup.py', 'check', '--restructuredtext', '--strict')
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)
103128

104129

105-
@nox.session(python='3.6')
130+
@nox.session(python="3.7")
106131
def cover(session):
107132
"""Run the final coverage report.
108133
109134
This outputs the coverage report aggregating coverage from the unit
110135
test runs (not system test runs), and then erases coverage data.
111136
"""
112-
session.install('coverage', 'pytest-cov')
113-
session.run('coverage', 'report', '--show-missing', '--fail-under=100')
114-
session.run('coverage', 'erase')
137+
session.install("coverage", "pytest-cov")
138+
session.run("coverage", "report", "--show-missing", "--fail-under=100")
139+
140+
session.run("coverage", "erase")

0 commit comments

Comments
 (0)