diff --git a/storage/google/cloud/storage/client.py b/storage/google/cloud/storage/client.py index a3aa5d628fa9..511be69bc45f 100644 --- a/storage/google/cloud/storage/client.py +++ b/storage/google/cloud/storage/client.py @@ -475,7 +475,7 @@ def list_blobs( versions=versions, projection=projection, fields=fields, - client=self + client=self, ) def list_buckets( diff --git a/storage/noxfile.py b/storage/noxfile.py index e66f04dac0ec..a391c6732b70 100644 --- a/storage/noxfile.py +++ b/storage/noxfile.py @@ -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 @@ -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.""" @@ -154,4 +152,4 @@ def docs(session): os.path.join("docs", "_build", "doctrees", ""), os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), - ) \ No newline at end of file + ) diff --git a/storage/setup.py b/storage/setup.py index cd0084752bb9..6f1e8bc396a8 100644 --- a/storage/setup.py +++ b/storage/setup.py @@ -20,41 +20,40 @@ # 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( @@ -62,30 +61,30 @@ 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, ) diff --git a/storage/tests/unit/test_blob.py b/storage/tests/unit/test_blob.py index b264ddcb8acf..b52a3753834a 100644 --- a/storage/tests/unit/test_blob.py +++ b/storage/tests/unit/test_blob.py @@ -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}" diff --git a/storage/tests/unit/test_client.py b/storage/tests/unit/test_client.py index 89ed8570dbfa..b5597977bb17 100644 --- a/storage/tests/unit/test_client.py +++ b/storage/tests/unit/test_client.py @@ -651,6 +651,7 @@ 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() @@ -658,8 +659,8 @@ def test_list_blobs(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 @@ -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 @@ -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 @@ -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):