Пример #1
0
def run_black_and_isort(
        rule_runner: RuleRunner,
        targets: list[Target],
        *,
        extra_args: list[str] | None = None) -> LanguageFmtResults:
    fmt_targets = PythonFmtTargets(Targets(targets))
    rule_runner.set_options(
        [
            "--backend-packages=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']",
            *(extra_args or []),
        ],
        # We propagate LANG and LC_ALL to satisfy click, which black depends upon. Without this we
        # see something like the following in CI:
        #
        # RuntimeError: Click will abort further execution because Python was configured to use
        # ASCII as encoding for the environment. Consult
        # https://click.palletsprojects.com/unicode-support/ for mitigation steps.
        #
        # This system supports the C.UTF-8 locale which is recommended. You might be able to
        # resolve your issue by exporting the following environment variables:
        #
        #     export LC_ALL=C.UTF-8
        #     export LANG=C.UTF-8
        #
        env_inherit={"PATH", "PYENV_ROOT", "HOME", "LANG", "LC_ALL"},
    )
    return rule_runner.request(LanguageFmtResults, [fmt_targets])
Пример #2
0
def run_black_and_isort(
        rule_runner: RuleRunner,
        targets: list[Target],
        *,
        extra_args: list[str] | None = None) -> LanguageFmtResults:
    fmt_targets = PythonFmtTargets(Targets(targets))
    rule_runner.set_options(
        [
            "--backend-packages=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']",
            *(extra_args or []),
        ],
        env_inherit={"PATH", "PYENV_ROOT", "HOME"},
    )
    return rule_runner.request(LanguageFmtResults, [fmt_targets])
Пример #3
0
 def run_black_and_isort(
     self, source_files: List[FileContent], *, name: str, extra_args: Optional[List[str]] = None
 ) -> LanguageFmtResults:
     for source_file in source_files:
         self.create_file(source_file.path, source_file.content.decode())
     target = PythonLibrary({}, address=Address.parse(f"test:{name}"))
     origin = SingleAddress(directory="test", name=name)
     targets = PythonFmtTargets(TargetsWithOrigins([TargetWithOrigin(target, origin)]))
     args = [
         "--backend-packages2=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']",
         *(extra_args or []),
     ]
     results = self.request_single_product(
         LanguageFmtResults, Params(targets, create_options_bootstrapper(args=args)),
     )
     return results
def run_black_and_isort(
    rule_runner: RuleRunner,
    source_files: List[FileContent],
    *,
    name: str,
    extra_args: Optional[List[str]] = None,
) -> LanguageFmtResults:
    for source_file in source_files:
        rule_runner.create_file(source_file.path, source_file.content.decode())
    targets = PythonFmtTargets(Targets([PythonLibrary({}, address=Address.parse(f"test:{name}"))]))
    rule_runner.set_options(
        [
            "--backend-packages=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']",
            *(extra_args or []),
        ]
    )
    results = rule_runner.request(LanguageFmtResults, [targets])
    return results
Пример #5
0
 def run_black_and_isort(
         self,
         source_files: List[FileContent],
         *,
         name: str,
         extra_args: Optional[List[str]] = None) -> LanguageFmtResults:
     for source_file in source_files:
         self.create_file(source_file.path, source_file.content.decode())
     targets = PythonFmtTargets(
         Targets([PythonLibrary({},
                                address=Address.parse(f"test:{name}"))]))
     args = [
         "--backend-packages=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']",
         *(extra_args or []),
     ]
     results = self.request_product(
         LanguageFmtResults,
         [targets, create_options_bootstrapper(args=args)])
     return results