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 0e0f2ff commit ac7b4dd
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 49 deletions.
18 changes: 18 additions & 0 deletions packages/google-cloud-os-login/.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
13 changes: 13 additions & 0 deletions packages/google-cloud-os-login/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[flake8]
ignore = E203, E266, E501, W503
exclude =
# Exclude generated code.
**/proto/**
**/gapic/**
*_pb2.py

# Standard linting exemptions.
__pycache__,
.git,
*.pyc,
conf.py
4 changes: 3 additions & 1 deletion packages/google-cloud-os-login/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)

__path__ = pkgutil.extend_path(__path__, __name__)
4 changes: 3 additions & 1 deletion packages/google-cloud-os-login/google/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)

__path__ = pkgutil.extend_path(__path__, __name__)
5 changes: 1 addition & 4 deletions packages/google-cloud-os-login/google/cloud/oslogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@
from google.cloud.oslogin_v1 import OsLoginServiceClient
from google.cloud.oslogin_v1 import types

__all__ = (
'types',
'OsLoginServiceClient',
)
__all__ = ("types", "OsLoginServiceClient")
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ class OsLoginServiceClient(os_login_service_client.OsLoginServiceClient):
__doc__ = os_login_service_client.OsLoginServiceClient.__doc__


__all__ = (
'types',
'OsLoginServiceClient',
)
__all__ = ("types", "OsLoginServiceClient")
16 changes: 4 additions & 12 deletions packages/google-cloud-os-login/google/cloud/oslogin_v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,9 @@
from google.protobuf import empty_pb2
from google.protobuf import field_mask_pb2

_shared_modules = [
http_pb2,
common_pb2,
descriptor_pb2,
empty_pb2,
field_mask_pb2,
]

_local_modules = [
oslogin_pb2,
]
_shared_modules = [http_pb2, common_pb2, descriptor_pb2, empty_pb2, field_mask_pb2]

_local_modules = [oslogin_pb2]

names = []

Expand All @@ -46,7 +38,7 @@
names.append(name)
for module in _local_modules:
for name, message in get_messages(module).items():
message.__module__ = 'google.cloud.oslogin_v1.types'
message.__module__ = "google.cloud.oslogin_v1.types"
setattr(sys.modules[__name__], name, message)
names.append(name)

Expand Down
120 changes: 106 additions & 14 deletions packages/google-cloud-os-login/noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,31 +20,121 @@
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):
# Install all test dependencies, then install this package in-place.
session.install('pytest', 'mock')
session.install("mock", "pytest", "pytest-cov")
for local_dep in LOCAL_DEPS:
session.install('-e', local_dep)
session.install('-e', '.')
session.install("-e", local_dep)
session.install("-e", ".")

# Run py.test against the unit tests.
session.run('py.test', '--quiet', os.path.join('tests', 'unit'))
session.run(
"py.test",
"--quiet",
"--cov=google.cloud",
"--cov=tests.unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=97",
os.path.join("tests", "unit"),
*session.posargs,
)


@nox.session(python=['2.7', '3.5', '3.6', '3.7'])
@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
def unit(session):
"""Run the unit test suite."""
default(session)


@nox.session(python='3.6')
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')
@nox.session(python=["2.7", "3.7"])
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 system_test_exists and not system_test_folder_exists:
session.skip("System tests were not found")

# Use pre-release gRPC for system tests.
session.install("--pre", "grpcio")

# Install all test dependencies, then install this package into the
# virtualenv's dist-packages.
session.install("mock", "pytest")
for local_dep in LOCAL_DEPS:
session.install("-e", local_dep)
session.install("-e", "../test_utils/")
session.install("-e", ".")

# Run py.test against the system tests.
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")
def cover(session):
"""Run the final coverage report.
This outputs the coverage report aggregating coverage from the unit
test runs (not system test runs), and then erases coverage data.
"""
session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=100")

session.run("coverage", "erase")
33 changes: 20 additions & 13 deletions packages/google-cloud-os-login/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@
from synthtool import gcp

gapic = gcp.GAPICGenerator()
common = gcp.CommonTemplates()


#----------------------------------------------------------------------------
# Generate oslogin client
#----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Generate oslogin GAPIC layer
# ----------------------------------------------------------------------------
library = gapic.py_library(
'oslogin',
'v1',
config_path='/google/cloud/oslogin/artman_oslogin_v1.yaml',
artman_output_name='os-login-v1')
"oslogin",
"v1",
config_path="/google/cloud/oslogin/artman_oslogin_v1.yaml",
artman_output_name="os-login-v1",
)

s.move(library / 'google/cloud/oslogin_v1')
s.move(library / 'tests/unit/gapic/v1')
s.move(library / "google/cloud/oslogin_v1")
s.move(library / "tests/unit/gapic/v1")

# Fix up imports
s.replace(
'google/**/proto/*.py',
'from google.cloud.oslogin.common import common_pb2',
'from google.cloud.oslogin_v1.proto import common_pb2',
"google/**/proto/*.py",
"from google.cloud.oslogin.common import common_pb2",
"from google.cloud.oslogin_v1.proto import common_pb2",
)

# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
templated_files = common.py_library(unit_cov_level=97, cov_level=100)
s.move(templated_files)

0 comments on commit ac7b4dd

Please # to comment.