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

Introduce FormatterSettings #7545

Merged
merged 1 commit into from
Sep 21, 2023
Merged

Introduce FormatterSettings #7545

merged 1 commit into from
Sep 21, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Sep 20, 2023

Stack Summary

This stack splits Settings into FormatterSettings and LinterSettings and moves it into ruff_workspace. This change is necessary to add the FormatterSettings to Settings without adding ruff_python_formatter as a dependency to ruff_linter (and the linter should not contain the formatter settings).

A quick overview of our settings struct at play:

  • Options: 1:1 representation of the options in the pyproject.toml or ruff.toml. Used for deserialization.
  • Configuration: Resolved Options, potentially merged from multiple configurations (when using extend). The representation is very close if not identical to the Options.
  • Settings: The resolved configuration that uses a data format optimized for reading. Optional fields are initialized with their default values. Initialized by Configuration::into_settings .

The goal of this stack is to split Settings into tool-specific resolved Settings that are independent of each other. This comes at the advantage that the individual crates don't need to know anything about the other tools. The downside is that information gets duplicated between Settings. Right now the duplication is minimal (line-length, tab-width) but we may need to come up with a solution if more expensive data needs sharing.

This stack focuses on Settings. Splitting Configuration into some smaller structs is something I'll follow up on later.

PR Summary

This is the final step for the settings related structure changes. This PR introduces a new FormatterSettings struct in ruff_python_formatter and populates it in Configuration::into_settings. This PR doesn't add new options yet (still only supports setting line_width).

Test Plan

cargo test

  • Run the hyperfine benchmark against main with caching. The numbers remain unchanged, proving that the cache is working
  • Changing a setting that is not part of the cache key (e.g. output_format) does not result in a cache invalidation (same runtime as when running multiple times with the same settings)
  • Changing any other setting results in invalidating the cache and recomputing the output.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 20, 2023

CodSpeed Performance Report

Merging #7545 will not alter performance

Comparing formatter-settings (e9cbfab) with main (6540321)

Summary

✅ 25 untouched benchmarks

let options = PyFormatOptions::from_source_type(source_type)
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)))
.with_preview(preview);
let options = resolved_settings.formatter.to_format_options(source_type);
Copy link
Member Author

Choose a reason for hiding this comment

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

All just for this 😆

Copy link
Member

Choose a reason for hiding this comment

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

It's beautiful

@MichaReiser MichaReiser force-pushed the move-settings-to-ruff-workspace branch 2 times, most recently from 030293a to 9452ec3 Compare September 20, 2023 13:02
@MichaReiser MichaReiser added the internal An internal refactor or improvement label Sep 20, 2023
@MichaReiser MichaReiser marked this pull request as ready for review September 20, 2023 14:06
@MichaReiser MichaReiser force-pushed the move-settings-to-ruff-workspace branch 2 times, most recently from 2421373 to 1ebf2ea Compare September 20, 2023 15:05
Base automatically changed from move-settings-to-ruff-workspace to main September 20, 2023 15:24
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

Excellent.

@github-actions
Copy link
Contributor

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

@MichaReiser MichaReiser merged commit f8f1cd5 into main Sep 21, 2023
16 checks passed
@MichaReiser MichaReiser deleted the formatter-settings branch September 21, 2023 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants