Skip to content

Add target_version to formatter options#9220

Merged
MichaReiser merged 2 commits into
mainfrom
add-target-version-to-formatter-options
Dec 21, 2023
Merged

Add target_version to formatter options#9220
MichaReiser merged 2 commits into
mainfrom
add-target-version-to-formatter-options

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Dec 21, 2023

Copy link
Copy Markdown
Member

Summary

This PR adds the target_version option to the formatter option and initializes it with the target_version specified in the ruff.toml.

The new configuration doesn't yet affect any formatting.

Test Plan

I ran ruff manually in my test project and added a dbg statement to to_format_options. Changes to target-version in the configuration were reflected in the debug printed PyFormatOptions. Verified that using requires-python works as intended.

@MichaReiser MichaReiser added configuration Related to settings and configuration formatter Related to the formatter labels Dec 21, 2023
Comment on lines +368 to +383
#[derive(CacheKey, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Default)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "lowercase")
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum PythonVersion {
Py37,
#[default]
Py38,
Py39,
Py310,
Py311,
Py312,
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could have a single PythonVersion definitions shared by the linter and formatter but there's currently no good crate where to place it. Creating one feels overkill for such a simple definition.

Ultimately I think the definition should be in ruff_python_ast where it specifies the language features.

@MichaReiser MichaReiser force-pushed the add-target-version-to-formatter-options branch from 6bc4c0f to 37ddbea Compare December 21, 2023 02:51
@github-actions

github-actions Bot commented Dec 21, 2023

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Comment thread crates/ruff_python_formatter/src/options.rs
@MichaReiser MichaReiser enabled auto-merge (squash) December 21, 2023 04:02
@MichaReiser MichaReiser merged commit 8cb7950 into main Dec 21, 2023
@MichaReiser MichaReiser deleted the add-target-version-to-formatter-options branch December 21, 2023 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Related to settings and configuration formatter Related to the formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants