mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
Improve Pyre workarounds for FindEXE
Summary: A bug in Pyre causes the properties of FindEXE to have an incorrect type. We currently work around this bug by silencing type errors. Unfortunately, this might silence legitimate errors too. Instead of silencing type errors, using `typing.cast` to tell Pyre the correct type. This should expose legitimate errors if they exist. This diff should not change behavior. Reviewed By: chadaustin Differential Revision: D13709138 fbshipit-source-id: 55f47f47062a35911c6bbe03ffd7b02a90a5107f
This commit is contained in:
parent
82e63507aa
commit
69515ab060
@ -12,6 +12,7 @@ import os
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import typing
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
from typing import Optional, Sequence, Set
|
||||
@ -319,8 +320,7 @@ class CloneTest(testcase.EdenRepoTest):
|
||||
clone_output = self.eden.run_cmd(
|
||||
"clone",
|
||||
"--daemon-binary",
|
||||
# pyre-ignore[6]: T38947910
|
||||
FindExe.EDEN_DAEMON,
|
||||
typing.cast(str, FindExe.EDEN_DAEMON), # T38947910
|
||||
self.repo.path,
|
||||
str(tmp),
|
||||
"--daemon-args",
|
||||
@ -380,11 +380,10 @@ class CloneFakeEdenFSTestBase(ServiceTestCaseBase, PexpectAssertionMixin):
|
||||
args = (
|
||||
["--config-dir", str(self.eden_dir)]
|
||||
+ self.get_required_eden_cli_args()
|
||||
# pyre-ignore[6]: T38947910
|
||||
+ [
|
||||
"clone",
|
||||
"--daemon-binary",
|
||||
FindExe.FAKE_EDENFS,
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
str(repo_path),
|
||||
str(mount_path),
|
||||
]
|
||||
|
@ -14,6 +14,7 @@ import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import typing
|
||||
from types import TracebackType
|
||||
from typing import Any, Dict, List, Optional, Union, cast
|
||||
|
||||
@ -136,8 +137,11 @@ class EdenFS(object):
|
||||
A list of arguments to run Eden that can be used with
|
||||
subprocess.Popen() or subprocess.check_call().
|
||||
"""
|
||||
# pyre-ignore[9]: T38947910
|
||||
cmd = [FindExe.EDEN_CLI, "--config-dir", self._eden_dir] # type: List[str]
|
||||
cmd = [
|
||||
typing.cast(str, FindExe.EDEN_CLI), # T38947910
|
||||
"--config-dir",
|
||||
self._eden_dir,
|
||||
]
|
||||
if self._etc_eden_dir:
|
||||
cmd += ["--etc-eden-dir", self._etc_eden_dir]
|
||||
if self._home_dir:
|
||||
@ -180,9 +184,9 @@ class EdenFS(object):
|
||||
"--local_storage_engine_unsafe",
|
||||
self._storage_engine,
|
||||
"--hgImportHelper",
|
||||
FindExe.EDEN_HG_IMPORT_HELPER,
|
||||
typing.cast(str, FindExe.EDEN_HG_IMPORT_HELPER), # T38947910
|
||||
"--hgPath",
|
||||
FindExe.HG_REAL,
|
||||
typing.cast(str, FindExe.HG_REAL), # T38947910
|
||||
# FIXME: find a way to introduce this into the test matrix so
|
||||
# that we can test the old and the new way of using the importer
|
||||
"--hgImportUseDebugSubcommand",
|
||||
@ -210,7 +214,6 @@ class EdenFS(object):
|
||||
if self._extra_args:
|
||||
extra_daemon_args.extend(self._extra_args)
|
||||
|
||||
# pyre-ignore[7]: T38947910
|
||||
return extra_daemon_args
|
||||
|
||||
def _spawn(self, gdb: bool = False, takeover: bool = False) -> None:
|
||||
@ -220,8 +223,7 @@ class EdenFS(object):
|
||||
args = self._get_eden_args(
|
||||
"daemon",
|
||||
"--daemon-binary",
|
||||
# pyre-ignore[6]: T38947910
|
||||
FindExe.EDEN_DAEMON,
|
||||
typing.cast(str, FindExe.EDEN_DAEMON), # T38947910
|
||||
"--foreground",
|
||||
)
|
||||
|
||||
@ -310,8 +312,11 @@ class EdenFS(object):
|
||||
"""
|
||||
assert self._process is not None
|
||||
|
||||
cmd = [FindExe.TAKEOVER_TOOL, "--edenDir", self._eden_dir]
|
||||
# pyre-ignore[6]: T38947910
|
||||
cmd = [
|
||||
typing.cast(str, FindExe.TAKEOVER_TOOL), # T38947910
|
||||
"--edenDir",
|
||||
self._eden_dir,
|
||||
]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
old_process = self._process
|
||||
|
@ -25,8 +25,9 @@ class EdenFSSystemdMixin(metaclass=abc.ABCMeta):
|
||||
assert self.systemd is None
|
||||
self.systemd = self.make_temporary_systemd_user_service_manager()
|
||||
self.systemd.enable_runtime_unit_from_file(
|
||||
# pyre-ignore[6]: T38947910
|
||||
unit_file=pathlib.Path(FindExe.SYSTEMD_FB_EDENFS_SERVICE)
|
||||
unit_file=pathlib.Path(
|
||||
typing.cast(str, FindExe.SYSTEMD_FB_EDENFS_SERVICE) # T38947910
|
||||
)
|
||||
)
|
||||
self.set_environment_variables(self.systemd.extra_env)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class FakeEdenFS(typing.ContextManager[int]):
|
||||
extra_arguments: typing.Optional[typing.Sequence[str]] = None,
|
||||
) -> "FakeEdenFS":
|
||||
command = [
|
||||
FindExe.FAKE_EDENFS,
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
"--configPath",
|
||||
str(home_dir / ".edenrc"),
|
||||
"--edenDir",
|
||||
@ -42,7 +42,6 @@ class FakeEdenFS(typing.ContextManager[int]):
|
||||
]
|
||||
if extra_arguments:
|
||||
command.extend(extra_arguments)
|
||||
# pyre-ignore[6]: T38947910
|
||||
subprocess.check_call(command)
|
||||
return cls.from_existing_process(eden_dir=eden_dir)
|
||||
|
||||
@ -55,7 +54,7 @@ class FakeEdenFS(typing.ContextManager[int]):
|
||||
extra_arguments: typing.Optional[typing.Sequence[str]] = None,
|
||||
) -> "FakeEdenFS":
|
||||
command = [
|
||||
FindExe.EDEN_CLI,
|
||||
typing.cast(str, FindExe.EDEN_CLI), # T38947910
|
||||
"--config-dir",
|
||||
str(eden_dir),
|
||||
"--etc-eden-dir",
|
||||
@ -64,12 +63,11 @@ class FakeEdenFS(typing.ContextManager[int]):
|
||||
str(home_dir),
|
||||
"start",
|
||||
"--daemon-binary",
|
||||
FindExe.FAKE_EDENFS,
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
]
|
||||
if extra_arguments:
|
||||
command.append("--")
|
||||
command.extend(extra_arguments)
|
||||
# pyre-ignore[6]: T38947910
|
||||
subprocess.check_call(command)
|
||||
return cls.from_existing_process(eden_dir=eden_dir)
|
||||
|
||||
|
@ -16,6 +16,7 @@ import distutils.spawn
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import typing
|
||||
from typing import Callable, Dict, List, Optional, Type
|
||||
|
||||
from libfb.py import pathutils
|
||||
@ -194,8 +195,7 @@ class FindExeClass(object):
|
||||
return hg_bin
|
||||
|
||||
# Fall back to the real hg binary
|
||||
# pyre-ignore[7]: T38947910
|
||||
return self.HG_REAL
|
||||
return typing.cast(str, self.HG_REAL) # T38947910
|
||||
|
||||
def _find_hg_real(self) -> str:
|
||||
# If HG_REAL_BIN is set in the environment, use that.
|
||||
|
@ -425,8 +425,9 @@ class _TransientUnmanagedSystemdUserServiceManager:
|
||||
# HACK(strager): Work around 'systemd --user' refusing to start if the
|
||||
# system is not managed by systemd.
|
||||
env["LD_PRELOAD"] = str(
|
||||
# pyre-ignore[6]: T38947910
|
||||
pathlib.Path(FindExe.FORCE_SD_BOOTED).resolve(strict=True)
|
||||
pathlib.Path(
|
||||
typing.cast(str, FindExe.FORCE_SD_BOOTED) # T38947910
|
||||
).resolve(strict=True)
|
||||
)
|
||||
process = subprocess.Popen(
|
||||
[
|
||||
|
@ -35,12 +35,14 @@ class RestartTestBase(ServiceTestCaseBase):
|
||||
|
||||
def ensure_stopped() -> None:
|
||||
stop_cmd = (
|
||||
[FindExe.EDEN_CLI, "--config-dir", str(self.eden_dir)]
|
||||
# pyre-ignore[6]: T38220626
|
||||
[
|
||||
typing.cast(str, FindExe.EDEN_CLI), # T38947910
|
||||
"--config-dir",
|
||||
str(self.eden_dir),
|
||||
]
|
||||
+ self.get_required_eden_cli_args()
|
||||
+ ["stop"]
|
||||
)
|
||||
# pyre-ignore: T38947910
|
||||
subprocess.call(stop_cmd)
|
||||
|
||||
self.addCleanup(ensure_stopped)
|
||||
|
@ -133,8 +133,7 @@ class DirectInvokeTest(unittest.TestCase):
|
||||
self._check_error(["restart"])
|
||||
|
||||
def _check_error(self, args: List[str], err: Optional[str] = None) -> None:
|
||||
# pyre-ignore[9]: T38947910
|
||||
cmd = [FindExe.EDEN_DAEMON] # type: List[str]
|
||||
cmd = [typing.cast(str, FindExe.EDEN_DAEMON)] # T38947910
|
||||
cmd.extend(args)
|
||||
out = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
self.assertEqual(os.EX_USAGE, out.returncode)
|
||||
@ -271,8 +270,11 @@ class StartFakeEdenFSTest(ServiceTestCaseBase, PexpectAssertionMixin):
|
||||
args = (
|
||||
self.get_required_eden_cli_args()
|
||||
+ config_dir_args
|
||||
# pyre-ignore: T38947910
|
||||
+ ["start", "--daemon-binary", FindExe.FAKE_EDENFS]
|
||||
+ [
|
||||
"start",
|
||||
"--daemon-binary",
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
]
|
||||
)
|
||||
start_process: pexpect.spawn[str] = pexpect.spawn(
|
||||
FindExe.EDEN_CLI, args, encoding="utf-8", logfile=sys.stderr
|
||||
@ -315,8 +317,11 @@ class StartFakeEdenFSTest(ServiceTestCaseBase, PexpectAssertionMixin):
|
||||
args = (
|
||||
["--config-dir", str(eden_dir)]
|
||||
+ self.get_required_eden_cli_args()
|
||||
# pyre-ignore[6]: T38947910
|
||||
+ ["start", "--daemon-binary", FindExe.FAKE_EDENFS]
|
||||
+ [
|
||||
"start",
|
||||
"--daemon-binary",
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
]
|
||||
)
|
||||
if extra_args:
|
||||
args.extend(extra_args)
|
||||
@ -337,7 +342,7 @@ def run_eden_start_with_real_daemon(
|
||||
else:
|
||||
env.pop("EDEN_EXPERIMENTAL_SYSTEMD", None)
|
||||
command = [
|
||||
FindExe.EDEN_CLI,
|
||||
typing.cast(str, FindExe.EDEN_CLI), # T38947910
|
||||
"--config-dir",
|
||||
str(eden_dir),
|
||||
"--etc-eden-dir",
|
||||
@ -346,11 +351,10 @@ def run_eden_start_with_real_daemon(
|
||||
str(home_dir),
|
||||
"start",
|
||||
"--daemon-binary",
|
||||
FindExe.EDEN_DAEMON,
|
||||
typing.cast(str, FindExe.EDEN_DAEMON), # T38947910
|
||||
]
|
||||
if eden_start_needs_allow_root_option(systemd=systemd):
|
||||
command.extend(["--", "--allowRoot"])
|
||||
# pyre-ignore[6]: T38947910
|
||||
subprocess.check_call(command, env=env)
|
||||
|
||||
|
||||
|
@ -56,8 +56,12 @@ class SystemdTest(
|
||||
start_process.expect_exact("Started edenfs")
|
||||
|
||||
test(start_args=["--", "--allowRoot"])
|
||||
# pyre-ignore[6]: T38947910
|
||||
test(start_args=["--daemon-binary", FindExe.FAKE_EDENFS])
|
||||
test(
|
||||
start_args=[
|
||||
"--daemon-binary",
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
]
|
||||
)
|
||||
|
||||
# TODO(T33122320): Delete this test when systemd is properly integrated.
|
||||
def test_eden_start_with_systemd_disabled_does_not_say_systemd_mode_is_enabled(
|
||||
@ -81,17 +85,23 @@ class SystemdTest(
|
||||
)
|
||||
|
||||
test(start_args=["--", "--allowRoot"])
|
||||
# pyre-ignore[6]: T38947910
|
||||
test(start_args=["--daemon-binary", FindExe.FAKE_EDENFS])
|
||||
test(
|
||||
start_args=[
|
||||
"--daemon-binary",
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
]
|
||||
)
|
||||
|
||||
def test_eden_start_starts_systemd_service(self) -> None:
|
||||
self.set_up_edenfs_systemd_service()
|
||||
subprocess.check_call(
|
||||
# pyre-ignore[6]: T38947910
|
||||
[FindExe.EDEN_CLI]
|
||||
# pyre-ignore[6]: T38220626
|
||||
[typing.cast(str, FindExe.EDEN_CLI)] # T38947910
|
||||
+ self.get_required_eden_cli_args()
|
||||
+ ["start", "--daemon-binary", FindExe.FAKE_EDENFS]
|
||||
+ [
|
||||
"start",
|
||||
"--daemon-binary",
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
]
|
||||
)
|
||||
self.assert_systemd_service_is_active(eden_dir=pathlib.Path(self.eden_dir))
|
||||
|
||||
@ -99,14 +109,12 @@ class SystemdTest(
|
||||
self.set_up_edenfs_systemd_service()
|
||||
self.assert_systemd_service_is_stopped(eden_dir=pathlib.Path(self.eden_dir))
|
||||
subprocess.call(
|
||||
# pyre-ignore[6]: T38947910
|
||||
[FindExe.EDEN_CLI]
|
||||
# pyre-ignore[6]: T38220626
|
||||
[typing.cast(str, FindExe.EDEN_CLI)] # T38947910
|
||||
+ self.get_required_eden_cli_args()
|
||||
+ [
|
||||
"start",
|
||||
"--daemon-binary",
|
||||
FindExe.FAKE_EDENFS,
|
||||
typing.cast(str, FindExe.FAKE_EDENFS), # T38947910
|
||||
"--",
|
||||
"--failDuringStartup",
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user