Skip to content

Commit

Permalink
Move to Ruff for formatting (microsoft#23060)
Browse files Browse the repository at this point in the history
Also set the line length to 100.
  • Loading branch information
brettcannon authored and anthonykim1 committed Mar 14, 2024
1 parent 9f0074b commit 10a57d0
Show file tree
Hide file tree
Showing 40 changed files with 162 additions and 438 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Expand Up @@ -9,13 +9,12 @@
"customizations": {
"vscode": {
"extensions": [
"charliermarsh.ruff",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"ms-python.python",
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"ms-python.debugpy"
]
}
Expand Down
9 changes: 1 addition & 8 deletions .github/actions/lint/action.yml
Expand Up @@ -41,17 +41,10 @@ runs:
python-version: '3.x'
cache: 'pip'

- name: Check Python format
run: |
python -m pip install -U black ruff
python -m ruff check
python -m black . --check
working-directory: python_files
shell: bash

- name: Run Ruff
run: |
python -m pip install -U ruff
python -m ruff check .
python -m ruff format --check
working-directory: python_files
shell: bash
6 changes: 2 additions & 4 deletions .vscode/extensions.json
Expand Up @@ -2,13 +2,11 @@
// See https://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"charliermarsh.ruff",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"ms-python.python",
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.flake8"
"ms-python.vscode-pylance"
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Expand Up @@ -28,7 +28,7 @@
"source.fixAll.eslint": "explicit",
"source.organizeImports.isort": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
6 changes: 1 addition & 5 deletions python_files/linter.py
Expand Up @@ -37,11 +37,7 @@ def main():
invoke = sys.argv[1]
if invoke == "-m":
linter = sys.argv[2]
args = (
[sys.executable, "-m", linter]
+ linter_settings[linter]["args"]
+ sys.argv[3:]
)
args = [sys.executable, "-m", linter] + linter_settings[linter]["args"] + sys.argv[3:]
else:
linter = sys.argv[2]
args = [sys.argv[3]] + linter_settings[linter]["args"] + sys.argv[4:]
Expand Down
8 changes: 2 additions & 6 deletions python_files/normalizeSelection.py
Expand Up @@ -191,9 +191,7 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted):
ast.IfExp,
ast.ExceptHandler,
)
if isinstance(node, ast_types_with_nodebody) and isinstance(
node.body, Iterable
):
if isinstance(node, ast_types_with_nodebody) and isinstance(node.body, Iterable):
for child_nodes in node.body:
top_level_nodes.append(child_nodes)

Expand All @@ -204,9 +202,7 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted):
which_line_next = 0
for same_line_node in exact_nodes:
should_run_top_blocks.append(same_line_node)
smart_code += (
f"{ast.get_source_segment(wholeFileContent, same_line_node)}\n"
)
smart_code += f"{ast.get_source_segment(wholeFileContent, same_line_node)}\n"
which_line_next = get_next_block_lineno(should_run_top_blocks)
return {
"normalized_smart_result": smart_code,
Expand Down
10 changes: 8 additions & 2 deletions python_files/pyproject.toml
Expand Up @@ -36,8 +36,14 @@ ignore = [
]

[tool.ruff]
line-length = 140
exclude = ["tests/testing_tools/adapter/.data"]
line-length = 100
exclude = [
"tests/testing_tools/adapter/.data",
"tests/unittestadapter/.data"
]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint.pydocstyle]
convention = "pep257"
4 changes: 1 addition & 3 deletions python_files/testing_tools/adapter/__main__.py
Expand Up @@ -50,9 +50,7 @@ def parse_args(
subsub = add_subparser(cmdname, toolname, subsubs)
if cmdname == "discover":
subsub.add_argument("--simple", action="store_true")
subsub.add_argument(
"--no-hide-stdio", dest="hidestdio", action="store_false"
)
subsub.add_argument("--no-hide-stdio", dest="hidestdio", action="store_false")
subsub.add_argument("--pretty", action="store_true")

# Parse the args!
Expand Down
4 changes: 1 addition & 3 deletions python_files/testing_tools/adapter/info.py
Expand Up @@ -61,9 +61,7 @@ def __init__(self, *args, **kwargs):
raise TypeError("missing relpath")


class SingleTestInfo(
namedtuple("TestInfo", "id name path source markers parentid kind")
):
class SingleTestInfo(namedtuple("TestInfo", "id name path source markers parentid kind")):
"""Info for a single test."""

MARKERS = ("skip", "skip-if", "expected-failure")
Expand Down
2 changes: 1 addition & 1 deletion python_files/testing_tools/adapter/pytest/_discovery.py
Expand Up @@ -17,7 +17,7 @@ def discover(
# *,
_pytest_main=pytest.main,
_plugin=None,
**_ignored
**_ignored,
):
"""Return the results of test discovery."""
if _plugin is None:
Expand Down
4 changes: 1 addition & 3 deletions python_files/testing_tools/adapter/pytest/_pytest_item.py
Expand Up @@ -170,9 +170,7 @@ def parse_item(
parents = [(parentid, item.originalname, kind)] + parents
name = parameterized[1:-1] or "<empty>"
else:
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
item.nodeid, kind
)
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(item.nodeid, kind)
name = item.name

# Note: testfunc does not necessarily match item.function.__name__.
Expand Down
2 changes: 1 addition & 1 deletion python_files/testing_tools/adapter/report.py
Expand Up @@ -13,7 +13,7 @@ def report_discovered(
pretty=False,
simple=False,
_send=print,
**_ignored
**_ignored,
):
"""Serialize the discovered tests and write to stdout."""
if simple:
Expand Down
4 changes: 2 additions & 2 deletions python_files/testing_tools/adapter/util.py
Expand Up @@ -128,7 +128,7 @@ def fix_fileid(
normalize=False,
strictpathsep=None,
_pathsep=PATH_SEP,
**kwargs
**kwargs,
):
"""Return a pathsep-separated file ID ("./"-prefixed) for the given value.
Expand All @@ -150,7 +150,7 @@ def fix_fileid(
rootdir,
_pathsep=_pathsep,
# ...
**kwargs
**kwargs,
)
if relpath: # Note that we treat "" here as an absolute path.
_fileid = "./" + relpath
Expand Down
4 changes: 1 addition & 3 deletions python_files/testing_tools/socket_manager.py
Expand Up @@ -29,9 +29,7 @@ def __exit__(self, *_):
self.close()

def connect(self):
self.socket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP
)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
if sys.platform == "win32":
addr_use = socket.SO_EXCLUSIVEADDRUSE
else:
Expand Down
4 changes: 1 addition & 3 deletions python_files/tests/__main__.py
Expand Up @@ -12,9 +12,7 @@
def parse_args():
parser = argparse.ArgumentParser()
# To mark a test as functional: (decorator) @pytest.mark.functional
parser.add_argument(
"--functional", dest="markers", action="append_const", const="functional"
)
parser.add_argument("--functional", dest="markers", action="append_const", const="functional")
parser.add_argument(
"--no-functional", dest="markers", action="append_const", const="not functional"
)
Expand Down
8 changes: 2 additions & 6 deletions python_files/tests/debug_adapter/test_install_debugpy.py
Expand Up @@ -18,12 +18,8 @@ def test_install_debugpy(tmpdir):
import install_debugpy

install_debugpy.main(str(tmpdir))
dir_path = os.path.join(
str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_bundle"
)
dir_path = os.path.join(str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_bundle")
_check_binaries(dir_path)

dir_path = os.path.join(
str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_frame_eval"
)
dir_path = os.path.join(str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_frame_eval")
_check_binaries(dir_path)
37 changes: 9 additions & 28 deletions python_files/tests/pytestadapter/expected_discovery_test_output.py
Expand Up @@ -322,19 +322,12 @@
# └── test_bottom_function_t
# └── test_bottom_function_f
dual_level_nested_folder_path = TEST_DATA_PATH / "dual_level_nested_folder"
test_top_folder_path = (
TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py"
)
test_top_folder_path = TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py"

test_nested_folder_one_path = (
TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one"
)
test_nested_folder_one_path = TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one"

test_bottom_folder_path = (
TEST_DATA_PATH
/ "dual_level_nested_folder"
/ "nested_folder_one"
/ "test_bottom_folder.py"
TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one" / "test_bottom_folder.py"
)


Expand Down Expand Up @@ -851,12 +844,8 @@
os.path.join(tests_path, "test_a.py"),
),
"type_": "test",
"id_": get_absolute_test_id(
"tests/test_a.py::test_a_function", tests_a_path
),
"runID": get_absolute_test_id(
"tests/test_a.py::test_a_function", tests_a_path
),
"id_": get_absolute_test_id("tests/test_a.py::test_a_function", tests_a_path),
"runID": get_absolute_test_id("tests/test_a.py::test_a_function", tests_a_path),
}
],
},
Expand All @@ -874,12 +863,8 @@
os.path.join(tests_path, "test_b.py"),
),
"type_": "test",
"id_": get_absolute_test_id(
"tests/test_b.py::test_b_function", tests_b_path
),
"runID": get_absolute_test_id(
"tests/test_b.py::test_b_function", tests_b_path
),
"id_": get_absolute_test_id("tests/test_b.py::test_b_function", tests_b_path),
"runID": get_absolute_test_id("tests/test_b.py::test_b_function", tests_b_path),
}
],
},
Expand Down Expand Up @@ -996,12 +981,8 @@
}
SYMLINK_FOLDER_PATH = TEST_DATA_PATH / "symlink_folder"
SYMLINK_FOLDER_PATH_TESTS = TEST_DATA_PATH / "symlink_folder" / "tests"
SYMLINK_FOLDER_PATH_TESTS_TEST_A = (
TEST_DATA_PATH / "symlink_folder" / "tests" / "test_a.py"
)
SYMLINK_FOLDER_PATH_TESTS_TEST_B = (
TEST_DATA_PATH / "symlink_folder" / "tests" / "test_b.py"
)
SYMLINK_FOLDER_PATH_TESTS_TEST_A = TEST_DATA_PATH / "symlink_folder" / "tests" / "test_a.py"
SYMLINK_FOLDER_PATH_TESTS_TEST_B = TEST_DATA_PATH / "symlink_folder" / "tests" / "test_b.py"

symlink_expected_discovery_output = {
"name": "symlink_folder",
Expand Down

0 comments on commit 10a57d0

Please sign in to comment.