-
Notifications
You must be signed in to change notification settings - Fork 550
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
Strict rules that check dependencies and type annotations #296
Comments
Can you elaborate? Not sure what is meant.
Then |
At google we have (actually) As I realized this involves pytype, I suppose this could be a quite some work... |
People are using macros to do this sort of thing right now, and Bazel Aspects alternatively. In future I think there should be a 'paved road' for writing type-annotated Python in Bazel, though can't say yet whether there'd be rules like |
(I'm the author of the strict deps checking rule at Google) "Strict deps" is a term we use to mean if you have "import foo" in your code, then some direct dependency provides "foo". It helps prevent your code from breaking when its dependencies's dependencies have changed. The strict deps checking and pytype checking are separate implementations. We just bundle them into a single macro because usually people want both (both have their own separate stand alone macros, too). The core design of how strict deps works would probably mostly work for Bazel built Python code. It has to make some assumptions with how things work, of course. We've also had to work around a variety of short comings in the Python providers that starlark currently has. wrt naming: having macro names that reflect a particular aspect/validator being enforced also comes with a combinatorical drawback. You end up with py_strict_, pytype_, mypy_, pytype_strict_, mypy_strict_*, etc etc. While it works, and there's a certain appeal to having "what it does" right there in the rule name, it's also a headache for new comers ("Which of the 12 rules do I use?") and naming. I wonder if there's a better way (the particular idea in my head is: what if I want to make sure my code works with pytype and mypy and pyre and strict deps and etc mypy_pytype_pyre_strict_library?). |
Ok I see that there is open source consideration here that different type checkers may be used. So strict_deps and type checking are definitely two separate considerations. I wonder if the type checkers can all be hooked into a single entry point (not sure if it makes sense to use more than one type checker at the same time but) so the work can be hidden behind py_library:
|
Maybe rather than having a string have a Provider like |
Passing a string probably isn't a good idea because it would require the callee to have a mapping of names to functions, e.g., Anyways... Here's a bit of a brain dump for some Bazel things that would make implementing strict deps much easier. These are various assumptions it makes in our implementation. Fundamentally, it's all about mapping a target to the module names, package names, and package attributes that the target provides.
In our implementation, most of those points above are hard coded in some way (e.g., we have a file with a bunch of info about the stdlib, we make various assumptions when transforming a file path to a module name, etc). |
+1 to py_strict_* functions and would love pytype support too. These two features by themselves make Bazel a really appealing option for Python code, plus the ability to easily generate par files (I suspect the Python community might otherwise ignore Bazel). |
Something like the above, but with labels so it supports custom checkers seems like a good middle ground.
Then a couple macros could be provided:
That just add in a |
@fahhem This looks very much like what Google does. I would much rather be able to provide a global setting for all Python libraries for the type checkers. If you have a large project, inserting the type_checkers in every single target will become quite redundant real fast. Ditto re. strict targets. And what about linting? The problem with requiring lint to pass is that one needs to be able to disable that until ready to commit. That smells to me also like a global setting. |
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. |
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?" |
Is this issue resolved? I don't seem to find an implementation in the thread. |
I will re-open. But since a different issue was filed in bazel/bazel we may not be able to implement here. |
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. |
Bumping so it doesn't close this issue |
Bump. Any plans to get this done anytime soon? |
(from an ex-Googler) |
Also bumping. Was very valuable when a few of us were at google and we wish it was available in the open verison. |
+1 |
2 similar comments
+1 |
+1 |
Related: #2537 |
This adds attributes and fields of use to static analysis. For type definition files (usually `.pyi` files), the `pyi_srcs` and `pyi_deps` fields are added to the rules. They end up in the PyInfo fields direct_pyi_files and transitive_pyi_files. So that static analysis tools can retain access to a target's Python source files, even if precompiling is enabled, `direct_original_sources` and `transitive_original_sources` fields are added to PyInfo. Work towards #2537, #296
With #2538, the basics for a basic implementation of strictdeps is now possible. The last remaining feature gap is handling cases where the importable modules/packages/attributes information is in a file instead of directly within a provider field. This makes it possible to (1) handle importing things from packages (distinguishing between |
Will we have strict rules that check for deps and type annotations? i.e.
py_strict_library
,py_strict_binary
,py_strict_test
.The text was updated successfully, but these errors were encountered: