Skip to content
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

docstring code formatter: add a --docstring-code-format parameter to ruff format CLI #9186

Closed
kdeldycke opened this issue Dec 18, 2023 · 4 comments · Fixed by #9599
Closed
Labels
formatter Related to the formatter wish Not on the current roadmap; maybe in the future

Comments

@kdeldycke
Copy link

Following the implementation of experimental docstring format, a docstring-code-format configuration "knob" has been added in #8854. That way you can activate this new behavior by adding the following to ruff.toml (or any equivalent):

[format]
docstring-code-format = true

What I would like to have is a --docstring-code-format CLI option that I can use like so:

$ ruff format --docstring-code-format .

Why? Because I would like to test the docstring formatter on some projects, by the way of reuseable GitHub actions. And for these projects, I do not have the authority on the configuration files. I can only alter CLI parameters of ruff in the actions.

Is my proposal reasonable? Or is there a way I can pass arbitrary local configuration parameters via the CLI?

@kdeldycke kdeldycke changed the title docstring code formatter: add a --docstring-code-format parameter to the CLI docstring code formatter: add a --docstring-code-format parameter to ruff format CLI Dec 18, 2023
@MichaReiser MichaReiser added question Asking for support or clarification formatter Related to the formatter labels Dec 19, 2023
@MichaReiser
Copy link
Member

MichaReiser commented Dec 19, 2023

Hy @kdeldycke

Thanks for opening this issue and explaining your use case.

We've been hesitant to expose all formater options because the main benefit of a formatter is consistency and it requires that all users use the same configuration, ideally commited in the repository. We only support --line-length today (see #8363). But we understand that there are use cases where providing the option via CLI is useful, your use case is one of them. Our preferred solution is that ruff has a generic way to set an arbitrary configuration value. It encourage using configuration files over using CLI options but enables use cases like yours. See #8368

Unfortunately, we haven't made progress with implementing a generic way to pass option values yet which, understandably, is unsatisfying for users.

I don't think there's a good workaround for use case at the moment. You could specify another configuration but it would override all other settings too (and disables the automatic configuration discovery).

Related to:

@MichaReiser MichaReiser added question Asking for support or clarification wish Not on the current roadmap; maybe in the future and removed question Asking for support or clarification labels Dec 19, 2023
kdeldycke added a commit to kdeldycke/workflows that referenced this issue Jan 3, 2024
kdeldycke added a commit to kdeldycke/workflows that referenced this issue Jan 4, 2024
@kdeldycke
Copy link
Author

Thanks @MichaReiser for the detailed explanation of the current state of the CLI. I totally understand the priority and decision of my feature request. There are things way more important to focus on.

In the mean time, I hacked my way into generating a custom local ruff.toml file to feed to my CLI.

@kdeldycke
Copy link
Author

Another use case to consider, is using CLI parameters to setting up Ruff VScode extension:

Screenshot 2024-01-05 at 11 37 46

@MichaReiser
Copy link
Member

This will be supported once #9186 is merged

AlexWaygood added a commit that referenced this issue Feb 9, 2024
…9599)

Fixes #8368
Fixes #9186

## Summary

Arbitrary TOML strings can be provided via the command-line to override
configuration options in `pyproject.toml` or `ruff.toml`. As an example:
to run over typeshed and respect typeshed's `pyproject.toml`, but
override a specific isort setting and enable an additional pep8-naming
setting:

```
cargo run -- check ../typeshed --no-cache --config ../typeshed/pyproject.toml --config "lint.isort.combine-as-imports=false" --config "lint.extend-select=['N801']"
```

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Zanie Blue <contact@zanie.dev>
nkxxll pushed a commit to nkxxll/ruff that referenced this issue Mar 10, 2024
…stral-sh#9599)

Fixes astral-sh#8368
Fixes astral-sh#9186

## Summary

Arbitrary TOML strings can be provided via the command-line to override
configuration options in `pyproject.toml` or `ruff.toml`. As an example:
to run over typeshed and respect typeshed's `pyproject.toml`, but
override a specific isort setting and enable an additional pep8-naming
setting:

```
cargo run -- check ../typeshed --no-cache --config ../typeshed/pyproject.toml --config "lint.isort.combine-as-imports=false" --config "lint.extend-select=['N801']"
```

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Zanie Blue <contact@zanie.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter wish Not on the current roadmap; maybe in the future
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants