Skip to content

Run black on files in package#328

Closed
tsalo wants to merge 8 commits intophysiopy:masterfrom
tsalo:ref/format-package
Closed

Run black on files in package#328
tsalo wants to merge 8 commits intophysiopy:masterfrom
tsalo:ref/format-package

Conversation

@tsalo
Copy link
Copy Markdown
Member

@tsalo tsalo commented Oct 21, 2020

References issue #324 and PR #327. This should probably be merged before #327, so that the linting CI step passes in that PR.

Proposed Changes

  • Run black on the package, skipping heuristics, tests, and anything from the repo's top level.

I skipped heuristics, tests, and anything from the repo's top level.
@tsalo tsalo added the Internal Changes affect the internal API. It doesn't increase the version, but produces a changelog label Oct 21, 2020
@tsalo tsalo requested a review from smoia October 21, 2020 21:28
@tsalo
Copy link
Copy Markdown
Member Author

tsalo commented Oct 21, 2020

The E203 error in the linting step can be ignore- E203 is not PEP8 compatible and flake8 is in the wrong on this.

Copy link
Copy Markdown
Member

@smoia smoia left a comment

Choose a reason for hiding this comment

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

I went through half of the files and I saw many cases that need fixing - I know, you whised it was as simple as just running black.

Can I ask you to look at the changes? I will continue later on.

@@ -22,136 +22,186 @@ def _get_parser():
"""
parser = argparse.ArgumentParser()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some of the parser helps got weird. we should probably manually edit them after black - unless I missed the part in which black doesn't substitute ' with " if " is contained in the string, but then it becomes incredibly ugly and confusing.

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.

I've gone through and cleaned up the strings. Some switches between ' and " are necessary, although the internal double-quotes could be changed to single-quotes to eliminate them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds reasonable! In fact, I think they were double quote for a similar reason (not to confuse them with the external single quotes).

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.

Awesome. I've switched them.

type=str,
help="Folder where output should be placed. "
"Default is current folder. "
'If "-heur" is used, it\'ll become '
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or here

orig_units.append(item.split(" ")[1])
units = [
"s",
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know why black is formatting this list in this way throughout the whole file, but it's awful. can we add a #fmt: off (or whatever it was) here?

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.

This is fixed by just not including the trailing commas in the lists (not sure why they're there). black won't reformat units = ["s"], so I'll just revert those.

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.

After digging a bit, it turns out that trailing commas are there to make lists easily extensible, so it actually makes sense to expand any list with a comma at the end to multiple lines because you expect that list to grow and you want minimal diffs when that happens. In any case, these lists aren't likely to grow, so I just removed the trailing commas and put them on single lines.

LGR.warning('While "-heur" was specified, option "-sub" was not.\n'
'Skipping BIDS formatting.')
LGR.warning(
'While "-heur" was specified, option "-sub" was not.\n'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Odd

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.

Do you mean the new line is odd, or the fact that this line uses single quotes and the next uses double quotes?

@smoia smoia self-assigned this Oct 21, 2020
@smoia smoia requested a review from eurunuela October 21, 2020 22:16
@tsalo tsalo requested a review from smoia October 21, 2020 23:21
@smoia smoia mentioned this pull request Oct 21, 2020
Copy link
Copy Markdown
Collaborator

@eurunuela eurunuela left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @tsalo !

It will take me some time to get used to the double quotes 😅

Comment on lines +15 to +39
# kelvin: thermodynamic temperature
"kelvin": "K", "kelvins": "K",
# mole: amount of substance
"mol": "mol", "mole": "mol",
# newton: force, weight
"newton": "N", "newtons": "N",
# pascal: pressure, stress
"pascal": "Pa", "pascals": "Pa", "pa": "Pa",
# volt: voltage (electrical potential), emf
"volt": "V", "volts": "V",
# degree Celsius: temperature relative to 273.15 K
"°c": "°C", "°celsius": "°C", "celsius": "°C",
# ampere: electric current
"ampere": "A", "amp": "A", "amps": "A",
# second: time and hertzs: frequency
# siemens: electric conductance (e.g. EDA)
"siemens": "S",
# second: time and hertzs
"1/hz": "s", "1/hertz": "s", "hz": "Hz",
"1/s": "Hz", "1/second": "Hz", "1/seconds": "Hz",
"1/sec": "Hz", "1/secs": "Hz", "hertz": "Hz",
"second": "s", "seconds": "s", "sec": "s",
"secs": "s",
# All the aliases with one letter (to avoid issues)
"k": "K", "n": "N", "v": "V", "c": "°C", "a": "A", "s": "s",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh no 😅

f"The given unit prefix {unit} does not "
"have aliases, passing it as is"
)
prefix = orig_unit[: len(unit)]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well this is new to me.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was referring to the space after the colon.

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.

Yes, it takes some getting used to. The PEP8 rules for colons are annoyingly complicated, but this more in line with them than what flake8 enforces.

@smoia smoia added Refactoring Improve nonfunctional attributes and removed Internal Changes affect the internal API. It doesn't increase the version, but produces a changelog labels Nov 2, 2020
'call phys2bids using both "-ntp" and "-tr" arguments')
LGR.warning(
"Skipping trigger pulse count. If you want to run it, "
'call phys2bids using both "-ntp" and "-tr" arguments'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Black failed here!

@tsalo tsalo closed this Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactoring Improve nonfunctional attributes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants