tophat / codewatch

[deprecated] Monitor and manage deeply customizable metrics about your python code using ASTs
https://codewatch.io
Apache License 2.0
38 stars 3 forks source link

Update for async API calling pattern (for debug-time use of linter failures) #62

Open cabiad opened 5 years ago

cabiad commented 5 years ago

For large codebases, it would be good if lint results could be communicated to devs before CI / pre-commit time. We were wondering if we could integrate with our web back end when it's in debug mode to show devs ASAP if there are problems with what they're doing.

cabiad commented 5 years ago

@lime-green investigated pretty thoroughly but we haven't found a great way for the tool to operate asynchronously. We may come back to this another day.

lime-green commented 5 years ago

It was hard to integrate with our UWSGI django app, notably because multiple processes would run and this required locking (I used django cache but this only works if the underlying cache implementation is atomic) or to start it independently of the UWSGI processes. It also either requires a file watcher (but then codewatch restarts on every little change) or someway to restart whenever the dev server restarts.

After discussion with @francoiscampbell, I propose the following:

noahnu commented 5 years ago

Alternative solution:

Explicitly define and support a monotonic assertion type.

A monotonic assertion would have the properties:

Now given monotonic assertions, provide CLI "watch" mode (or IDE hook) such that: When a file is saved, check that it matches file/dir filters. Now, for every monotonic assertion, alternate between a visit to each dependant visitor and an execution of the parent assertion. When the assertion fails, report an "error" and stop traversing the AST.

What does this solve?

We no longer need to traverse the entire AST of the codebase before determining if an assertion fails. In CI you'll probably still want the complete stats, but for something like an IDE / watch mode integration, you're probably only concerned with the files you're actively editing (or diff between current code and HEAD of upstream).

Caveats

This would require a way to know if an assertion is monotonic. We could provide a way to explicitly label the function and explicitly note the dependant visitor functions.

Need to support way to alternate between visitors and assertions efficiently.

Comments

Most of our assertions in use are already monotonic according to the above definition.