Skip to content

Commit

Permalink
Mark files ignored in configuration as ignored in pyre report
Browse files Browse the repository at this point in the history
Summary:
Noticed while testing different configurations in the tools that unless a file has an explicit ignore comment, it will be marked as the default for the configuration (unsafe or strict) even if it has been explicitly ignored in the configuration.

This checks for ignored files from the configuration and applies the appropriate module status

Reviewed By: kinto0

Differential Revision: D47851218

fbshipit-source-id: e336338ce39fc92a447480748c03d13e3479845a
  • Loading branch information
Maggie Moss authored and facebook-github-bot committed Jul 28, 2023
1 parent f00ad98 commit e142a99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 15 additions & 7 deletions client/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ def collect(
module: libcst.MetadataWrapper,
path: ModulePath,
strict_by_default: bool,
ignored: bool,
) -> ModuleData:
mode = coverage_data.collect_mode(module, strict_by_default)
mode = coverage_data.collect_mode(module, strict_by_default, ignored)
suppressions = coverage_data.collect_suppressions(module)
functions = coverage_data.collect_functions(module)
return ModuleData(
Expand All @@ -118,6 +119,7 @@ class CollectFromPathArgs:

path: ModulePath
strict_by_default: bool
ignored: bool

@staticmethod
def collect_from_path(
Expand All @@ -131,21 +133,24 @@ def collect_from_path(
module,
path=args.path,
strict_by_default=args.strict_by_default,
ignored=args.ignored,
)

@staticmethod
def collect_from_paths(
module_paths: Sequence[ModulePath],
strict_by_default: bool,
number_of_workers: int,
ignored_modules: Sequence[ModulePath],
) -> List[ModuleData]:
tasks = [
ModuleData.CollectFromPathArgs(
path=path,
strict_by_default=strict_by_default,
tasks = []
for path in module_paths:
ignored = path in ignored_modules
tasks.append(
ModuleData.CollectFromPathArgs(
path=path, strict_by_default=strict_by_default, ignored=ignored
)
)
for path in module_paths
]
with multiprocessing.Pool(number_of_workers) as pool:
return [
module_data
Expand All @@ -169,10 +174,13 @@ def run(
configuration=configuration,
paths=paths,
)
ignored_paths = [Path(path) for path in configuration.get_ignore_all_errors()]
data = ModuleData.collect_from_paths(
module_paths,
strict_by_default=configuration.is_strict(),
number_of_workers=configuration.get_number_of_workers(),
ignored_modules=get_module_paths(configuration, ignored_paths),
)

print_data_as_json(data)
return commands.ExitCode.SUCCESS
4 changes: 3 additions & 1 deletion client/coverage_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,13 @@ def visit_Comment(self, node: libcst.Comment) -> None:
def collect_mode(
module: libcst.MetadataWrapper,
strict_by_default: bool,
ignored: bool = False, # means the module was ignored in the pyre configuration
) -> ModuleModeInfo:
visitor = ModuleModeCollector(strict_by_default)
module.visit(visitor)
mode = ModuleMode.IGNORE_ALL if ignored else visitor.mode
return ModuleModeInfo(
mode=visitor.mode,
mode=mode,
explicit_comment_line=visitor.explicit_comment_line,
)

Expand Down

0 comments on commit e142a99

Please sign in to comment.