-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add support to config & run linter programmatically #246
Comments
I actully tried to hack it only to realize that The issue can be reduced to exposing that |
Thanks for the issue! I'd like to clarify what you are trying to achieve here.
Are you looking for a way to dynamically generate the contract / configuration that Import Linter discovers? |
Good example - let me explain... I'm focusing on the 1st bullet only (with invocation entry point) - the 2nd one (custom contract types) is outside the scope for this issue. The problem is The point is to avoid creating any config file (and simply pass config from code = from memory), for example, in my hack, I simply initialized some data = self.data.copy()
session_options = data.get("session_options", {})
contracts_options = data.get("contracts_options", [])
return UserOptions(session_options=session_options, contracts_options=contracts_options) That's all I want:
Tests of |
Got it. I think that |
I created few rules as unit tests, for example, And I am pretty happy with that. Thanks for the pointers! You can see that I reference modules by their compiler-enforced names (instead of opaque strings) which makes it easier for the rule to survive refactoring. Also, unit tests are free to provide extra context and structure - they are free from specific config format. I guess the issue can be closed unless you want to make a change to enforce stability of this API.
|
There is already a Python API for reading configuration, so I'd be happy to have a similar thing for |
Configuring and running
import-linter
programmatically has multiple benefits:Referencing modules by their imported names (instead of opaque string in configs)?
This reliably survives refactoring (especialy if this code runs in tests - see below).
Generating rules instead of relying on static config files?
It is still possible to generate config files and then load them, but it would:
Running
import-linter
via tests?It "lints" relationship between modules (not code as text).
This should allow running it in the same Python runtime with those modules under tests.
The text was updated successfully, but these errors were encountered: