Skip to content

Commit

Permalink
Add templates for flake8, coveragerc, noxfile, and black. (#6642)
Browse files Browse the repository at this point in the history
  • Loading branch information
crwilcox authored Nov 28, 2018
1 parent b89814c commit 4e4ecf8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 62 deletions.
18 changes: 18 additions & 0 deletions packages/google-cloud-asset/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[run]
branch = True

[report]
fail_under = 100
show_missing = True
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
# Ignore debug-only repr
def __repr__
# Ignore abstract methods
raise NotImplementedError
omit =
*/gapic/*.py
*/proto/*.py
*/google-cloud-python/core/*.py
*/site-packages/*.py
1 change: 1 addition & 0 deletions packages/google-cloud-asset/.flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503
exclude =
# Exclude generated code.
**/proto/**
Expand Down
105 changes: 55 additions & 50 deletions packages/google-cloud-asset/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,50 @@
import nox


LOCAL_DEPS = (os.path.join("..", "api_core"),)
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))

@nox.session(python="3.7")
def blacken(session):
"""Run black.
Format code to uniform standard.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)


@nox.session(python="3.7")
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", "black", *LOCAL_DEPS)
session.run(
"black",
"--check",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)
session.run("flake8", "google", "tests")


@nox.session(python="3.7")
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
session.install("docutils", "pygments")
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")


def default(session):
Expand All @@ -39,7 +82,7 @@ def default(session):
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=86",
"--cov-fail-under=79",
os.path.join("tests", "unit"),
*session.posargs,
)
Expand All @@ -55,11 +98,15 @@ def unit(session):
def system(session):
"""Run the system test suite."""
system_test_path = os.path.join("tests", "system.py")
system_test_folder_path = os.path.join("tests", "system")
# Sanity check: Only run tests if the environment variable is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable")

system_test_exists = os.path.exists(system_test_path)
system_test_folder_exists = os.path.exists(system_test_folder_path)
# Sanity check: only run tests if found.
if not os.path.exists(system_test_path):
if not system_test_exists and not system_test_folder_exists:
session.skip("System tests were not found")

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

# Run py.test against the system tests.
session.run("py.test", "--quiet", system_test_path, *session.posargs)


@nox.session(python="3.7")
def blacken(session):
"""Run black.
Format code to uniform standard.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)


@nox.session(python="3.7")
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", "black", *LOCAL_DEPS)
session.install(".")
session.run(
"black",
"--check",
"google",
"tests",
"docs",
"--exclude",
".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py",
)
session.run("flake8", "google", "tests")


@nox.session(python="3.7")
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
session.install("docutils", "pygments")
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
if system_test_exists:
session.run("py.test", "--quiet", system_test_path, *session.posargs)
if system_test_folder_exists:
session.run("py.test", "--quiet", system_test_folder_path, *session.posargs)


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

session.run("coverage", "erase")
23 changes: 11 additions & 12 deletions packages/google-cloud-asset/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
from synthtool import gcp

gapic = gcp.GAPICGenerator()

common = gcp.CommonTemplates()
versions = ["v1beta1"]

excludes = [
'setup.py',
'nox*.py',
'README.rst',
'docs/conf.py',
'docs/index.rst',
]
excludes = ["setup.py", "nox*.py", "README.rst", "docs/conf.py", "docs/index.rst"]

# ----------------------------------------------------------------------------
# Generate asset GAPIC layer
# ----------------------------------------------------------------------------
for version in versions:
library = gapic.py_library(
"asset",
Expand All @@ -39,10 +36,6 @@

s.move(library, excludes=excludes)

templated_files = gcp.CommonTemplates().py_library(
unit_cov_level=86, cov_level=85)
s.move(templated_files)

s.replace(
"google/cloud/asset_v1beta1/proto/assets_pb2.py",
"from google.iam.v1 import policy_pb2 as",
Expand Down Expand Up @@ -85,3 +78,9 @@
_BORKED_ASSET_DOCSTRING,
_FIXED_ASSET_DOCSTRING,
)

# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
templated_files = gcp.CommonTemplates().py_library(unit_cov_level=79, cov_level=80)
s.move(templated_files)

0 comments on commit 4e4ecf8

Please sign in to comment.