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

feat: update to black v24 and fix double curly braces #216

Merged
merged 2 commits into from
Jan 31, 2024

Conversation

mbhall88
Copy link
Member

This PR closes #215, which was caused by the different f-string tokenizing in python 3.12. We had previously dealt with this (#213), but this was only in snakemake code. #215 relates to python code outside of snakemake code (i.e. outside of rules).

The PR also updates black to v24.1, which contains some style changes we need to make some alterations for:

  • It enforces a blank line after module strings ("""module string"""). We had some test cases where we allow multiple module strings to be passed to rule directives such as shell and message, so I had to add some code to remove black's added newline in these cases.
  • docstrings are aligned correctly now, which required a slight alteration to the expected output of one test
  • better handling of long lines. This required an alteration to one test where an inline if-else statement is now broken into three lines

I also explicitly added a default for the python versions we target to black.

@mbhall88 mbhall88 requested a review from bricoletc January 29, 2024 03:25
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1d11dba) 97.76% compared to head (8ee74cd) 97.82%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
+ Coverage   97.76%   97.82%   +0.06%     
==========================================
  Files          12       12              
  Lines        1028     1057      +29     
  Branches      228      237       +9     
==========================================
+ Hits         1005     1034      +29     
  Misses         12       12              
  Partials       11       11              
Flag Coverage Δ
unittests 97.72% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
snakefmt/__init__.py 77.77% <100.00%> (+6.34%) ⬆️
snakefmt/config.py 100.00% <100.00%> (ø)
snakefmt/formatter.py 98.87% <100.00%> (+0.09%) ⬆️
snakefmt/parser/parser.py 97.86% <100.00%> (+0.07%) ⬆️
snakefmt/parser/syntax.py 98.91% <ø> (ø)
snakefmt/snakefmt.py 95.27% <100.00%> (ø)

@johanneskoester
Copy link
Contributor

Merge and new release?

@mbhall88
Copy link
Member Author

mbhall88 commented Jan 30, 2024

Merge and new release?

I'd rather wait for @bricoletc to review if that's okay? He often will find things I've missed or suggest better ways to do certain things (he is more familiar with the parser logic than me).

@bricoletc
Copy link
Collaborator

bricoletc commented Jan 31, 2024

@mbhall88 @johanneskoester I will review this by the end of the week ideally 👍

@johanneskoester
Copy link
Contributor

Sure!

Copy link
Collaborator

@bricoletc bricoletc left a comment

Choose a reason for hiding this comment

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

V. nice commits @mbhall88, clearly #215 is fixed

In the future I think we should PR from a non-master branch on snakefmt itself; that way, when one of us reviews, we can add commits to that branch, which updates the PR here on github

I've added two commits to my fork that I would like to put on top of mbhall/master (i.e. this PR) - do you know what's the best way to do this?

And I've left comments

Thanks :))

Comment on lines +19 to +25
DEFAULT_TARGET_VERSIONS = {
TargetVersion.PY38,
TargetVersion.PY39,
TargetVersion.PY310,
TargetVersion.PY311,
TargetVersion.PY312,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just checking I'm following here @mbhall88, what does this achieve exactly? I'm guessing Black's Mode constructor now requires the target_version argument, but does the set of target versions provided change how Black will format the code??

Copy link
Collaborator

Choose a reason for hiding this comment

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

This also forces up to maintain in two places what python versions we support - the 'classical' pyproject.toml, and here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was more to be explicit with black that we are targeting these versions as I suspect there might be python >=3.12-specific formatting changes that can happen with the new f-string functionality.
I know it's a pain to maintain in two places....Maybe we can make this just target the version of python that is being used when snakefmt is run...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes that would be better IMO - do you want to try and write that up, or do you prefer that I do it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy for you to do it. Should be as easy as using sys to check the current version of python. Though, I wonder if black actually already does this?

tests/test_formatter.py Show resolved Hide resolved
tests/test_formatter.py Show resolved Hide resolved
snakefmt/parser/parser.py Show resolved Hide resolved
snakefmt/formatter.py Show resolved Hide resolved
@bricoletc bricoletc merged commit 8ee74cd into snakemake:master Jan 31, 2024
13 checks passed
@bricoletc
Copy link
Collaborator

Erm, @mbhall88 sorry I made a mistake, I mistakenly merged this into master here, didn't mean to. I've reversed master here back to v0.9.0 .

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.

Incorrectly removes double curly braces in f-string
3 participants