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

Use ruff's formatter #177

Merged
merged 5 commits into from
Aug 22, 2024
Merged

Use ruff's formatter #177

merged 5 commits into from
Aug 22, 2024

Conversation

henriquegemignani
Copy link
Member

No description provided.

@henriquegemignani henriquegemignani requested a review from a team July 14, 2024 15:02
Copy link

codecov bot commented Jul 14, 2024

Codecov Report

Attention: Patch coverage is 65.62500% with 44 lines in your changes missing coverage. Please review.

Project coverage is 76.98%. Comparing base (6943fc8) to head (fec15d1).
Report is 6 commits behind head on main.

Files Patch % Lines
...rc/mercury_engine_data_structures/formats/bmtre.py 0.00% 14 Missing ⚠️
...mercury_engine_data_structures/file_tree_editor.py 50.00% 4 Missing ⚠️
src/mercury_engine_data_structures/common_types.py 75.00% 3 Missing ⚠️
...rc/mercury_engine_data_structures/formats/bmsad.py 85.71% 2 Missing ⚠️
...rc/mercury_engine_data_structures/formats/brfld.py 33.33% 2 Missing ⚠️
...ercury_engine_data_structures/formats/gui_files.py 66.66% 2 Missing ⚠️
src/mercury_engine_data_structures/formats/pkg.py 50.00% 2 Missing ⚠️
src/mercury_engine_data_structures/game_check.py 33.33% 2 Missing ⚠️
...pyinstaller/hook-mercury_engine_data_structures.py 0.00% 1 Missing ⚠️
src/mercury_engine_data_structures/cli.py 0.00% 1 Missing ⚠️
... and 11 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #177   +/-   ##
=======================================
  Coverage   76.98%   76.98%           
=======================================
  Files          76       76           
  Lines        3494     3494           
=======================================
  Hits         2690     2690           
  Misses        804      804           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Const(0x000B0001, Hex(Int32ul)),
Const(0x000C0001, Hex(Int32ul))
"version"
/ IfThenElse(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ruff makes these look rather ugly :(

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to tell ruff to exempt these? or is the only fix to just change all of those to use = syntax instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm kinda fine with how it looks. Not the best, but it's still usable to not bother trying to make it look different.

Copy link
Contributor

Choose a reason for hiding this comment

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

no this is really bad imo

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm strong on needing some sort of auto-formatting though. Especially to keep all the project settings in sync across all repos in the organisation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I unsucessfully tried to find some sort of rule for that. Is there anyway to do it without disabling ruff for each of those lines?

Copy link
Member Author

Choose a reason for hiding this comment

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

black and ruff's formatter don't offer configuration to how the code is formatted. Best I can think of is wrapping the construct definitions in a "don't format this block"?

Copy link
Contributor

@ThanatosGit ThanatosGit left a comment

Choose a reason for hiding this comment

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

Should the marked lines also be excluded from formatting?

def GetTypeConstruct(self, keyfunc, follow_typedef: bool = True) -> construct.Construct:
return construct.FocusedSeq(
"switch",
"key" / construct.Computed(keyfunc),
"type" / construct.Computed(lambda this: self.get_type(this.key, follow_typedef=follow_typedef).name),
"switch" / construct.Switch(
"switch"
/ construct.Switch(
Copy link
Contributor

Choose a reason for hiding this comment

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

.

@@ -112,13 +112,14 @@ def PrefixedAllowZeroLen(lengthfield, subcon, includelengthfield=False):
return FocusedSeq(
"prefixed",
"len" / Peek(lengthfield),
"prefixed" / Prefixed(
"prefixed"
/ Prefixed(
Copy link
Contributor

Choose a reason for hiding this comment

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

.

Struct(
"type" / StrId,
"value"
/ Switch(
Copy link
Contributor

Choose a reason for hiding this comment

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

.

@henriquegemignani
Copy link
Member Author

I saw these when reviewing it myself and thought they were small enough to not bother.

@ThanatosGit
Copy link
Contributor

Alright, I leave it to the others who were complaining if they want to change it or not. I'm fine with it how it is.

Copy link
Contributor

@steven11sjf steven11sjf left a comment

Choose a reason for hiding this comment

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

I read about 1/3 of it but it's mostly good to me. the hex-escape formatting is the biggest issue I have with it.

@@ -177,7 +177,7 @@ def decode_encode_compare_file(file_path: Path, game: Game, file_format: str):
resource = resource_class.parse(raw, target_game=game)
encoded = resource.build()

if raw != encoded and raw.rstrip(b"\xFF") != encoded:
if raw != encoded and raw.rstrip(b"\xff") != encoded:
Copy link
Contributor

Choose a reason for hiding this comment

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

Personal preference but hex escapes look better with A-F capitalized, especially \x.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm indifferent, but I don't believe it's configurable

@@ -112,13 +112,14 @@ def PrefixedAllowZeroLen(lengthfield, subcon, includelengthfield=False):
return FocusedSeq(
"prefixed",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should choose either the / format or the = format and standardize it across the repo. I'm partial to the = format because it feels more readable to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably more of a "we should pick one and manually update code to comply/enforce it on new PRs" than something that ruff can handle

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should choose either the / format or the = format and standardize it across the repo. I'm partial to the = format because it feels more readable to me.

if we must pick one, it needs to be the / format. readability is secondary to functionality, and using kwargs (the = format) does not offer as much functionality

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine having both.
I prefer the kwargs one, but it is more limiting, particularly having unnamed padding

@henriquegemignani henriquegemignani merged commit afb176d into main Aug 22, 2024
9 of 10 checks passed
@henriquegemignani henriquegemignani deleted the feature/formatting branch August 22, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants