Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
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
15 changes: 15 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Prettier
2b6a8f2d439fe9d5e66665ea46d8b690ac9b2c39
649156a09ccdc51c0d20f7cd44540f1918f9347b
4f774d94bf4fbf87bb417b2b2b8e79e334eb3536
61b179b2092050709e3c373a6738abad8ce581c4
c33617b0b98daeb4d72040b48c5850b476d6256c
db8e1e2460e9754ec0672d958789382b6d15c5aa
08bc9ad3bee5b19f02fa756fbc53ab32f1b39920
# Black
a58eeffd1b64498e2afe5f11597888dfd1c8699c
5cd8f539f4d2086b718c8f11f823c0ac12fc2c49
9ec9e9eaebb25adc6d942ac19d4d6c128abb987f
c4af91e090057d20d7a633b3afa45eaa13ece76f
# Ruff
e931bed3efbede7b05113316506958ecd7506777
8 changes: 1 addition & 7 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ runs:
python-version: '3.x'
cache: 'pip'

- name: Check Python format
run: |
python -m pip install -U black
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"testObserver",
"quickPickItemTooltip",
"terminalDataWriteEvent",
"terminalExecuteCommandEvent"
"terminalExecuteCommandEvent",
"contribIssueReporter"
],
"author": {
"name": "Microsoft Corporation"
Expand Down Expand Up @@ -1243,6 +1244,11 @@
}
],
"menus": {
"issue/reporter": [
{
"command": "python.reportIssue"
}
],
"commandPalette": [
{
"category": "Python",
Expand Down
6 changes: 3 additions & 3 deletions python_files/installed_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
LIB_ROOT = pathlib.Path(__file__).parent / "lib" / "python"
sys.path.insert(0, os.fspath(LIB_ROOT))

import tomli
from importlib_metadata import metadata
from packaging.requirements import Requirement
import tomli # noqa: E402
from importlib_metadata import metadata # noqa: E402
from packaging.requirements import Requirement # noqa: E402

DEFAULT_SEVERITY = "3" # 'Hint'
try:
Expand Down
6 changes: 1 addition & 5 deletions python_files/linter.py
Original file line number Diff line number Diff line change
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
14 changes: 3 additions & 11 deletions python_files/normalizeSelection.py
Original file line number Diff line number Diff line change
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 Expand Up @@ -277,11 +273,7 @@ def get_next_block_lineno(which_line_next):
data = None
which_line_next = 0

if (
empty_Highlight
and contents.get("smartSendExperimentEnabled")
and contents.get("smartSendSettingsEnabled")
):
if empty_Highlight and contents.get("smartSendSettingsEnabled"):
result = traverse_file(
contents["wholeFileContent"],
vscode_start_line,
Expand Down
36 changes: 9 additions & 27 deletions python_files/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,14 @@ ignore = [
]

[tool.ruff]
line-length = 140
ignore = ["E402"]
line-length = 100
exclude = [
# Ignore testing_tools files same as Pyright way
'get-pip.py',
'install_debugpy.py',
'tensorboard_launcher.py',
'testlauncher.py',
'visualstudio_py_testlauncher.py',
'testing_tools/unittest_discovery.py',
'testing_tools/adapter/util.py',
'testing_tools/adapter/pytest/_discovery.py',
'testing_tools/adapter/pytest/_pytest_item.py',
'tests/debug_adapter/test_install_debugpy.py',
'tests/testing_tools/adapter/.data',
'tests/testing_tools/adapter/test___main__.py',
'tests/testing_tools/adapter/test_discovery.py',
'tests/testing_tools/adapter/test_functional.py',
'tests/testing_tools/adapter/test_report.py',
'tests/testing_tools/adapter/test_util.py',
'tests/testing_tools/adapter/pytest/test_cli.py',
'tests/testing_tools/adapter/pytest/test_discovery.py',
'python_files/testing_tools/*',
'python_files/testing_tools/adapter/pytest/__init__.py',
'python_files/tests/pytestadapter/expected_execution_test_output.py',
'python_files/tests/unittestadapter/.data/discovery_error/file_one.py',
'python_files/tests/unittestadapter/test_utils.py',

"tests/testing_tools/adapter/.data",
"tests/unittestadapter/.data"
]

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

[tool.ruff.lint.pydocstyle]
convention = "pep257"
4 changes: 2 additions & 2 deletions python_files/run-jedi-language-server.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sys
import os
import sys

# Add the lib path to our sys path so jedi_language_server can find its references
EXTENSION_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(EXTENSION_ROOT, "python_files", "lib", "jedilsp"))


from jedi_language_server.cli import cli
from jedi_language_server.cli import cli # noqa: E402

sys.exit(cli())
4 changes: 1 addition & 3 deletions python_files/testing_tools/adapter/__main__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
20 changes: 4 additions & 16 deletions python_files/testing_tools/adapter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ def group_attr_names(attrnames):
return grouped


if sys.version_info < (3,):
_str_to_lower = lambda val: val.decode().lower()
else:
_str_to_lower = str.lower


#############################
# file paths

Expand Down Expand Up @@ -134,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 @@ -156,15 +150,15 @@ def fix_fileid(
rootdir,
_pathsep=_pathsep,
# ...
**kwargs
**kwargs,
)
if relpath: # Note that we treat "" here as an absolute path.
_fileid = "./" + relpath

if normalize:
if strictpathsep:
raise ValueError("cannot normalize *and* keep strict path separator")
_fileid = _str_to_lower(_fileid)
_fileid = _fileid.lower()
elif strictpathsep:
# We do not use _normcase since we want to preserve capitalization.
_fileid = _fileid.replace("/", _pathsep)
Expand Down Expand Up @@ -224,12 +218,6 @@ def _replace_stderr(target):
sys.stderr = orig


if sys.version_info < (3,):
_coerce_unicode = lambda s: unicode(s)
else:
_coerce_unicode = lambda s: s


@contextlib.contextmanager
def _temp_io():
sio = StringIO()
Expand All @@ -239,7 +227,7 @@ def _temp_io():
finally:
tmp.seek(0)
buff = tmp.read()
sio.write(_coerce_unicode(buff))
sio.write(buff)


@contextlib.contextmanager
Expand Down
4 changes: 1 addition & 3 deletions python_files/testing_tools/socket_manager.py
Original file line number Diff line number Diff line change
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
13 changes: 6 additions & 7 deletions python_files/testing_tools/unittest_discovery.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import inspect
import os
import sys
Expand All @@ -13,13 +14,13 @@
def get_sourceline(obj):
try:
s, n = inspect.getsourcelines(obj)
except:
except Exception:
try:
# this handles `tornado` case we need a better
# way to get to the wrapped function.
# This is a temporary solution
# XXX This is a temporary solution
s, n = inspect.getsourcelines(obj.orig_method)
except:
except Exception:
return "*"

for i, v in enumerate(s):
Expand Down Expand Up @@ -50,16 +51,14 @@ def generate_test_cases(suite):
loader_errors.append(s._exception)
else:
print(testId.replace(".", ":") + ":" + get_sourceline(tm))
except:
except Exception:
print("=== exception start ===")
traceback.print_exc()
print("=== exception end ===")


for error in loader_errors:
try:
with contextlib.suppress(Exception):
print("=== exception start ===")
print(error.msg)
print("=== exception end ===")
except:
pass
4 changes: 1 addition & 3 deletions python_files/tests/__main__.py
Original file line number Diff line number Diff line change
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
Loading