Skip to content

Commit

Permalink
Blacken noxfile and setup file in nox session (#7619)
Browse files Browse the repository at this point in the history
  • Loading branch information
tswast authored and tseaver committed Mar 30, 2019
1 parent 86c6662 commit 321b83e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 124 deletions.
4 changes: 1 addition & 3 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,7 @@ def _get_progress_bar(self, progress_bar_type):
desc=description, total=self.total_rows, unit=unit
)
elif progress_bar_type == "tqdm_gui":
return tqdm.tqdm_gui(
desc=description, total=self.total_rows, unit=unit
)
return tqdm.tqdm_gui(desc=description, total=self.total_rows, unit=unit)
except (KeyError, TypeError):
# Protect ourselves from any tqdm errors. In case of
# unexpected tqdm behavior, just fall back to showing
Expand Down
161 changes: 77 additions & 84 deletions bigquery/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@


LOCAL_DEPS = (
os.path.join('..', 'api_core[grpc]'),
os.path.join('..', 'core'),
os.path.join("..", "api_core[grpc]"),
os.path.join("..", "core"),
# TODO: Move bigquery_storage back to dev_install once dtypes feature is
# released. Issue #7049
os.path.join('..', 'bigquery_storage[pandas,fastavro]'),
os.path.join("..", "bigquery_storage[pandas,fastavro]"),
)

BLACK_PATHS = ("google", "tests", "docs", "noxfile.py", "setup.py")


def default(session):
"""Default unit test session.
Expand All @@ -38,135 +40,129 @@ 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", local_dep)

# Pyarrow does not support Python 3.7
if session.python == '3.7':
dev_install = '.[pandas, tqdm]'
if session.python == "3.7":
dev_install = ".[pandas, tqdm]"
else:
dev_install = '.[pandas, pyarrow, tqdm]'
session.install('-e', dev_install)
dev_install = ".[pandas, pyarrow, tqdm]"
session.install("-e", dev_install)

# IPython does not support Python 2 after version 5.x
if session.python == '2.7':
session.install('ipython==5.5')
if session.python == "2.7":
session.install("ipython==5.5")
else:
session.install('ipython')
session.install("ipython")

# Run py.test against the unit tests.
session.run(
'py.test',
'--quiet',
'--cov=google.cloud.bigquery',
'--cov=tests.unit',
'--cov-append',
'--cov-config=.coveragerc',
'--cov-report=',
'--cov-fail-under=97',
os.path.join('tests', 'unit'),
"py.test",
"--quiet",
"--cov=google.cloud.bigquery",
"--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=['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)
session.install('-e', os.path.join('..', 'storage'))
session.install('-e', os.path.join('..', 'test_utils'))
session.install('-e', '.[pandas]')
session.install("-e", local_dep)
session.install("-e", os.path.join("..", "storage"))
session.install("-e", os.path.join("..", "test_utils"))
session.install("-e", ".[pandas]")

# IPython does not support Python 2 after version 5.x
if session.python == '2.7':
session.install('ipython==5.5')
if session.python == "2.7":
session.install("ipython==5.5")
else:
session.install('ipython')
session.install("ipython")

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


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

# Sanity check: Only run snippets 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.")

# 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)
session.install('-e', os.path.join('..', 'storage'))
session.install('-e', os.path.join('..', 'test_utils'))
session.install('-e', '.[pandas, pyarrow, fastparquet]')
session.install("-e", local_dep)
session.install("-e", os.path.join("..", "storage"))
session.install("-e", os.path.join("..", "test_utils"))
session.install("-e", ".[pandas, pyarrow, fastparquet]")

# Run py.test against the snippets tests.
session.run(
'py.test', os.path.join('docs', 'snippets.py'), *session.posargs)
session.run("py.test", os.path.join("docs", "snippets.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')
session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=100")
session.run("coverage", "erase")


@nox.session(python='3.6')
@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', os.path.join('google', 'cloud', 'bigquery'))
session.run('flake8', 'tests')
session.run(
'flake8', os.path.join('docs', 'snippets.py'))
session.install("black", "flake8", *LOCAL_DEPS)
session.install(".")
session.run("flake8", os.path.join("google", "cloud", "bigquery"))
session.run("flake8", "tests")
session.run("flake8", os.path.join("docs", "snippets.py"))
session.run("black", "--check", *BLACK_PATHS)


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

session.install("docutils", "Pygments")
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")


@nox.session(python="3.6")
Expand All @@ -175,32 +171,29 @@ def blacken(session):
Format code to uniform standard.
"""
session.install("black")
session.run(
"black",
"google",
"tests",
"docs",
)
session.run("black", *BLACK_PATHS)


@nox.session(python='3.6')
@nox.session(python="3.6")
def docs(session):
"""Build the docs."""

session.install('ipython', 'recommonmark', 'sphinx', 'sphinx_rtd_theme')
session.install("ipython", "recommonmark", "sphinx", "sphinx_rtd_theme")
for local_dep in LOCAL_DEPS:
session.install('-e', local_dep)
session.install('-e', os.path.join('..', 'storage'))
session.install('-e', '.[pandas, pyarrow]')
session.install("-e", local_dep)
session.install("-e", os.path.join("..", "storage"))
session.install("-e", ".[pandas, pyarrow]")

shutil.rmtree(os.path.join('docs', '_build'), ignore_errors=True)
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
'sphinx-build',
'-W', # warnings as errors
'-T', # show full traceback on exception
'-N', # no colors
'-b', 'html',
'-d', os.path.join('docs', '_build', 'doctrees', ''),
os.path.join('docs', ''),
os.path.join('docs', '_build', 'html', ''),
"sphinx-build",
"-W", # warnings as errors
"-T", # show full traceback on exception
"-N", # no colors
"-b",
"html",
"-d",
os.path.join("docs", "_build", "doctrees", ""),
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)
73 changes: 36 additions & 37 deletions bigquery/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,79 +20,78 @@

# Package metadata.

name = 'google-cloud-bigquery'
description = 'Google BigQuery API client library'
version = '1.10.0'
name = "google-cloud-bigquery"
description = "Google BigQuery API client library"
version = "1.10.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-api-core >= 1.6.0, < 2.0.0dev',
'google-cloud-core >= 0.29.0, < 0.30dev',
'google-resumable-media >= 0.3.1',
"google-api-core >= 1.6.0, < 2.0.0dev",
"google-cloud-core >= 0.29.0, < 0.30dev",
"google-resumable-media >= 0.3.1",
]
extras = {
'bqstorage': 'google-cloud-bigquery-storage >= 0.2.0dev1, <2.0.0dev',
'pandas': 'pandas>=0.17.1',
"bqstorage": "google-cloud-bigquery-storage >= 0.2.0dev1, <2.0.0dev",
"pandas": "pandas>=0.17.1",
# Exclude PyArrow dependency from Windows Python 2.7.
'pyarrow: platform_system != "Windows" or python_version >= "3.4"':
'pyarrow>=0.4.1',
'tqdm': 'tqdm >= 4.0.0, <5.0.0dev',
'fastparquet': ['fastparquet', 'python-snappy'],
'pyarrow: platform_system != "Windows" or python_version >= "3.4"': "pyarrow>=0.4.1",
"tqdm": "tqdm >= 4.0.0, <5.0.0dev",
"fastparquet": ["fastparquet", "python-snappy"],
}


# 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,
)

0 comments on commit 321b83e

Please sign in to comment.