-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Configuration via JSON #5102
Comments
I think this does make sense, and it's come up at least once before. |
It would help with this too: #3694. |
Good point with #3694 - I can take a try at this sometime this week if you're OK with what I described |
I'm supportive of it! You can probably look at how the (Disclaimer that I'll want to get @MichaReiser's take prior to merging since he's thought about the future of configuration -- he's on vacation but will be back next week.) |
Sounds great! I will jump on this |
I think being able to set any configuration value via the CLI would have two benefits:
The downside I see of using
@tgross35 what would you think if we instead use an approach similar to
We would need to come up with a different name because ruff already uses I think this should work for your use case too, because you can iterate over the toml and create one One issue that could potentially come up is that this approach fails for very large configurations where it would be necessary to pass a few thousands of lines of key value pairs. |
I don't think there is any need to support YAML or anything else. As I see it, this option would be available for other tools to run
This might be a good idea if you are looking for ways to ease user configuration, but I think it is clunkier for other tools - because now you need to take configuration that is easily serializable to JSON (as is the case for TOML and YAML) and manually split it up, remove quotes, convert lists to CSV, recurse this for all nesting options, etc. And then do the opposite on the |
Have you considered creating a (named) temp file and passing that path to Ruff? It seems that unlocks the functionality you want without requiring any changes on Ruff's side. The reason I'm heistant of adding |
I did some more research and the only tool that I found that supports something similar is Jest where |
The named temp file is the current solution, but it is unfortunately quite cumbersome.
Could the option be hidden from the In any case, I don't think Samples of the use cases I am imagining, which could be documented examples: //! A `cargo-ruff` tool that would run ruff upon running `cargo ruff`, with config in
//! `[package.metadata.ruff]` in `Cargo.toml`
fn main() {
let manifest_path = // ... use cargo_metadata to extract
let contents = std::fs::read_to_string(manifest_path)?;
let v: Value = serde_json::from_str(contents)?;
let cfg = v["package"]["metadata"]["ruff"];
Command::new("ruff").arg("--config-json").arg(cfg.to_str()).status();
} # Makefile for C+Py projects where some configuration exists in a YAML file
lint:
ruff --config-json $(yq '.ruff-config' project-config.yaml) // A NPM project with a few python files (very similar to above)
{
"name": "demo",
// ...
"scripts": {
"lint:py": "ruff $(jq '.ruff-config' package.json)"
},
"ruff-config":
"per-file-ignores": {
"__init__.py": ["E402"],
"path/to/file.py": ["E402"]
}
} # Python just needs to construct a dict to run `ruff`
cfg = {"extend-exclude": [f for f in skip_files]}
subprocess.run(["ruff", "--config-json", json.dumps(cfg)]) // The ruff changes would only be a few dozen lines: more or
// less just the below
if let Some(cfg) = args.config_json {
return serde_json::from_str::<Options>()?;
} All of those are simple yet powerful use cases in 1-3 lines - super easy to add to any project. Any sort of custom |
Thank you for adding the additional detail and I see why a temporary file doesn't work well for a script in We discussed this further internally. We do see the value of it and may decide to support it eventually, but we aren't sure if adding a new CLI option accepting JSON is the right way to go. I'll close this issue in favor of #3694 which asks for a similar feature. I, unfortunately, can't suggest a better solution for the time being other than autogenerating the |
This is my second (and I think improved) take on #4970
What would thoughts be on accepting a parameter
--config-json
that takes identical configuration toruff.toml
? Example:Reasoning:
ruff
from tools that are unaware of ruff's CLI format or schema. For example, acargo-ruff
tool could (1) grab thepackage.metadata.ruff
table fromCargo.toml
, (2) naively reserialize it as JSON, no validation required, (3) invoke ruff with the CLI option. Same for a NPM tool that uses config inpackage.json
, or something that uses legacytox.ini
orsetup.cfg
toml
version, the same structs can be used with serde and no additional documentation is requiredruff.toml
/pyproject.toml
but is difficult to supply via CLI arguments, this would provide a workaround for CI toolsThe text was updated successfully, but these errors were encountered: