Skip to content

Commit 8497986

Browse files
brettcannonwesm
authored andcommitted
Move to Ruff for formatting (microsoft/vscode-python#23060)
Also set the line length to 100.
1 parent 2280133 commit 8497986

39 files changed

+160
-432
lines changed

extensions/positron-python/.devcontainer/devcontainer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
"customizations": {
1010
"vscode": {
1111
"extensions": [
12+
"charliermarsh.ruff",
1213
"editorconfig.editorconfig",
1314
"esbenp.prettier-vscode",
1415
"dbaeumer.vscode-eslint",
1516
"ms-python.python",
16-
"ms-python.black-formatter",
1717
"ms-python.vscode-pylance",
18-
"charliermarsh.ruff",
1918
"ms-python.debugpy"
2019
]
2120
}

extensions/positron-python/.github/actions/lint/action.yml

+1-8
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,10 @@ runs:
4141
python-version: '3.x'
4242
cache: 'pip'
4343

44-
- name: Check Python format
45-
run: |
46-
python -m pip install -U black ruff
47-
python -m ruff check
48-
python -m black . --check
49-
working-directory: python_files
50-
shell: bash
51-
5244
- name: Run Ruff
5345
run: |
5446
python -m pip install -U ruff
5547
python -m ruff check .
48+
python -m ruff format --check
5649
working-directory: python_files
5750
shell: bash

extensions/positron-python/.vscode/extensions.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// See https://go.microsoft.com/fwlink/?LinkId=827846
33
// for the documentation about the extensions.json format
44
"recommendations": [
5+
"charliermarsh.ruff",
56
"editorconfig.editorconfig",
67
"esbenp.prettier-vscode",
78
"dbaeumer.vscode-eslint",
89
"ms-python.python",
9-
"ms-python.black-formatter",
10-
"ms-python.vscode-pylance",
11-
"ms-python.isort",
12-
"ms-python.flake8"
10+
"ms-python.vscode-pylance"
1311
]
1412
}

extensions/positron-python/.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"editor.codeActionsOnSave": {
2828
"source.organizeImports": "explicit"
2929
},
30-
"editor.defaultFormatter": "ms-python.black-formatter"
30+
"editor.defaultFormatter": "charliermarsh.ruff",
3131
},
3232
"[typescript]": {
3333
"editor.defaultFormatter": "esbenp.prettier-vscode",

extensions/positron-python/python_files/linter.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ def main():
3737
invoke = sys.argv[1]
3838
if invoke == "-m":
3939
linter = sys.argv[2]
40-
args = (
41-
[sys.executable, "-m", linter]
42-
+ linter_settings[linter]["args"]
43-
+ sys.argv[3:]
44-
)
40+
args = [sys.executable, "-m", linter] + linter_settings[linter]["args"] + sys.argv[3:]
4541
else:
4642
linter = sys.argv[2]
4743
args = [sys.argv[3]] + linter_settings[linter]["args"] + sys.argv[4:]

extensions/positron-python/python_files/pyproject.toml

+8-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ ignore = [
5353
]
5454

5555
[tool.ruff]
56-
line-length = 140
57-
exclude = ["tests/testing_tools/adapter/.data"]
56+
line-length = 100
57+
exclude = [
58+
"tests/testing_tools/adapter/.data",
59+
"tests/unittestadapter/.data"
60+
]
61+
62+
[tool.ruff.format]
63+
docstring-code-format = true
5864

5965
[tool.ruff.lint.pydocstyle]
6066
convention = "pep257"

extensions/positron-python/python_files/testing_tools/adapter/__main__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def parse_args(
5050
subsub = add_subparser(cmdname, toolname, subsubs)
5151
if cmdname == "discover":
5252
subsub.add_argument("--simple", action="store_true")
53-
subsub.add_argument(
54-
"--no-hide-stdio", dest="hidestdio", action="store_false"
55-
)
53+
subsub.add_argument("--no-hide-stdio", dest="hidestdio", action="store_false")
5654
subsub.add_argument("--pretty", action="store_true")
5755

5856
# Parse the args!

extensions/positron-python/python_files/testing_tools/adapter/info.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def __init__(self, *args, **kwargs):
6161
raise TypeError("missing relpath")
6262

6363

64-
class SingleTestInfo(
65-
namedtuple("TestInfo", "id name path source markers parentid kind")
66-
):
64+
class SingleTestInfo(namedtuple("TestInfo", "id name path source markers parentid kind")):
6765
"""Info for a single test."""
6866

6967
MARKERS = ("skip", "skip-if", "expected-failure")

extensions/positron-python/python_files/testing_tools/adapter/pytest/_discovery.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def discover(
1717
# *,
1818
_pytest_main=pytest.main,
1919
_plugin=None,
20-
**_ignored
20+
**_ignored,
2121
):
2222
"""Return the results of test discovery."""
2323
if _plugin is None:

extensions/positron-python/python_files/testing_tools/adapter/pytest/_pytest_item.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def parse_item(
170170
parents = [(parentid, item.originalname, kind)] + parents
171171
name = parameterized[1:-1] or "<empty>"
172172
else:
173-
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
174-
item.nodeid, kind
175-
)
173+
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(item.nodeid, kind)
176174
name = item.name
177175

178176
# Note: testfunc does not necessarily match item.function.__name__.

extensions/positron-python/python_files/testing_tools/adapter/report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def report_discovered(
1313
pretty=False,
1414
simple=False,
1515
_send=print,
16-
**_ignored
16+
**_ignored,
1717
):
1818
"""Serialize the discovered tests and write to stdout."""
1919
if simple:

extensions/positron-python/python_files/testing_tools/adapter/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def fix_fileid(
128128
normalize=False,
129129
strictpathsep=None,
130130
_pathsep=PATH_SEP,
131-
**kwargs
131+
**kwargs,
132132
):
133133
"""Return a pathsep-separated file ID ("./"-prefixed) for the given value.
134134
@@ -150,7 +150,7 @@ def fix_fileid(
150150
rootdir,
151151
_pathsep=_pathsep,
152152
# ...
153-
**kwargs
153+
**kwargs,
154154
)
155155
if relpath: # Note that we treat "" here as an absolute path.
156156
_fileid = "./" + relpath

extensions/positron-python/python_files/testing_tools/socket_manager.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def __exit__(self, *_):
2929
self.close()
3030

3131
def connect(self):
32-
self.socket = socket.socket(
33-
socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP
34-
)
32+
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
3533
if sys.platform == "win32":
3634
addr_use = socket.SO_EXCLUSIVEADDRUSE
3735
else:

extensions/positron-python/python_files/tests/__main__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
def parse_args():
1313
parser = argparse.ArgumentParser()
1414
# To mark a test as functional: (decorator) @pytest.mark.functional
15-
parser.add_argument(
16-
"--functional", dest="markers", action="append_const", const="functional"
17-
)
15+
parser.add_argument("--functional", dest="markers", action="append_const", const="functional")
1816
parser.add_argument(
1917
"--no-functional", dest="markers", action="append_const", const="not functional"
2018
)

extensions/positron-python/python_files/tests/debug_adapter/test_install_debugpy.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ def test_install_debugpy(tmpdir):
1818
import install_debugpy
1919

2020
install_debugpy.main(str(tmpdir))
21-
dir_path = os.path.join(
22-
str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_bundle"
23-
)
21+
dir_path = os.path.join(str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_bundle")
2422
_check_binaries(dir_path)
2523

26-
dir_path = os.path.join(
27-
str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_frame_eval"
28-
)
24+
dir_path = os.path.join(str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_frame_eval")
2925
_check_binaries(dir_path)

extensions/positron-python/python_files/tests/pytestadapter/expected_discovery_test_output.py

+9-28
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,12 @@
322322
# └── test_bottom_function_t
323323
# └── test_bottom_function_f
324324
dual_level_nested_folder_path = TEST_DATA_PATH / "dual_level_nested_folder"
325-
test_top_folder_path = (
326-
TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py"
327-
)
325+
test_top_folder_path = TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py"
328326

329-
test_nested_folder_one_path = (
330-
TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one"
331-
)
327+
test_nested_folder_one_path = TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one"
332328

333329
test_bottom_folder_path = (
334-
TEST_DATA_PATH
335-
/ "dual_level_nested_folder"
336-
/ "nested_folder_one"
337-
/ "test_bottom_folder.py"
330+
TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one" / "test_bottom_folder.py"
338331
)
339332

340333

@@ -851,12 +844,8 @@
851844
os.path.join(tests_path, "test_a.py"),
852845
),
853846
"type_": "test",
854-
"id_": get_absolute_test_id(
855-
"tests/test_a.py::test_a_function", tests_a_path
856-
),
857-
"runID": get_absolute_test_id(
858-
"tests/test_a.py::test_a_function", tests_a_path
859-
),
847+
"id_": get_absolute_test_id("tests/test_a.py::test_a_function", tests_a_path),
848+
"runID": get_absolute_test_id("tests/test_a.py::test_a_function", tests_a_path),
860849
}
861850
],
862851
},
@@ -874,12 +863,8 @@
874863
os.path.join(tests_path, "test_b.py"),
875864
),
876865
"type_": "test",
877-
"id_": get_absolute_test_id(
878-
"tests/test_b.py::test_b_function", tests_b_path
879-
),
880-
"runID": get_absolute_test_id(
881-
"tests/test_b.py::test_b_function", tests_b_path
882-
),
866+
"id_": get_absolute_test_id("tests/test_b.py::test_b_function", tests_b_path),
867+
"runID": get_absolute_test_id("tests/test_b.py::test_b_function", tests_b_path),
883868
}
884869
],
885870
},
@@ -996,12 +981,8 @@
996981
}
997982
SYMLINK_FOLDER_PATH = TEST_DATA_PATH / "symlink_folder"
998983
SYMLINK_FOLDER_PATH_TESTS = TEST_DATA_PATH / "symlink_folder" / "tests"
999-
SYMLINK_FOLDER_PATH_TESTS_TEST_A = (
1000-
TEST_DATA_PATH / "symlink_folder" / "tests" / "test_a.py"
1001-
)
1002-
SYMLINK_FOLDER_PATH_TESTS_TEST_B = (
1003-
TEST_DATA_PATH / "symlink_folder" / "tests" / "test_b.py"
1004-
)
984+
SYMLINK_FOLDER_PATH_TESTS_TEST_A = TEST_DATA_PATH / "symlink_folder" / "tests" / "test_a.py"
985+
SYMLINK_FOLDER_PATH_TESTS_TEST_B = TEST_DATA_PATH / "symlink_folder" / "tests" / "test_b.py"
1005986

1006987
symlink_expected_discovery_output = {
1007988
"name": "symlink_folder",

0 commit comments

Comments
 (0)