Skip to content

Commit

Permalink
Revert D19053571: refactor enabled features in start
Browse files Browse the repository at this point in the history
Differential Revision:
D19053571

Original commit changeset: b6e25a7831a4

fbshipit-source-id: 47942c29235ecec7f2f65e6c26fd5e0b483bc9e0
  • Loading branch information
aleivag authored and facebook-github-bot committed Dec 19, 2019
1 parent 4288a95 commit 43392a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
1 change: 1 addition & 0 deletions client/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def __init__(
self._analysis_directory: AnalysisDirectory = (
analysis_directory or self.generate_analysis_directory()
)
self._features: Optional[str] = arguments.features

@classmethod
def add_subparser(cls, parser: argparse._SubParsersAction) -> None:
Expand Down
53 changes: 23 additions & 30 deletions client/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
import os
from logging import Logger
from typing import Dict, List, Optional
from typing import List, Optional

from .. import configuration_monitor, filesystem, project_files_monitor
from ..analysis_directory import AnalysisDirectory
Expand All @@ -23,12 +23,11 @@
LOG: Logger = logging.getLogger(__name__)


try:
from ...facebook.enabled_features import get_enabled_features
except Exception:

def get_enabled_features() -> Dict[str, bool]:
return {}
def _fine_grained_incremental_override(feature_string: str) -> bool:
try:
return json.loads(feature_string).get("enable_fine_grained_incremental", False)
except Exception:
return False


class Start(Reporting):
Expand All @@ -48,9 +47,20 @@ def __init__(
self._store_type_check_resolution: bool = arguments.store_type_check_resolution
self._use_watchman: bool = not arguments.no_watchman

self._provided_incremental_style: Optional[
IncrementalStyle
] = arguments.incremental_style
features = self._features
fine_grained_override = (
_fine_grained_incremental_override(features)
if features is not None
else False
)
default_incremental_style = (
IncrementalStyle.FINE_GRAINED
if fine_grained_override
else IncrementalStyle.SHALLOW
)
self._incremental_style: IncrementalStyle = (
arguments.incremental_style or default_incremental_style
)

if self._no_saved_state:
self._save_initial_state_to: Optional[str] = None
Expand Down Expand Up @@ -139,23 +149,6 @@ def _run(self) -> None:
else:
raise exception

def _incremental_style(self) -> IncrementalStyle:
provided_incremental_style = self._provided_incremental_style
if provided_incremental_style is not None:
return provided_incremental_style

# If no explicit incremental style was provided in the arguments, compute from
# Gatekeepers.
LOG.info("Checking enabled features...")
features = get_enabled_features()
LOG.info("Determined enabled features.")
fine_grained_override = features.get("enable_fine_grained_incremental", False)
return (
IncrementalStyle.FINE_GRAINED
if fine_grained_override
else IncrementalStyle.SHALLOW
)

def _flags(self) -> List[str]:
flags = super()._flags()
if self._taint_models_path:
Expand Down Expand Up @@ -222,13 +215,13 @@ def _flags(self) -> List[str]:
for extension in extensions:
flags.extend(["-extension", extension])

incremental_style = self._incremental_style()
if incremental_style == IncrementalStyle.TRANSITIVE:
if self._incremental_style == IncrementalStyle.TRANSITIVE:
flags.append("-transitive")
elif incremental_style == IncrementalStyle.FINE_GRAINED:
elif self._incremental_style == IncrementalStyle.FINE_GRAINED:
flags.append("-new-incremental-check")

if self._configuration.autocomplete:
flags.append("-autocomplete")
flags.extend(self._feature_flags())

return flags
17 changes: 5 additions & 12 deletions client/commands/tests/start_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
from ...commands import start # noqa
from ...filesystem import acquire_lock # noqa
from ..command import __name__ as client_name
from ..start import __name__ as start_name
from .command_test import mock_arguments, mock_configuration


_typeshed_search_path: str = "{}.typeshed_search_path".format(commands.start.__name__)


@patch("{}.get_enabled_features".format(start_name), return_value={})
class StartTest(unittest.TestCase):
@patch("{}.find_project_root".format(client_name), return_value=".")
@patch("{}.find_local_root".format(client_name), return_value=None)
Expand All @@ -38,7 +36,6 @@ def test_start(
lock_file,
find_local_root,
find_project_root,
get_enabled_features,
) -> None:
original_directory = "/original/directory"
arguments = mock_arguments()
Expand Down Expand Up @@ -238,11 +235,7 @@ def raise_mount_error(fileno, command):
@patch(_typeshed_search_path, Mock(return_value=["path3"]))
@patch.object(commands.Reporting, "_get_directories_to_analyze", return_value=set())
def test_start_flags(
self,
get_directories_to_analyze,
find_local_root,
find_project_root,
get_enabled_features,
self, get_directories_to_analyze, find_local_root, find_project_root
) -> None:
# Check start with watchman.
original_directory = "/original/directory"
Expand Down Expand Up @@ -733,9 +726,9 @@ def test_start_flags(

# Incremental style override tests
arguments = mock_arguments()
arguments.features = '{ "enable_fine_grained_incremental": false }'
arguments.incremental_style = None
configuration = mock_configuration(version_hash="hash")
get_enabled_features.return_value = {"enable_fine_grained_incremental": False}
command = commands.Start(
arguments, original_directory, configuration, AnalysisDirectory(".")
)
Expand All @@ -758,9 +751,9 @@ def test_start_flags(
)

arguments = mock_arguments()
arguments.features = '{ "irrelevant_feature": true }'
arguments.incremental_style = None
configuration = mock_configuration(version_hash="hash")
get_enabled_features.return_value = {"irrelevant_feature": True}
command = commands.Start(
arguments, original_directory, configuration, AnalysisDirectory(".")
)
Expand All @@ -783,9 +776,9 @@ def test_start_flags(
)

arguments = mock_arguments()
arguments.features = '{ "enable_fine_grained_incremental": true }'
arguments.incremental_style = None
configuration = mock_configuration(version_hash="hash")
get_enabled_features.return_value = {"enable_fine_grained_incremental": True}
command = commands.Start(
arguments, original_directory, configuration, AnalysisDirectory(".")
)
Expand All @@ -810,8 +803,8 @@ def test_start_flags(

# Command line override takes precedence
arguments = mock_arguments()
arguments.features = '{ "enable_fine_grained_incremental": true }'
arguments.incremental_style = commands.IncrementalStyle.SHALLOW
get_enabled_features.return_value = {"enable_fine_grained_incremental": True}
configuration = mock_configuration(version_hash="hash")
command = commands.Start(
arguments, original_directory, configuration, AnalysisDirectory(".")
Expand Down

0 comments on commit 43392a5

Please sign in to comment.