-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc70792
commit b3c39f2
Showing
10 changed files
with
640 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
resource(name="lockfile", source="ruff.lock") | ||
|
||
python_sources( | ||
overrides={"subsystem.py": {"dependencies": [":lockfile"]}}, | ||
) | ||
|
||
python_tests( | ||
name="tests", | ||
overrides={ | ||
"rules_integration_test.py": { | ||
"timeout": 330, | ||
"tags": ["platform_specific_behavior"], | ||
}, | ||
}, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Iterable | ||
|
||
from pants.engine.rules import Rule | ||
from pants.engine.unions import UnionRule | ||
|
||
from .rules import rules as ruff_rules | ||
|
||
|
||
def rules() -> Iterable[Rule | UnionRule]: | ||
return (*ruff_rules(),) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// This lockfile was autogenerated by Pants. To regenerate, run: | ||
// | ||
// ./pants run build-support/bin/generate_builtin_lockfiles.py | ||
// | ||
// --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- | ||
// { | ||
// "version": 3, | ||
// "valid_for_interpreter_constraints": [ | ||
// "CPython<4,>=3.7" | ||
// ], | ||
// "generated_with_requirements": [ | ||
// "ruff<1,>=0.1.2" | ||
// ], | ||
// "manylinux": "manylinux2014", | ||
// "requirement_constraints": [], | ||
// "only_binary": [], | ||
// "no_binary": [] | ||
// } | ||
// --- END PANTS LOCKFILE METADATA --- | ||
|
||
{ | ||
"allow_builds": true, | ||
"allow_prereleases": false, | ||
"allow_wheels": true, | ||
"build_isolation": true, | ||
"constraints": [], | ||
"locked_resolves": [ | ||
{ | ||
"locked_requirements": [ | ||
{ | ||
"artifacts": [ | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "ea284789861b8b5ca9d5443591a92a397ac183d4351882ab52f6296b4fdd5462", | ||
"url": "https://files.pythonhosted.org/packages/11/02/3a7e3101d88b113f326e0fdf3f566fba2600fc4b1fd828d56027d293e22d/ruff-0.1.6-py3-none-musllinux_1_2_x86_64.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "bd98138a98d48a1c36c394fd6b84cd943ac92a08278aa8ac8c0fdefcf7138f35", | ||
"url": "https://files.pythonhosted.org/packages/09/92/36850598e84f75cfe8edd252dbf40442b4cc226ed2c76206a9b3cbfb9986/ruff-0.1.6-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "1b09f29b16c6ead5ea6b097ef2764b42372aebe363722f1605ecbcd2b9207184", | ||
"url": "https://files.pythonhosted.org/packages/25/4c/2f786388acd82c295eedc4afeede7ef4b29cf27277151d8d13be906bac70/ruff-0.1.6.tar.gz" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "3a0cd909d25f227ac5c36d4e7e681577275fb74ba3b11d288aff7ec47e3ae745", | ||
"url": "https://files.pythonhosted.org/packages/3b/2f/8ef67614631622aa3ea79b27e01ac86d7f90a988520454e3a84cb2fd890f/ruff-0.1.6-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "e8fd1c62a47aa88a02707b5dd20c5ff20d035d634aa74826b42a1da77861b5ff", | ||
"url": "https://files.pythonhosted.org/packages/3c/4b/af366db98d15efe83fd3e3aae7319d3897e3475fc53a2f1b0287c8255422/ruff-0.1.6-py3-none-musllinux_1_2_aarch64.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "491262006e92f825b145cd1e52948073c56560243b55fb3b4ecb142f6f0e9543", | ||
"url": "https://files.pythonhosted.org/packages/81/b0/92c4cb6bceb19ebd27cedd1f45b337f7fd5397e6b760094831266be59661/ruff-0.1.6-py3-none-musllinux_1_2_i686.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "05991ee20d4ac4bb78385360c684e4b417edd971030ab12a4fbd075ff535050e", | ||
"url": "https://files.pythonhosted.org/packages/92/7c/38fd1b9cb624f5725a6a08c81bf7e823c64b28622ffcb4369c56dc0a16d0/ruff-0.1.6-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "5c549ed437680b6105a1299d2cd30e4964211606eeb48a0ff7a93ef70b902248", | ||
"url": "https://files.pythonhosted.org/packages/a2/91/8b2920f6026c069ae0802fc3c44f7337e04bf2a198ce94bfab360073477a/ruff-0.1.6-py3-none-macosx_10_12_x86_64.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "88b8cdf6abf98130991cbc9f6438f35f6e8d41a02622cc5ee130a02a0ed28703", | ||
"url": "https://files.pythonhosted.org/packages/b6/75/5054ec93ec0d5db26e218cb2814ddaa085ba1f29fad0ec56dd8107a97688/ruff-0.1.6-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "fd89b45d374935829134a082617954120d7a1470a9f0ec0e7f3ead983edc48cc", | ||
"url": "https://files.pythonhosted.org/packages/bf/af/25b794e750f1d74a83ce6b16625e3306beeb2161c517b9d883958de05526/ruff-0.1.6-py3-none-musllinux_1_2_armv7l.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "87455a0c1f739b3c069e2f4c43b66479a54dea0276dd5d4d67b091265f6fd1dc", | ||
"url": "https://files.pythonhosted.org/packages/c7/c3/98e3d0eb92e5a2ec10f76c71067640b6f21def23c3b1ff8f08ab6348255e/ruff-0.1.6-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "137852105586dcbf80c1717facb6781555c4e99f520c9c827bd414fac67ddfb6", | ||
"url": "https://files.pythonhosted.org/packages/c7/f1/60d43182f98113156a1b21a17f30541dda9f5ffcfeedc2b54dc030a2c413/ruff-0.1.6-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "1cf5f701062e294f2167e66d11b092bba7af6a057668ed618a9253e1e90cfd76", | ||
"url": "https://files.pythonhosted.org/packages/df/1e/03ef0cc5c7d03e50d4f954218551d6001f1f70e6f391cdb678efb5c6e6ab/ruff-0.1.6-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl" | ||
}, | ||
{ | ||
"algorithm": "sha256", | ||
"hash": "683aa5bdda5a48cb8266fcde8eea2a6af4e5700a392c56ea5fb5f0d4bfdc0240", | ||
"url": "https://files.pythonhosted.org/packages/e8/33/62fb966eb70d9bb45ddf5023d40e26946a5e5127d99956b84c8a9a76b153/ruff-0.1.6-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl" | ||
} | ||
], | ||
"project_name": "ruff", | ||
"requires_dists": [], | ||
"requires_python": ">=3.7", | ||
"version": "0.1.6" | ||
} | ||
], | ||
"platform_tag": null | ||
} | ||
], | ||
"path_mappings": {}, | ||
"pex_version": "2.1.152", | ||
"pip_version": "23.3.1", | ||
"prefer_older_binary": false, | ||
"requirements": [ | ||
"ruff<1,>=0.1.2" | ||
], | ||
"requires_python": [ | ||
"<4,>=3.7" | ||
], | ||
"resolver_version": "pip-2020-resolver", | ||
"style": "universal", | ||
"target_systems": [ | ||
"linux", | ||
"mac" | ||
], | ||
"transitive": true, | ||
"use_pep517": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Any, Tuple | ||
|
||
from pants.backend.python.util_rules import pex | ||
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess | ||
from pants.core.goals.fix import FixResult, FixTargetsRequest | ||
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest | ||
from pants.core.goals.lint import LintResult, LintTargetsRequest | ||
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest | ||
from pants.core.util_rules.partitions import PartitionerType | ||
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest | ||
from pants.engine.fs import Digest, MergeDigests | ||
from pants.engine.internals.native_engine import Snapshot | ||
from pants.engine.process import FallibleProcessResult | ||
from pants.engine.rules import Get, MultiGet, collect_rules, rule | ||
from pants.util.logging import LogLevel | ||
from pants.util.meta import classproperty | ||
from pants.util.strutil import pluralize | ||
|
||
from .subsystem import Ruff, RuffFieldSet, RuffMode | ||
|
||
|
||
class RuffFixRequest(FixTargetsRequest): | ||
field_set_type = RuffFieldSet | ||
tool_subsystem = Ruff | ||
partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION | ||
|
||
@classproperty | ||
def tool_name(cls) -> str: | ||
return "ruff --fix" | ||
|
||
|
||
class RuffLintRequest(LintTargetsRequest): | ||
field_set_type = RuffFieldSet | ||
tool_subsystem = Ruff | ||
partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION | ||
|
||
|
||
class RuffFormatRequest(FmtTargetsRequest): | ||
field_set_type = RuffFieldSet | ||
tool_subsystem = Ruff | ||
partitioner_type = PartitionerType.DEFAULT_SINGLE_PARTITION | ||
|
||
|
||
@dataclass(frozen=True) | ||
class _RunRuffRequest: | ||
snapshot: Snapshot | ||
mode: RuffMode | ||
|
||
|
||
@rule(level=LogLevel.DEBUG) | ||
async def run_ruff( | ||
request: _RunRuffRequest, | ||
ruff: Ruff, | ||
) -> FallibleProcessResult: | ||
ruff_pex_get = Get(VenvPex, PexRequest, ruff.to_pex_request()) | ||
|
||
config_files_get = Get( | ||
ConfigFiles, ConfigFilesRequest, ruff.config_request(request.snapshot.dirs) | ||
) | ||
|
||
ruff_pex, config_files = await MultiGet(ruff_pex_get, config_files_get) | ||
|
||
input_digest = await Get( | ||
Digest, | ||
MergeDigests((request.snapshot.digest, config_files.snapshot.digest)), | ||
) | ||
|
||
conf_args = [f"--config={ruff.config}"] if ruff.config else [] | ||
|
||
extra_initial_args: Tuple[str, ...] = ("check",) | ||
if request.mode == RuffMode.FORMAT: | ||
extra_initial_args = ("format",) | ||
elif request.mode == RuffMode.FIX: | ||
extra_initial_args = ( | ||
"check", | ||
"--fix", | ||
) | ||
|
||
# `--force-exclude` applies file excludes from config to files provided explicitly | ||
# The format argument must be passed before force-exclude if Ruff is used for formatting. | ||
# For other cases, the flags should work the same regardless of the order. | ||
initial_args = extra_initial_args + ("--force-exclude",) | ||
|
||
result = await Get( | ||
FallibleProcessResult, | ||
VenvPexProcess( | ||
ruff_pex, | ||
argv=(*initial_args, *conf_args, *ruff.args, *request.snapshot.files), | ||
input_digest=input_digest, | ||
output_files=request.snapshot.files, | ||
description=f"Run ruff {' '.join(initial_args)} on {pluralize(len(request.snapshot.files), 'file')}.", | ||
level=LogLevel.DEBUG, | ||
), | ||
) | ||
return result | ||
|
||
|
||
@rule(desc="Fix with ruff", level=LogLevel.DEBUG) | ||
async def ruff_fix(request: RuffFixRequest.Batch, ruff: Ruff) -> FixResult: | ||
result = await Get( | ||
FallibleProcessResult, _RunRuffRequest(snapshot=request.snapshot, mode=RuffMode.FIX) | ||
) | ||
return await FixResult.create(request, result) | ||
|
||
|
||
@rule(desc="Lint with ruff", level=LogLevel.DEBUG) | ||
async def ruff_lint(request: RuffLintRequest.Batch[RuffFieldSet, Any]) -> LintResult: | ||
source_files = await Get( | ||
SourceFiles, SourceFilesRequest(field_set.source for field_set in request.elements) | ||
) | ||
result = await Get( | ||
FallibleProcessResult, _RunRuffRequest(snapshot=source_files.snapshot, mode=RuffMode.LINT) | ||
) | ||
return LintResult.create(request, result) | ||
|
||
|
||
@rule(desc="Format with ruff", level=LogLevel.DEBUG) | ||
async def ruff_fmt(request: RuffFormatRequest.Batch, ruff: Ruff) -> FmtResult: | ||
result = await Get( | ||
FallibleProcessResult, _RunRuffRequest(snapshot=request.snapshot, mode=RuffMode.FORMAT) | ||
) | ||
return await FmtResult.create(request, result) | ||
|
||
|
||
def rules(): | ||
return [ | ||
*collect_rules(), | ||
*RuffFixRequest.rules(), | ||
*RuffLintRequest.rules(), | ||
*RuffFormatRequest.rules(), | ||
*pex.rules(), | ||
] |
Oops, something went wrong.