Skip to content

Commit 0dcf739

Browse files
partheanicain
andauthored
chore: upgrade black in noxfile.py to 22.3.0 (#1377)
* chore: upgrade black to 22.3.0 * update lint also * run blacken session * ci: use click>8.0 for blacken/lint sessions * chore: fix typo Co-authored-by: nicain <nicholascain@google.com> * rebase error Co-authored-by: nicain <nicholascain@google.com>
1 parent 65e3263 commit 0dcf739

17 files changed

Lines changed: 68 additions & 43 deletions

File tree

noxfile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ def generate_protos(session):
2020
session.run(
2121
"python", "-m", "grpc_tools.protoc", "-Isynthtool/protos", "--python_out=synthtool/protos", "synthtool/protos/metadata.proto", "synthtool/protos/preconfig.proto")
2222

23-
@nox.session(python=['3.6', '3.8'])
23+
@nox.session(python=['3.6', '3.9'])
2424
def blacken(session):
25-
session.install('black==19.10b0')
25+
session.install('black==22.3.0', 'click>8.0')
2626
session.run('black', 'synthtool', 'tests')
2727

2828

2929
@nox.session(python=['3.6', '3.8', '3.9'])
3030
def lint(session):
31-
session.install('mypy==0.790', 'flake8', 'black==19.10b0')
31+
session.install('mypy==0.790', 'flake8', 'black==22.3.0')
3232
session.run('pip', 'install', '-e', '.')
33+
session.run('pip', 'install', 'click>8.0')
3334
session.run('black', '--check', 'synthtool', 'tests')
3435
session.run('flake8', 'synthtool', 'tests')
3536
session.run('mypy', 'synthtool')

synthtool/gcp/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def detect_versions(
423423

424424

425425
def decamelize(value: str):
426-
""" parser to convert fooBar.js to Foo Bar. """
426+
"""Parser to convert fooBar.js to Foo Bar."""
427427
if not value:
428428
return ""
429429
str_decamelize = re.sub("^.", value[0].upper(), value) # apple -> Apple.

synthtool/gcp/samples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def all_samples(sample_globs: List[str]) -> List[Dict[str, str]]:
7878

7979

8080
def _decamelize(value: str):
81-
""" parser to convert fooBar.js to Foo Bar. """
81+
"""Parser to convert fooBar.js to Foo Bar."""
8282
if not value:
8383
return ""
8484
str_decamelize = re.sub("^.", value[0].upper(), value) # apple -> Apple.

synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/execute_changed_notebooks_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def str2bool(v):
8585
args = parser.parse_args()
8686

8787
notebooks = execute_changed_notebooks_helper.get_changed_notebooks(
88-
test_paths_file=args.test_paths_file, base_branch=args.base_branch,
88+
test_paths_file=args.test_paths_file,
89+
base_branch=args.base_branch,
8990
)
9091

9192
execute_changed_notebooks_helper.process_and_execute_notebooks(

synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/execute_changed_notebooks_helper.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class NotebookExecutionResult:
6464

6565

6666
def _process_notebook(
67-
notebook_path: str, variable_project_id: str, variable_region: str,
67+
notebook_path: str,
68+
variable_project_id: str,
69+
variable_region: str,
6870
):
6971
# Read notebook
7072
with open(notebook_path) as f:
@@ -77,7 +79,10 @@ def _process_notebook(
7779
)
7880

7981
# Use no-execute preprocessor
80-
(nb, resources,) = remove_no_execute_cells_preprocessor.preprocess(nb)
82+
(
83+
nb,
84+
resources,
85+
) = remove_no_execute_cells_preprocessor.preprocess(nb)
8186

8287
(nb, resources) = update_variables_preprocessor.preprocess(nb, resources)
8388

@@ -183,7 +188,8 @@ def process_and_execute_notebook(
183188

184189

185190
def get_changed_notebooks(
186-
test_paths_file: str, base_branch: Optional[str] = None,
191+
test_paths_file: str,
192+
base_branch: Optional[str] = None,
187193
) -> List[str]:
188194
"""
189195
Get the notebooks that exist under the folders defined in the test_paths_file.
@@ -293,7 +299,9 @@ def process_and_execute_notebooks(
293299
print("\n=== RESULTS ===\n")
294300

295301
results_sorted = sorted(
296-
notebook_execution_results, key=lambda result: result.is_pass, reverse=True,
302+
notebook_execution_results,
303+
key=lambda result: result.is_pass,
304+
reverse=True,
297305
)
298306

299307
# Print results

synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/execute_notebook_helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929

3030
def execute_notebook(
31-
notebook_source: str, output_file_or_uri: str, should_log_output: bool,
31+
notebook_source: str,
32+
output_file_or_uri: str,
33+
should_log_output: bool,
3234
):
3335
"""Execute a single notebook using Papermill"""
3436
file_name = os.path.basename(os.path.normpath(notebook_source))

synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/utils/NotebookProcessors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def preprocess(self, notebook, resources=None):
5454
for cell in notebook.cells:
5555
if cell.cell_type == "code":
5656
cell.source = self.update_variables(
57-
content=cell.source, replacement_map=self._replacement_map,
57+
content=cell.source,
58+
replacement_map=self._replacement_map,
5859
)
5960

6061
executable_cells.append(cell)

synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/utils/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def download_file(bucket_name: str, blob_name: str, destination_file: str) -> st
3131
return destination_file
3232

3333

34-
def upload_file(local_file_path: str, remote_file_path: str,) -> str:
34+
def upload_file(
35+
local_file_path: str,
36+
remote_file_path: str,
37+
) -> str:
3538
"""Copies a local file to a GCS path"""
3639
subprocess.check_output(
3740
["gsutil", "cp", local_file_path, remote_file_path], encoding="UTF-8"

synthtool/languages/java.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ def _common_template_metadata() -> Dict[str, Any]:
455455
)
456456

457457
metadata["latest_bom_version"] = latest_maven_version(
458-
group_id="com.google.cloud", artifact_id="libraries-bom",
458+
group_id="com.google.cloud",
459+
artifact_id="libraries-bom",
459460
)
460461

461462
metadata["samples"] = samples.all_samples(["samples/**/src/main/java/**/*.java"])

synthtool/languages/php.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def _merge(src: str, dest: str, path: Path):
6666

6767

6868
def _find_copy_target(src: Path, version_string: str) -> typing.Optional[Path]:
69-
"""Returns a directory contains the version subdirectory.
70-
"""
69+
"""Returns a directory contains the version subdirectory."""
7170
logger.debug("_find_copy_target called with %s and %s", src, version_string)
7271
entries = os.scandir(src)
7372
if not entries:
@@ -81,10 +80,11 @@ def _find_copy_target(src: Path, version_string: str) -> typing.Optional[Path]:
8180

8281

8382
def owlbot_copy_version(
84-
src: Path, dest: Path, copy_excludes: typing.Optional[typing.List[str]] = None,
83+
src: Path,
84+
dest: Path,
85+
copy_excludes: typing.Optional[typing.List[str]] = None,
8586
) -> None:
86-
"""Copies files from a version subdirectory.
87-
"""
87+
"""Copies files from a version subdirectory."""
8888
logger.debug("owlbot_copy_version called from %s to %s", src, dest)
8989

9090
if copy_excludes is None:
@@ -146,8 +146,7 @@ def owlbot_main(
146146
copy_excludes: typing.Optional[typing.List[str]] = None,
147147
patch_func: typing.Callable[[], None] = owlbot_patch,
148148
) -> None:
149-
"""Copies files from generated tree.
150-
"""
149+
"""Copies files from generated tree."""
151150
entries = os.scandir(src)
152151
if not entries:
153152
logger.info("there is no version subdirectory to copy")
@@ -161,9 +160,7 @@ def owlbot_main(
161160

162161

163162
def owlbot_entrypoint(staging_dir: str = STAGING_DIR) -> None:
164-
"""Copies files from staging and template directories into current working dir.
165-
166-
"""
163+
"""Copies files from staging and template directories into current working dir."""
167164
logging.basicConfig(level=logging.INFO)
168165

169166
logger.debug("owlbot_main called")

0 commit comments

Comments
 (0)