Skip to content

Commit

Permalink
apply Black 2024 style in fbcode (6/16)
Browse files Browse the repository at this point in the history
Summary:
Formats the covered files with pyfmt.

paintitblack

Reviewed By: aleivag

Differential Revision: D54447740

fbshipit-source-id: e6562ba4b2cd9046d8912400ae69b2a7baa94c1e
  • Loading branch information
amyreese authored and facebook-github-bot committed Mar 3, 2024
1 parent 055676d commit 62b1545
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 63 deletions.
1 change: 1 addition & 0 deletions multipy/runtime/test_deploy_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
from pathlib import Path


# we've taken steps to clear out the embedded python environment,
# so we have to go searching for real python to figure out where its libraries are installed.
def python_path(cpath):
Expand Down
8 changes: 6 additions & 2 deletions scripts/auto_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
import sys
from typing import List, Tuple

COPYRIGHT_NOTICE_PYTHON: str = """
COPYRIGHT_NOTICE_PYTHON: str = (
"""
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
""".strip()
)

COPYRIGHT_NOTICE_C: str = """
COPYRIGHT_NOTICE_C: str = (
"""
// Copyright (c) Meta Platforms, Inc. and affiliates.
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
""".strip()
)


def get_all_files_with_extension(directories: List[str], extensions: Tuple[str]):
Expand Down
10 changes: 5 additions & 5 deletions scripts/linter/adapters/black_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ def main() -> None:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
10 changes: 5 additions & 5 deletions scripts/linter/adapters/clangformat_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ def main() -> None:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
22 changes: 13 additions & 9 deletions scripts/linter/adapters/clangtidy_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
PYTORCH_ROOT = result.stdout.decode("utf-8").strip()
IS_WINDOWS: bool = os.name == "nt"


# Returns '/usr/local/include/python<version number>'
def get_python_include_dir() -> str:
return gp()["include"]
Expand Down Expand Up @@ -149,7 +150,7 @@ def check_file(
proc = run_command(
[binary, f"-p={build_dir}", *include_args, filename],
)
except (OSError) as err:
except OSError as err:
return [
LintMessage(
path=filename,
Expand Down Expand Up @@ -178,9 +179,12 @@ def check_file(
name=match["code"],
description=match["message"],
line=int(match["line"]),
char=int(match["column"])
if match["column"] is not None and not match["column"].startswith("-")
else None,
char=(
int(match["column"])
if match["column"] is not None
and not match["column"].startswith("-")
else None
),
code="CLANGTIDY",
severity=severities.get(match["severity"], LintSeverity.ERROR),
original=None,
Expand Down Expand Up @@ -225,11 +229,11 @@ def main() -> None:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
11 changes: 6 additions & 5 deletions scripts/linter/adapters/exec_linter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
EXEC: Ensure that source files are not executable.
"""

import argparse
import json
import logging
Expand Down Expand Up @@ -68,11 +69,11 @@ def check_file(filename: str) -> Optional[LintMessage]:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
26 changes: 15 additions & 11 deletions scripts/linter/adapters/flake8_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ def check_files(
try:
proc = run_command(
[sys.executable, "-mflake8", "--exit-zero"] + filenames,
extra_env={"FLAKE8_PLUGINS_PATH": flake8_plugins_path}
if flake8_plugins_path
else None,
extra_env=(
{"FLAKE8_PLUGINS_PATH": flake8_plugins_path}
if flake8_plugins_path
else None
),
retries=retries,
)
except (OSError, subprocess.CalledProcessError) as err:
Expand Down Expand Up @@ -295,9 +297,11 @@ def check_files(
get_issue_documentation_url(match["code"]),
),
line=int(match["line"]),
char=int(match["column"])
if match["column"] is not None and not match["column"].startswith("-")
else None,
char=(
int(match["column"])
if match["column"] is not None and not match["column"].startswith("-")
else None
),
code="FLAKE8",
severity=severities.get(match["code"]) or get_issue_severity(match["code"]),
original=None,
Expand Down Expand Up @@ -341,11 +345,11 @@ def main() -> None:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
10 changes: 5 additions & 5 deletions scripts/linter/adapters/grep_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ def main() -> None:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
18 changes: 10 additions & 8 deletions scripts/linter/adapters/mypy_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ def check_files(
name=match["code"],
description=match["message"],
line=int(match["line"]),
char=int(match["column"])
if match["column"] is not None and not match["column"].startswith("-")
else None,
char=(
int(match["column"])
if match["column"] is not None and not match["column"].startswith("-")
else None
),
code="MYPY",
severity=severities.get(match["severity"], LintSeverity.ERROR),
original=None,
Expand Down Expand Up @@ -157,11 +159,11 @@ def main() -> None:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
11 changes: 6 additions & 5 deletions scripts/linter/adapters/newlines_linter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
NEWLINE: Checks files to make sure there are no trailing newlines.
"""

import argparse
import json
import logging
Expand Down Expand Up @@ -145,11 +146,11 @@ def check_file(filename: str) -> Optional[LintMessage]:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down
1 change: 1 addition & 0 deletions scripts/linter/adapters/pip_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Initializer script that installs stuff to pip.
"""

import argparse
import logging
import os
Expand Down
8 changes: 5 additions & 3 deletions scripts/linter/adapters/s3_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ def download(
DRY_RUN = True

logging.basicConfig(
format="[DRY_RUN] %(levelname)s: %(message)s"
if DRY_RUN
else "%(levelname)s: %(message)s",
format=(
"[DRY_RUN] %(levelname)s: %(message)s"
if DRY_RUN
else "%(levelname)s: %(message)s"
),
level=logging.INFO,
stream=sys.stderr,
)
Expand Down
10 changes: 5 additions & 5 deletions scripts/linter/adapters/ufmt_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def main() -> None:

logging.basicConfig(
format="<%(threadName)s:%(levelname)s> %(message)s",
level=logging.NOTSET
if args.verbose
else logging.DEBUG
if len(args.filenames) < 1000
else logging.INFO,
level=(
logging.NOTSET
if args.verbose
else logging.DEBUG if len(args.filenames) < 1000 else logging.INFO
),
stream=sys.stderr,
)

Expand Down

0 comments on commit 62b1545

Please sign in to comment.