def test_group_field_sets_by_constraints() -> None: py2_fs = MockFieldSet.create_for_test("//:py2", ">=2.7,<3") py3_fs = [ MockFieldSet.create_for_test("//:py3", "==3.6.*"), MockFieldSet.create_for_test("//:py3_second", "==3.6.*"), ] no_constraints_fs = MockFieldSet.create_for_test("//:no_constraints", None) assert PexInterpreterConstraints.group_field_sets_by_constraints( [py2_fs, *py3_fs, no_constraints_fs], python_setup=create_subsystem(PythonSetup, interpreter_constraints=[]), ) == FrozenDict({ PexInterpreterConstraints(): (no_constraints_fs, ), PexInterpreterConstraints(["CPython>=2.7,<3"]): (py2_fs, ), PexInterpreterConstraints(["CPython==3.6.*"]): tuple(py3_fs), })
async def flake8_lint(request: Flake8Request, flake8: Flake8, python_setup: PythonSetup) -> LintResults: if flake8.options.skip: return LintResults() # NB: Flake8 output depends upon which Python interpreter version it's run with # (http://flake8.pycqa.org/en/latest/user/invocation.html). We batch targets by their # constraints to ensure, for example, that all Python 2 targets run together and all Python 3 # targets run together. constraints_to_field_sets = PexInterpreterConstraints.group_field_sets_by_constraints( request.field_sets, python_setup) partitioned_results = await MultiGet( Get[LintResult](Flake8Partition(partition_field_sets, partition_compatibility)) for partition_compatibility, partition_field_sets in constraints_to_field_sets.items()) return LintResults(partitioned_results)
async def bandit_lint(request: BanditRequest, bandit: Bandit, python_setup: PythonSetup) -> LintResults: if bandit.skip: return LintResults() # NB: Bandit output depends upon which Python interpreter version it's run with # ( https://github.com/PyCQA/bandit#under-which-version-of-python-should-i-install-bandit). We # batch targets by their constraints to ensure, for example, that all Python 2 targets run # together and all Python 3 targets run together. constraints_to_field_sets = PexInterpreterConstraints.group_field_sets_by_constraints( request.field_sets, python_setup) partitioned_results = await MultiGet( Get(LintResult, BanditPartition(partition_field_sets, partition_compatibility)) for partition_compatibility, partition_field_sets in constraints_to_field_sets.items()) return LintResults(partitioned_results)