-
-
Notifications
You must be signed in to change notification settings - Fork 85
feat: Add ty as a linter #665
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
base: main
Are you sure you want to change the base?
Conversation
|
95be6f4 to
70b0499
Compare
alexeagle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, excited that you've broken ground on this.
We'll have to do some README edits before landing to warn about both ty immaturity and also the experimental nature of this linter aspect.
.github/workflows/mirror.yml
Outdated
| npx @bazel/buildifier lint/ruff_versions.bzl | ||
| - name: Update ty | ||
| run: | | ||
| ./lint/mirror_ty.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's possible that we skip the mirroring, now that many Bazel users check in their MODULE.bazel.lock file they can get the Trust-on-first-use guarantee. I suspect it's too soon to change that, just raising for our team to consider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now do you mind dropping this file and the mirror_ty.sh from this PR? since it comes in through rules_multitool there are other options for updating it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
| @@ -0,0 +1,5 @@ | |||
| # Demo with just running ty: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this demo should look like bazel run @some_label//:ty -- some_file.py - we want to convince ourselves we know how to call the tool standalone
example/test/unsupported_operator.py
Outdated
| @@ -0,0 +1,3 @@ | |||
| # Demo with just running ty: | |||
| # $ bazel run --run_under="cd $PWD &&" -- //tools/lint:ty check --config=ty.toml src/*.py | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💎
lint/ty.bzl
Outdated
| load("@aspect_rules_lint//lint:ty.bzl", "lint_ty_aspect") | ||
| ty = lint_ty_aspect( | ||
| binary = Label("@aspect_rules_lint//lint:ty_bin", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing a closing paren
lint/ty.bzl
Outdated
| ```starlark | ||
| # Note: this won't interact properly with the --platform flag, see | ||
| # https://github.com/aspect-build/rules_lint/issues/389 | ||
| alias( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is copy-pasta? They should get this for free from multitool
lint/ty.bzl
Outdated
| https://docs.astral.sh/ty/reference/exit-codes/ | ||
| env: environment variables for ty | ||
| """ | ||
| inputs = srcs + config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The big remaining work here is a graph of py_library(name="a", deps = ["b"]) -> py_library(name="b")
I think you'll already find that it's broken to lint a because it will be missing type definitions from b.
In fixing that, we want to avoid any work of type-checking the b sources a second time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out. I'll start looking into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexeagle After looking into this a bit I had some directional questions that I'd like to get your input on.
It seems like the flake8 implementation is trying to avoid taking a dependency on rules_python, but using the PyInfo provider would be one way to collect the dependencies of a target. What are your thoughts on taking a dependency on rules_python?
I was also looking at the implementation of rules_mypy which I think handles some other cases I think this linter might want to eventually cover. Any thoughts on the approach taken in rules_mypy that would be good to pattern after or avoid?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's unavoidable to need the PyInfo symbol so rules_python is a required dep. bazelbuild/bazel#25509 can make it less painful.
@arrdem has spent more time in rules_mypy recently than I have. Could you give any short specifics or links on which cases/approach you're looking at?
- Removed ty mirroring in favor of multitool usage - Fixed running example ty linting with a standalone command. - Fixed a closing paren in the docs. - Dropped `fetch_ty` helper.
13ac733 to
719652b
Compare

Adds ty as a linter for Python.
This is my first contribution here, so a lot of this is copied from the implementation for
ruff, including the strategy for mirroringtyreleases.Changes are visible to end-users: yes
Test plan
Added
unsupported_operator.pyas an example lint, andcall_non_callable.py, which should be ignored by thety.tomlconfiguration file.