Skip to content

Commit

Permalink
apply Black 2024 style in fbcode (9/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: D54447729

fbshipit-source-id: fc781322b254f7027c24888cdadd5f1e90325ba8
  • Loading branch information
amyreese authored and facebook-github-bot committed Mar 3, 2024
1 parent fc4479e commit 13dc119
Show file tree
Hide file tree
Showing 72 changed files with 176 additions and 149 deletions.
2 changes: 2 additions & 0 deletions addons/build-tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
print_err = functools.partial(print, file=sys.stderr)
glob_r = functools.partial(glob.glob, recursive=True)


# used to detect if files are changed.
def hash_path_contents(paths: List[str]):
h = hashlib.sha1()
Expand All @@ -39,6 +40,7 @@ def hash_path_contents(paths: List[str]):
WALK_EXCLUDE_DIRS = ["node_modules", "build", "dist", "vscode-build", "coverage"]
WALK_EXCLUDE_EXTS = ".xz"


# find source code files (to hash_path_contents), excluding build results and node_modules
def walk_src_files(top: str):
for root, dirs, files in os.walk(top):
Expand Down
1 change: 1 addition & 0 deletions eden/fs/cli/buck.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from . import proc_utils
from .util import get_environment_suitable_for_subprocess


# In the EdenFS buck integration tests we build buck from source
# in these tests we need to use the source built buck. The path for
# this will be in the SOURCE_BUILT_BUCK environment variable. Otherwise we use
Expand Down
28 changes: 14 additions & 14 deletions eden/fs/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,15 @@ class ListMountInfo(typing.NamedTuple):
def to_json_dict(self) -> Dict[str, Any]:
return {
"data_dir": self.data_dir.as_posix(),
"state": MountState._VALUES_TO_NAMES.get(self.state)
if self.state is not None
else "NOT_RUNNING",
"state": (
MountState._VALUES_TO_NAMES.get(self.state)
if self.state is not None
else "NOT_RUNNING"
),
"configured": self.configured,
"backing_repo": self.backing_repo.as_posix()
if self.backing_repo is not None
else None,
"backing_repo": (
self.backing_repo.as_posix() if self.backing_repo is not None else None
),
}


Expand All @@ -234,17 +236,15 @@ def get_config_int(self, key: str, default: int) -> int:
except ValueError:
return default

def get_config_value(self, key: str, default: str) -> str:
...
def get_config_value(self, key: str, default: str) -> str: ...

def get_config_bool(self, key: str, default: bool) -> bool:
...
def get_config_bool(self, key: str, default: bool) -> bool: ...

def get_config_strs(self, key: str, default: configutil.Strs) -> configutil.Strs:
...
def get_config_strs(
self, key: str, default: configutil.Strs
) -> configutil.Strs: ...

def get_checkouts(self) -> List["EdenCheckout"]:
...
def get_checkouts(self) -> List["EdenCheckout"]: ...


class EdenInstance(AbstractEdenInstance):
Expand Down
4 changes: 2 additions & 2 deletions eden/fs/cli/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def run(self, args: argparse.Namespace) -> int:
processes.items(), key=lambda x: x[1].fetch_count, reverse=True
)

for (pid, process) in sorted_processes:
for pid, process in sorted_processes:
if process.fetch_count:
row: Dict[str, str] = {}
cmd = process.cmd
Expand Down Expand Up @@ -663,7 +663,7 @@ def check_size_corruption(

if local_store_corruption:
print(f"{len(local_store_corruption)} corrupted sizes in the local store")
for (filename, mismatch) in local_store_corruption[:10]:
for filename, mismatch in local_store_corruption[:10]:
print(
f"{filename} --"
f"actual size: {mismatch.actual_blobsize} -- "
Expand Down
8 changes: 5 additions & 3 deletions eden/fs/cli/doctor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ def _get_checkouts_info(self) -> Dict[Path, CheckoutInfo]:
checkout = CheckoutInfo(
self.instance,
path,
backing_repo=Path(os.fsdecode(mount.backingRepoPath))
if mount.backingRepoPath is not None
else None,
backing_repo=(
Path(os.fsdecode(mount.backingRepoPath))
if mount.backingRepoPath is not None
else None
),
running_state_dir=Path(os.fsdecode(mount.edenClientPath)),
state=mount_state,
mount_inode_info=mount_point_info.get(mount.mountPoint),
Expand Down
3 changes: 1 addition & 2 deletions eden/fs/cli/doctor/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def add_problem(self, problem: ProblemBase) -> None:
else:
self.add_problem_impl(problem)

def add_problem_impl(self, problem: ProblemBase) -> None:
...
def add_problem_impl(self, problem: ProblemBase) -> None: ...


class ProblemFixer(ProblemTracker):
Expand Down
18 changes: 9 additions & 9 deletions eden/fs/cli/doctor/test/lib/fake_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def __init__(self, eden_dir: Path, mount_table: FakeMountTable) -> None:
def _get_default_mount_state() -> Optional[eden_ttypes.MountState]:
return eden_ttypes.MountState.RUNNING

self._path_mount_state: Dict[
bytes, Optional[eden_ttypes.MountState]
] = defaultdict(_get_default_mount_state)

self._path_mount_inode_info: Dict[
bytes, eden_ttypes.MountInodeInfo
] = defaultdict(
lambda: eden_ttypes.MountInodeInfo(
unloadedInodeCount=1, loadedFileCount=2, loadedTreeCount=3
self._path_mount_state: Dict[bytes, Optional[eden_ttypes.MountState]] = (
defaultdict(_get_default_mount_state)
)

self._path_mount_inode_info: Dict[bytes, eden_ttypes.MountInodeInfo] = (
defaultdict(
lambda: eden_ttypes.MountInodeInfo(
unloadedInodeCount=1, loadedFileCount=2, loadedTreeCount=3
)
)
)

Expand Down
1 change: 1 addition & 0 deletions eden/fs/cli/mtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

kMountStaleSecondsTimeout = 10


# Note this function needs to be a global function, otherwise it will cause
# errors to spawn a process with this function as the entry point.
def lstat_process(path: Union[bytes, str]) -> None:
Expand Down
1 change: 1 addition & 0 deletions eden/fs/cli/prefetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .config import EdenCheckout, EdenInstance
from .subcmd import Subcmd


# Avoid CRLF line-endings on Windows.
def _println(val: str) -> None:
buffer = sys.stdout.buffer
Expand Down
26 changes: 10 additions & 16 deletions eden/fs/cli/proc_utils_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,29 @@ def raise_win_error() -> NoReturn:
# checking for us.
class _win32:
@staticmethod
def OpenProcess(desired_access: int, inherit_handle: bool, pid: int) -> _HANDLE:
...
def OpenProcess(
desired_access: int, inherit_handle: bool, pid: int
) -> _HANDLE: ...

@staticmethod
def OpenProcessToken(
handle: _HANDLE, desired_access: int, token_handle: _PHANDLE
) -> bool:
...
) -> bool: ...

@staticmethod
def CloseHandle(handle: _HANDLE) -> None:
...
def CloseHandle(handle: _HANDLE) -> None: ...

@staticmethod
def TerminateProcess(handle: _HANDLE, exit_code: int) -> bool:
...
def TerminateProcess(handle: _HANDLE, exit_code: int) -> bool: ...

@staticmethod
def GetExitCodeProcess(handle: _HANDLE, exit_code: _LPDWORD) -> _BOOL:
...
def GetExitCodeProcess(handle: _HANDLE, exit_code: _LPDWORD) -> _BOOL: ...

class psapi:
@staticmethod
def GetProcessImageFileNameW(
handle: _HANDLE, fileName: _LPWSTR, size: _DWORD
) -> _DWORD:
...
) -> _DWORD: ...

class advapi32:
@staticmethod
Expand All @@ -83,11 +79,9 @@ def GetTokenInformation(
token_information: ctypes._CArgObject,
token_information_length: _DWORD,
return_length: _PDWORD,
) -> bool:
...
) -> bool: ...

def raise_win_error() -> NoReturn:
...
def raise_win_error() -> NoReturn: ...


_PROCESS_TERMINATE = 0x0001
Expand Down
6 changes: 3 additions & 3 deletions eden/fs/cli/rage.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def print_diagnostic_info(


def report_edenfs_bug(instance: EdenInstance, reporter: str) -> None:
rage_lambda: Callable[
[EdenInstance, IO[bytes]], None
] = lambda inst, sink: print_diagnostic_info(inst, sink, False)
rage_lambda: Callable[[EdenInstance, IO[bytes]], None] = (
lambda inst, sink: print_diagnostic_info(inst, sink, False)
)
_report_edenfs_bug(rage_lambda, instance, reporter)


Expand Down
20 changes: 12 additions & 8 deletions eden/integration/hg/symlink_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ def test_symlink_diff(self) -> None:
self.write_file("symlink", os.path.join("adir", "hello.txt"))
self.assertEqual(
self.repo.hg("diff"),
"""diff --git a/symlink b/symlink
(
"""diff --git a/symlink b/symlink
old mode 120000
new mode 100644
"""
if os.name != "nt"
else r"""diff --git a/symlink b/symlink
if os.name != "nt"
else r"""diff --git a/symlink b/symlink
old mode 120000
new mode 100644
--- a/symlink
Expand All @@ -140,19 +141,21 @@ def test_symlink_diff(self) -> None:
\ No newline at end of file
+adir\hello.txt
\ No newline at end of file
""",
"""
),
)
self.repo.update(self.quasi_symlink_commit, clean=True)
os.remove(self.get_path("symlink"))
self.repo.symlink("symlink", os.path.join("adir", "hello.txt"))
self.assertEqual(
self.repo.hg("diff"),
"""diff --git a/symlink b/symlink
(
"""diff --git a/symlink b/symlink
old mode 100644
new mode 120000
"""
if os.name != "nt"
else r"""diff --git a/symlink b/symlink
if os.name != "nt"
else r"""diff --git a/symlink b/symlink
old mode 100644
new mode 120000
--- a/symlink
Expand All @@ -162,7 +165,8 @@ def test_symlink_diff(self) -> None:
\ No newline at end of file
+adir/hello.txt
\ No newline at end of file
""",
"""
),
)

def test_directory_listing(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion eden/integration/persistence_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_preserves_nonmaterialized_inode_metadata(self) -> None:

new_stats = [os.lstat(os.path.join(self.mount, path)) for path in inode_paths]

for (path, old_stat, new_stat) in zip(inode_paths, old_stats, new_stats):
for path, old_stat, new_stat in zip(inode_paths, old_stats, new_stats):
self.assertEqual(
old_stat.st_ino,
new_stat.st_ino,
Expand Down
18 changes: 9 additions & 9 deletions eden/integration/redirect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ def test_fixup_mounts_things(self) -> None:
"type": "bind",
"target": profile_path,
"source": ".eden-redirections",
"state": "not-mounted"
if sys.platform != "win32"
else "symlink-missing",
"state": (
"not-mounted" if sys.platform != "win32" else "symlink-missing"
),
},
],
)
Expand Down Expand Up @@ -355,9 +355,9 @@ def test_fixup_mounts_things(self) -> None:
"type": "bind",
"target": profile_path,
"source": ".eden-redirections",
"state": "not-mounted"
if sys.platform != "win32"
else "symlink-missing",
"state": (
"not-mounted" if sys.platform != "win32" else "symlink-missing"
),
},
],
)
Expand Down Expand Up @@ -443,9 +443,9 @@ def test_unmount_unmounts_things(self) -> None:
"type": "bind",
"target": profile_path,
"source": ".eden-redirections",
"state": "not-mounted"
if sys.platform != "win32"
else "symlink-missing",
"state": (
"not-mounted" if sys.platform != "win32" else "symlink-missing"
),
},
],
)
Expand Down
9 changes: 3 additions & 6 deletions eden/integration/snapshot/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,13 @@ def __contains__(self, path: object) -> bool:
return key in self._entries

@typing.overload
def pop(self, path: _AnyPath) -> ExpectedFileBase:
...
def pop(self, path: _AnyPath) -> ExpectedFileBase: ...

@typing.overload # noqa: F811
def pop(self, path: _AnyPath, default: ExpectedFileBase) -> ExpectedFileBase:
...
def pop(self, path: _AnyPath, default: ExpectedFileBase) -> ExpectedFileBase: ...

@typing.overload # noqa: F811
def pop(self, path: _AnyPath, default: None) -> Optional[ExpectedFileBase]:
...
def pop(self, path: _AnyPath, default: None) -> Optional[ExpectedFileBase]: ...

def pop( # noqa: F811
self,
Expand Down
2 changes: 1 addition & 1 deletion eden/mononoke/tests/integration/integration_runner_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def run_tests(

success = True

for (prefix, runner, tests) in work:
for prefix, runner, tests in work:
args = list(test_flags.runner_args())

if xunit_output is not None:
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/ghstack/rage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main(latest: bool = False) -> None:
if not latest:
print("Which invocation would you like to report?")
print()
for (i, fn) in enumerate(logs):
for i, fn in enumerate(logs):
if next_index > 10:
break

Expand Down
2 changes: 1 addition & 1 deletion eden/scm/sapling/ancestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def deepest(nodes):
depth = [0] * count
seen = [0] * count
mapping = []
for (i, n) in enumerate(sorted(nodes)):
for i, n in enumerate(sorted(nodes)):
depth[n] = 1
b = 1 << i
seen[n] = b
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/sapling/bundle2.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _makefpartparamsizes(nbparams):

def parthandler(
parttype: str,
params: "Tuple[str, ...]" = ()
params: "Tuple[str, ...]" = (),
# pyre-fixme[31]: Expression `unbundlepart), None)])]` is not a valid type.
) -> "Callable[Callable[(bundleoperation, unbundlepart), None], Callable[(bundleoperation, unbundlepart), None]]":
"""decorator that register a function as a bundle2 part handler
Expand Down
1 change: 1 addition & 0 deletions eden/scm/sapling/changegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ def generatefiles(
raise error.Abort(msg)

linkrevnodes = linknodes(filerevlog, fname)

# Lookup for filenodes, we collected the linkrev nodes above in
# the fastpath case and with lookupmf in the slowpath case.
def lookupfilelog(x):
Expand Down
2 changes: 1 addition & 1 deletion eden/scm/sapling/cmdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -3402,7 +3402,7 @@ def displaygraph(
renderer.reserve(rev)

show_abbreviated_ancestors = ShowAbbreviatedAncestorsWhen.load_from_config(repo.ui)
for (rev, _type, ctx, parents) in dag:
for rev, _type, ctx, parents in dag:
char = formatnode(repo, ctx)
copies = None
if getrenamed and ctx.rev():
Expand Down
Loading

0 comments on commit 13dc119

Please sign in to comment.