-
Notifications
You must be signed in to change notification settings - Fork 49
Conversation
@aneeshusa Could you please take a look and briefly comment on the changes? You seem to have a stronger sense of "good Python style" than I do :-) Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for making this more pep8 friendly! This looks OK at a glance but I personally much prefer block style indent.
homu/server.py
Outdated
@@ -1,7 +1,8 @@ | |||
import hmac | |||
import json | |||
import urllib.parse | |||
from .main import PullReqState, parse_commands, db_query, INTERRUPTED_BY_HOMU_RE, synchronize | |||
from .main import (PullReqState, parse_commands, db_query, | |||
INTERRUPTED_BY_HOMU_RE, synchronize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I much prefer block style indents (with trailing commas) in general, e.g.
from .main import (
PullReqState,
parse_commands,
db_query,
INTERRUPTED_BY_HOMU_RE,
synchronize,
)
They take up more vertical space but I find them easier to read and cause much less diff noise, which is valuable for git log
, git blame
and friends.
This also works for method calls, dictionary and list literals, etc. in addition to imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I'll try a unilateral switch to block-style indent to see if anything goes wrong -- I feel like we have a few spots where it'll be adding unduly many lines (like https://github.com/servo/homu/pull/103/files#diff-7a3e9e91f0de1349c2561ed96ae5e206R511) but on the whole it's probably worthwhile for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I just remembered the spot where block style indents fall apart: long function declarations.
Before:
def parse_commands(body, username, repo_cfg, state, my_username, db, states, *, realtime=False, sha=''):
global global_cfg
state_changed = False
Just sticking in a line break:
def parse_commands(body, username, repo_cfg, state, my_username, db, states,
*, realtime=False, sha=''):
global global_cfg
state_changed = False
Full block-style indent needs the end paren with no indent, which looks really funny to me:
def parse_commands(
body,
username,
repo_cfg,
state,
my_username,
db,
states,
*,
realtime=False,
sha=''
):
global global_cfg
state_changed = False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding only a line break means you get unnecessary diff noise if you change the function name. I've gotten used to block indent so the ):
without an indent looks fine to me, but I also think that there are further improvements to be had in the future by introducing some intermediate data structures as appropriate and reducing the general spaghetti-ness in further refactors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this is worth going back through and tidying right now, or shall we land these fixups as-is and catch the diff noise reduction cleanups in future refactors?
homu/server.py
Outdated
@@ -39,7 +40,8 @@ def find_state(sha): | |||
def get_repo(repo_label, repo_cfg): | |||
repo = g.repos[repo_label].gh | |||
if not repo: | |||
g.repos[repo_label] = repo = g.gh.repository(repo_cfg['owner'], repo_cfg['name']) | |||
g.repos[repo_label] = repo = g.gh.repository(repo_cfg['owner'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it clearer to put each assignment on its own line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, this double assignment thingy bugged me too the first time I looked at it and then I split it totally wrong the second time. Thanks for pointing that out!
homu/server.py
Outdated
@@ -242,7 +255,7 @@ def github(): | |||
payload = request.body.read() | |||
info = request.json | |||
|
|||
lazy_debug(logger, lambda: 'info: {}'.format(utils.remove_url_keys_from_json(info))) | |||
lazy_debug(logger, lambda: 'info: {}'.format(utils.remove_url_keys_from_json(info))) # NOQA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're adding the #noqa comments, can you update the Travis file to prevent regressions by adding flake8 homu/server.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think #noqa works instead of #NOQA, which I find easier on the eyes (less shouty).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the # noqa
; I'll change those and use the more-legible variant in the future.
I'm doing basically the same thing to the rest of Homu this week, so that https://github.com/servo/homu/blob/master/.travis.yml#L10 in the Travis config can lose its --ignore E501
.
I stuffed #noqa in quite liberally where I'm not sure of the consistent or best way to breeak things up. Refactored out the constant calls to verify_auth because they were painfully redundant. I *think* we're universally calling git_cmd with the same first args, and also github_create_status could just take state instead of state.get_repo and state.head_sha, but I'll have to double check both of those in all their uses to be sure.
This is like 80% of the way to better, and I shook out a few redundant function calls in the process. I'd advocate for landing these changes promptly and ironing out the remaining inconsistencies during future refactors, because if I let this thing bitrot it'll be a real nightmare to fix up. Additionally I've allocated enough time this week to fix the damage that this prettiness refactor is doing to the handful of currently open PRs. @Manishearth, @aneeshusa, thoughts? |
@bors-servo r=larsbergstrom,aneeshusa |
📌 Commit 6868caf has been approved by |
Begin pep8 fixups Partial pep8ening to get some feedback on the various styles of breaking up long lines that I've been using. @larsbergstrom, @Manishearth, could I get you to skim the diff and comment on any changes that you feel are a step in the wrong direction? <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/homu/103) <!-- Reviewable:end -->
☀️ Test successful - status-travis |
Partial pep8ening to get some feedback on the various styles of breaking up long lines that I've been using.
@larsbergstrom, @Manishearth, could I get you to skim the diff and comment on any changes that you feel are a step in the wrong direction?
This change is