Skip to content

Commit f4ff2cb

Browse files
add ruff to tox (#30858)
* add ruff to tox/weekly ci, no configuration * add ruff.toml and set max line length to match pylintrc * py37
1 parent 5e5b30a commit f4ff2cb

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

eng/pipelines/templates/stages/archetype-sdk-tests.yml

+13
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,16 @@ stages:
208208
--service="${{ parameters.ServiceDirectory }}"
209209
--toxenv="next-pyright"
210210
--disablecov
211+
212+
- task: PythonScript@0
213+
displayName: 'Run Ruff'
214+
continueOnError: true
215+
inputs:
216+
scriptPath: 'scripts/devops_tasks/setup_execute_tests.py'
217+
arguments: >-
218+
"azure*"
219+
--mark_arg="${{ parameters.TestMarkArgument }}"
220+
--service="${{ parameters.ServiceDirectory }}"
221+
--toxenv="ruff"
222+
--disablecov
223+
env: ${{ parameters.EnvVars }}

eng/tox/run_ruff.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
# This script is used to execute ruff within a tox environment.
7+
8+
import subprocess
9+
import argparse
10+
import os
11+
import sys
12+
from ci_tools.parsing import ParsedSetup
13+
14+
15+
if __name__ == "__main__":
16+
parser = argparse.ArgumentParser(
17+
description="Run ruff against target folder."
18+
)
19+
20+
parser.add_argument(
21+
"-t",
22+
"--target",
23+
dest="target_package",
24+
help="The target package directory on disk. The target module passed to ruff will be <target_package>/azure.",
25+
required=True,
26+
)
27+
28+
args = parser.parse_args()
29+
30+
pkg_dir = os.path.abspath(args.target_package)
31+
pkg_details = ParsedSetup.from_path(pkg_dir)
32+
top_level_module = pkg_details.namespace.split('.')[0]
33+
34+
subprocess.check_call(
35+
[
36+
sys.executable,
37+
"-m",
38+
"ruff",
39+
"check",
40+
os.path.join(args.target_package, top_level_module),
41+
]
42+
)

eng/tox/tox.ini

+19
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ commands =
117117
--package-type sdist
118118
python {repository_root}/eng/tox/run_pylint.py -t {tox_root} --next=True
119119

120+
[testenv:ruff]
121+
description=Lints a package with ruff
122+
skipsdist = true
123+
skip_install = true
124+
usedevelop = false
125+
setenv =
126+
{[testenv]setenv}
127+
PROXY_URL=http://localhost:5022
128+
deps =
129+
{[base]deps}
130+
ruff
131+
commands =
132+
python {repository_root}/eng/tox/create_package_and_install.py \
133+
-d {envtmpdir}/dist \
134+
-p {tox_root} \
135+
-w {envtmpdir} \
136+
--package-type sdist
137+
python {repository_root}/eng/tox/run_ruff.py -t {tox_root}
138+
120139
[testenv:mypy]
121140
description=Typechecks a package with mypy (version {[testenv:mypy]mypy_version})
122141
mypy_version=1.0.0

ruff.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
line-length = 120
2+
target-version = "py37"

0 commit comments

Comments
 (0)