Skip to content

Commit

Permalink
Run Pyright for all workflows (#18268)
Browse files Browse the repository at this point in the history
* Run Pyright for all workflows

* Rename job

* Remove special directory

* analyze types only in pythonFiles

* Install requirements

* Fix indentation

* Indentation, again

* Try excluding lib form pyright

* install debugger requirements, tweak extraPaths

* Remove debugpy install

* Exclude more files

* Add more to pyproject.toml, install test reqs

* Fix normalizeSelection

* Move from exclude to ignore

* Update build workflow
  • Loading branch information
kimadeline authored Jan 10, 2022
1 parent 7e1d4ae commit 2883012
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ jobs:
with:
node_version: ${{ env.NODE_VERSION }}

check-types:
name: Check Python types
if: github.repository == 'microsoft/vscode-python'
runs-on: ubuntu-latest
steps:
- name: Use Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Checkout
uses: actions/[email protected]

- name: Install Python requirements
run: |
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt --no-user
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/jedilsp --no-cache-dir --implementation py --no-deps --upgrade -r ./pythonFiles/jedilsp_requirements/requirements.txt
python -m pip install --upgrade -r build/test-requirements.txt
- name: Run Pyright
uses: jakebailey/pyright-action@v1
with:
working-directory: 'pythonFiles'

### Non-smoke tests
tests:
name: Tests
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ jobs:
with:
node_version: ${{ env.NODE_VERSION }}

check-types:
name: Check Python types
runs-on: ubuntu-latest
steps:
- name: Use Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Checkout
uses: actions/[email protected]

- name: Install Python requirements
run: |
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt --no-user
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/jedilsp --no-cache-dir --implementation py --no-deps --upgrade -r ./pythonFiles/jedilsp_requirements/requirements.txt
python -m pip install --upgrade -r build/test-requirements.txt
- name: Run Pyright
uses: jakebailey/pyright-action@v1
with:
working-directory: 'pythonFiles'

### Non-smoke tests
tests:
name: Tests
Expand Down
6 changes: 4 additions & 2 deletions pythonFiles/normalizeSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def _get_statements(selection):
# In Python 2.7, lineno takes into account decorators, so this offset check is unnecessary.
# Also, not all AST objects can have decorators.
if hasattr(node, "decorator_list") and sys.version_info.major >= 3:
line_end -= len(node.decorator_list)
# Using getattr instead of node.decorator_list or pyright will complain about an unknown member.
line_end -= len(getattr(node, "decorator_list"))
ends.append(line_end)
ends.append(len(lines))

Expand All @@ -71,7 +72,8 @@ def _get_statements(selection):

# Special handling of decorators similar to what's above.
if hasattr(node, "decorator_list") and sys.version_info.major >= 3:
start -= len(node.decorator_list)
# Using getattr instead of node.decorator_list or pyright will complain about an unknown member.
start -= len(getattr(node, "decorator_list"))
block = "\n".join(lines[start:end])

# If the block is multiline, add an extra newline character at its end.
Expand Down
24 changes: 24 additions & 0 deletions pythonFiles/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,27 @@ exclude = '''
)/
)
'''

[tool.pyright]
exclude = ['lib']
extraPaths = ['lib/python', 'lib/jedilsp']
ignore = [
# Ignore all pre-existing code with issues
'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_util.py',
'tests/testing_tools/adapter/pytest/test_cli.py',
'tests/testing_tools/adapter/pytest/test_discovery.py',
]

0 comments on commit 2883012

Please sign in to comment.