Skip to content

Commit 846edfb

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

File tree

5 files changed

+124
-93
lines changed

5 files changed

+124
-93
lines changed

packages/google-cloud-firestore/.coveragerc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
branch = True
33

44
[report]
5-
omit =
6-
*/firestore_v1beta1/proto/*_pb2.py
7-
*/firestore_v1beta1/proto/*_pb2_grpc.py
8-
*/firestore_v1beta1/gapic/*.py
95
fail_under = 100
106
show_missing = True
117
exclude_lines =
128
# Re-enable the standard pragma
139
pragma: NO COVER
1410
# Ignore debug-only repr
1511
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-firestore/.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/**
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__
Lines changed: 90 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Copyright 2017 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,109 +15,126 @@
1315
# limitations under the License.
1416

1517
from __future__ import absolute_import
16-
1718
import os
1819

1920
import nox
20-
import nox.command
2121

2222

23-
LOCAL_DEPS = (
24-
os.path.join('..', 'api_core'),
25-
os.path.join('..', 'core'),
26-
)
23+
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))
2724

25+
@nox.session(python="3.7")
26+
def blacken(session):
27+
"""Run black.
2828
29-
def default(session):
30-
"""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+
)
40+
41+
42+
@nox.session(python="3.7")
43+
def lint(session):
44+
"""Run linters.
3145
32-
This is intended to be run **without** an interpreter set, so
33-
that the current ``python`` (on the ``PATH``) or the version of
34-
Python corresponding to the ``nox`` binary the ``PATH`` can
35-
run the tests.
46+
Returns a failure if the linters find linting errors or sufficiently
47+
serious code quality issues.
3648
"""
37-
# Install all test dependencies, then install local packages in-place.
38-
session.install('mock', 'pytest', 'pytest-cov')
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")
3972
for local_dep in LOCAL_DEPS:
40-
session.install('-e', local_dep)
41-
session.install('-e', '.')
73+
session.install("-e", local_dep)
74+
session.install("-e", ".")
4275

4376
# Run py.test against the unit tests.
4477
session.run(
45-
'py.test',
46-
'--quiet',
47-
'--cov=google.cloud.firestore',
48-
'--cov=google.cloud.firestore_v1beta1',
49-
'--cov=tests.unit',
50-
'--cov-append',
51-
'--cov-config=.coveragerc',
52-
'--cov-report=',
53-
'--cov-fail-under=97',
54-
os.path.join('tests', 'unit'),
55-
*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,
5688
)
5789

5890

59-
@nox.session(python=['2.7', '3.5', '3.6', '3.7'])
91+
@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
6092
def unit(session):
6193
"""Run the unit test suite."""
62-
6394
default(session)
6495

6596

66-
@nox.session(python=['2.7', '3.6'])
97+
@nox.session(python=["2.7", "3.7"])
6798
def system(session):
6899
"""Run the system test suite."""
69-
# Sanity check: Only run system tests if the environment variable is set.
70-
if not os.environ.get('FIRESTORE_APPLICATION_CREDENTIALS'):
71-
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")
72111

73112
# Use pre-release gRPC for system tests.
74-
session.install('--pre', 'grpcio')
113+
session.install("--pre", "grpcio")
75114

76-
# Install all test dependencies, then install local packages in-place.
77-
session.install('mock', 'pytest')
115+
# Install all test dependencies, then install this package into the
116+
# virtualenv's dist-packages.
117+
session.install("mock", "pytest")
78118
for local_dep in LOCAL_DEPS:
79-
session.install('-e', local_dep)
80-
session.install('-e', os.path.join('..', 'test_utils'))
81-
session.install('-e', '.')
119+
session.install("-e", local_dep)
120+
session.install("-e", "../test_utils/")
121+
session.install("-e", ".")
82122

83123
# Run py.test against the system tests.
84-
session.run(
85-
'py.test',
86-
os.path.join('tests', 'system.py'),
87-
*session.posargs
88-
)
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)
89128

90129

91-
@nox.session(python='3.6')
92-
def lint(session):
93-
"""Run linters.
94-
95-
Returns a failure if the linters find linting errors or sufficiently
96-
serious code quality issues.
97-
"""
98-
session.install('flake8', *LOCAL_DEPS)
99-
session.install('.')
100-
session.run('flake8', 'google', 'tests')
101-
102-
103-
@nox.session(python='3.6')
104-
def lint_setup_py(session):
105-
"""Verify that setup.py is valid (including RST check)."""
106-
session.install('docutils', 'Pygments')
107-
session.run(
108-
'python', 'setup.py', 'check', '--restructuredtext', '--strict')
109-
110-
111-
@nox.session(python='3.6')
130+
@nox.session(python="3.7")
112131
def cover(session):
113132
"""Run the final coverage report.
114133
115134
This outputs the coverage report aggregating coverage from the unit
116135
test runs (not system test runs), and then erases coverage data.
117136
"""
118-
session.chdir(os.path.dirname(__file__))
119-
session.install('coverage', 'pytest-cov')
120-
session.run('coverage', 'report', '--show-missing', '--fail-under=100')
121-
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")

packages/google-cloud-firestore/synth.py

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

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

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

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

3536
s.replace(
36-
'tests/unit/gapic/v1beta1/test_firestore_client_v1beta1.py',
37-
'from google.cloud import firestore_v1beta1',
38-
'from google.cloud.firestore_v1beta1.gapic import firestore_client',
37+
"tests/unit/gapic/v1beta1/test_firestore_client_v1beta1.py",
38+
"from google.cloud import firestore_v1beta1",
39+
"from google.cloud.firestore_v1beta1.gapic import firestore_client",
3940
)
4041

4142
s.replace(
42-
'tests/unit/gapic/v1beta1/test_firestore_client_v1beta1.py',
43-
'client = firestore_v1beta1.FirestoreClient',
44-
'client = firestore_client.FirestoreClient',
43+
"tests/unit/gapic/v1beta1/test_firestore_client_v1beta1.py",
44+
"client = firestore_v1beta1.FirestoreClient",
45+
"client = firestore_client.FirestoreClient",
4546
)
47+
48+
# ----------------------------------------------------------------------------
49+
# Add templated files
50+
# ----------------------------------------------------------------------------
51+
templated_files = common.py_library(unit_cov_level=97, cov_level=100)
52+
s.move(templated_files)

0 commit comments

Comments
 (0)