Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Pyright #1246

Merged
merged 2 commits into from
May 22, 2024
Merged
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
12 changes: 11 additions & 1 deletion docs/contribute/DEV_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,19 @@ During development you can run static type checks using [mypy][]:
$ mypy
# No output is good!

There are also many [editor integrations for mypy][].
and [pyright][]:

$ npx pyright
...
Found 40 source files
0 errors, 0 warnings, 0 infos
Completed in 2sec

There are also many [editor integrations for mypy][], and Pyright can be
[configured for VS Code][].

[editor integrations for mypy]: https://github.com/python/mypy#integrations
[configured for VS Code]: https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance#settings-and-customization

### Removing features

Expand Down
30 changes: 30 additions & 0 deletions pyrightconfig.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the direction of this PR from trying to address all violations to just setting up Pyright and ignoring violations explicitly. This reflects similar work done in nextstrain/nextstrain.org#778.

Here's commits from the old direction: 9e8c9e0...3469831 and new direction: fda57c5

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"pythonVersion": "3.8",
"include": ["augur/"],


// These are rules that are enabled by default and currently have violations.

// TODO: go through these exceptions and determine if they should be kept or
// removed and violations addressed.

// TODO: consider aligning this with the same file in nextstrain/cli:
victorlin marked this conversation as resolved.
Show resolved Hide resolved
// <https://github.com/nextstrain/cli/blob/-/pyrightconfig.json>
"reportArgumentType": false,
"reportAttributeAccessIssue": false,
"reportCallIssue": false,
"reportGeneralTypeIssues": false,
"reportIncompatibleMethodOverride": false,
"reportMissingImports": false,
"reportMissingModuleSource": false,
"reportOperatorIssue": false,
"reportOptionalIterable": false,
"reportOptionalMemberAccess": false,
"reportOptionalOperand": false,
"reportOptionalSubscript": false,
"reportPossiblyUnboundVariable": false,
"reportPrivateImportUsage": false,
"reportSelfClsParameterName": false,
"reportUndefinedVariable": false,
"reportUnusedExpression": false,
}
22 changes: 22 additions & 0 deletions tests/test_pyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from pathlib import Path
from shutil import which
from subprocess import run

topdir = Path(__file__).resolve().parent.parent

pyright = which("pyright")
victorlin marked this conversation as resolved.
Show resolved Hide resolved
npx = which("npx")

if pyright:
pyright = [pyright]
elif npx:
pyright = [npx, "pyright"]
else:
pyright = None

@pytest.mark.skipif(not pyright, reason = "pyright is not available")
def test_pyright():
# Check the exit status ourselves for nicer test output on failure
result = run(pyright, cwd = topdir)
assert result.returncode == 0, "pyright exited with errors"
Loading