Skip to content

Commit

Permalink
Normalize 'lint' / 'blacken' support under nox. (#8831)
Browse files Browse the repository at this point in the history
Pin version of black.
  • Loading branch information
tseaver committed Jul 31, 2019
1 parent a699d86 commit f68fa43
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 113 deletions.
2 changes: 1 addition & 1 deletion storage/google/cloud/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def list_blobs(
versions=versions,
projection=projection,
fields=fields,
client=self
client=self,
)

def list_buckets(
Expand Down
136 changes: 67 additions & 69 deletions storage/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,45 @@
import nox


LOCAL_DEPS = (
os.path.join('..', 'api_core'),
os.path.join('..', 'core'),
)
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))
BLACK_VERSION = "black==19.3b0"
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]

if os.path.exists("samples"):
BLACK_PATHS.append("samples")


@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_VERSION, *LOCAL_DEPS)
session.run("black", "--check", *BLACK_PATHS)
session.run("flake8", "google", "tests")


@nox.session(python="3.6")
def blacken(session):
"""Run black.
Format code to uniform standard.
This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
That run uses an image that doesn't have 3.6 installed. Before updating this
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
"""
session.install(BLACK_VERSION)
session.run("black", *BLACK_PATHS)


@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")


@nox.session
Expand All @@ -36,105 +71,68 @@ def default(session):
run the tests.
"""
# Install all test dependencies, then install local packages in-place.
session.install('mock', 'pytest', 'pytest-cov')
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',
'--cov=google.cloud.storage',
'--cov=tests.unit',
'--cov-append',
'--cov-config=.coveragerc',
'--cov-report=',
'--cov-fail-under=97',
'tests/unit',
"py.test",
"--quiet",
"--cov=google.cloud.storage",
"--cov=tests.unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=97",
"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=['2.7', '3.6'])
@nox.session(python=["2.7", "3.6"])
def system(session):
"""Run the system test suite."""

# Sanity check: Only run system tests if the environment variable is set.
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
session.skip('Credentials must be set via environment variable.')
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable.")

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

# Install all test dependencies, then install local packages in-place.
session.install('mock', 'pytest')
session.install("mock", "pytest")
for local_dep in LOCAL_DEPS:
session.install('-e', local_dep)
systest_deps = [
'../test_utils/',
'../pubsub',
'../kms',
]
session.install("-e", local_dep)
systest_deps = ["../test_utils/", "../pubsub", "../kms"]
for systest_dep in systest_deps:
session.install('-e', systest_dep)
session.install('-e', '.')
session.install("-e", systest_dep)
session.install("-e", ".")

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


@nox.session(python='3.6')
@nox.session(python="3.6")
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')


@nox.session(python='3.6')
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install('flake8', *LOCAL_DEPS)
session.install('.')
session.run('flake8', 'google', 'tests')

session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=100")
session.run("coverage", "erase")

@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="3.6")
def blacken(session):
"""Run black.
Format code to uniform standard.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
)

@nox.session(python="3.7")
def docs(session):
"""Build the docs for this library."""
Expand All @@ -154,4 +152,4 @@ def docs(session):
os.path.join("docs", "_build", "doctrees", ""),
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)
)
63 changes: 31 additions & 32 deletions storage/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,71 @@

# Package metadata.

name = 'google-cloud-storage'
description = 'Google Cloud Storage API client library'
version = '1.17.0'
name = "google-cloud-storage"
description = "Google Cloud Storage API client library"
version = "1.17.0"
# Should be one of:
# 'Development Status :: 3 - Alpha'
# 'Development Status :: 4 - Beta'
# 'Development Status :: 5 - Production/Stable'
release_status = 'Development Status :: 5 - Production/Stable'
release_status = "Development Status :: 5 - Production/Stable"
dependencies = [
'google-auth >= 1.2.0',
"google-auth >= 1.2.0",
"google-cloud-core >= 1.0.0, < 2.0dev",
'google-resumable-media >= 0.3.1',
"google-resumable-media >= 0.3.1",
]
extras = {
}
extras = {}


# Setup boilerplate below this line.

package_root = os.path.abspath(os.path.dirname(__file__))

readme_filename = os.path.join(package_root, 'README.rst')
with io.open(readme_filename, encoding='utf-8') as readme_file:
readme_filename = os.path.join(package_root, "README.rst")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

# Only include packages under the 'google' namespace. Do not include tests,
# benchmarks, etc.
packages = [
package for package in setuptools.find_packages()
if package.startswith('google')]
package for package in setuptools.find_packages() if package.startswith("google")
]

# Determine which namespaces are needed.
namespaces = ['google']
if 'google.cloud' in packages:
namespaces.append('google.cloud')
namespaces = ["google"]
if "google.cloud" in packages:
namespaces.append("google.cloud")


setuptools.setup(
name=name,
version=version,
description=description,
long_description=readme,
author='Google LLC',
author_email='googleapis-packages@google.com',
license='Apache 2.0',
url='https://github.com/GoogleCloudPlatform/google-cloud-python',
author="Google LLC",
author_email="googleapis-packages@google.com",
license="Apache 2.0",
url="https://github.com/GoogleCloudPlatform/google-cloud-python",
classifiers=[
release_status,
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Operating System :: OS Independent',
'Topic :: Internet',
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Operating System :: OS Independent",
"Topic :: Internet",
],
platforms='Posix; MacOS X; Windows',
platforms="Posix; MacOS X; Windows",
packages=packages,
namespace_packages=namespaces,
install_requires=dependencies,
extras_require=extras,
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
include_package_data=True,
zip_safe=False,
)
4 changes: 1 addition & 3 deletions storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,7 @@ def test_public_url_w_tilde_in_name(self):
BLOB_NAME = "foo~bar"
bucket = _Bucket()
blob = self._make_one(BLOB_NAME, bucket=bucket)
self.assertEqual(
blob.public_url, "https://storage.googleapis.com/name/foo~bar"
)
self.assertEqual(blob.public_url, "https://storage.googleapis.com/name/foo~bar")

def test_public_url_with_non_ascii(self):
blob_name = u"winter \N{snowman}"
Expand Down
16 changes: 8 additions & 8 deletions storage/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,16 @@ def test_download_blob_to_file_with_invalid_uri(self):

def test_list_blobs(self):
from google.cloud.storage.bucket import Bucket

BUCKET_NAME = "bucket-name"

credentials = _make_credentials()
client = self._make_one(project="PROJECT", credentials=credentials)
connection = _make_connection({"items": []})

with mock.patch(
'google.cloud.storage.client.Client._connection',
new_callable=mock.PropertyMock
"google.cloud.storage.client.Client._connection",
new_callable=mock.PropertyMock,
) as client_mock:
client_mock.return_value = connection

Expand All @@ -671,11 +672,12 @@ def test_list_blobs(self):
connection.api_request.assert_called_once_with(
method="GET",
path="/b/%s/o" % BUCKET_NAME,
query_params={"projection": "noAcl"}
query_params={"projection": "noAcl"},
)

def test_list_blobs_w_all_arguments_and_user_project(self):
from google.cloud.storage.bucket import Bucket

BUCKET_NAME = "name"
USER_PROJECT = "user-project-123"
MAX_RESULTS = 10
Expand All @@ -701,8 +703,8 @@ def test_list_blobs_w_all_arguments_and_user_project(self):
connection = _make_connection({"items": []})

with mock.patch(
'google.cloud.storage.client.Client._connection',
new_callable=mock.PropertyMock
"google.cloud.storage.client.Client._connection",
new_callable=mock.PropertyMock,
) as client_mock:
client_mock.return_value = connection

Expand All @@ -721,9 +723,7 @@ def test_list_blobs_w_all_arguments_and_user_project(self):

self.assertEqual(blobs, [])
connection.api_request.assert_called_once_with(
method="GET",
path="/b/%s/o" % BUCKET_NAME,
query_params=EXPECTED
method="GET", path="/b/%s/o" % BUCKET_NAME, query_params=EXPECTED
)

def test_list_buckets_wo_project(self):
Expand Down

0 comments on commit f68fa43

Please sign in to comment.