Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(formatters): add autopep8 #4

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

Merged
fowles merged 9 commits into google:master from actionless:add-autopep8
Jan 26, 2015
Merged

Conversation

@actionless
Copy link
Contributor

@actionless actionless commented Jan 23, 2015

mb it make sense to generalize them somehow?
because it's almost the same as gofmt one

Copy link
Contributor

Choose a reason for hiding this comment

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

the setup instructions seem to trail off

Copy link
Contributor

fowles commented Jan 23, 2015

It might make sense to generalize now that there is more than one.

Before merging any request you have we will need you to sign the CLA (contributor lisence agreement). Sorry the lawyercats are sticklers for this.

https://github.com/google/vim-codefmt/blob/master/CONTRIBUTING.md

Copy link
Contributor

Choose a reason for hiding this comment

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

autopep8 1.0 and later support --range line line, which will give much better results than this hack. Unfortunately, Ubuntu seems to be stuck on a version almost 2 years old (0.9.1) which doesn't support it, so I could see people being stuck on an old version without it. I just filed https://bugs.launchpad.net/ubuntu/+source/autopep8/+bug/1414258 asking Ubuntu to update.

Could you file a feature request along with these changes to support true range formatting, with this as a fallback? "autopep8 --version" runs pretty quick for me, so I don't think running that once per vim session to detect native range support would be a problem.

Copy link
Contributor Author

@actionless actionless Jan 24, 2015

Choose a reason for hiding this comment

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

how do u think it will be better to make that choice -- setting plugin.Flag manually or reading autopep --version output once and caching it?

Copy link
Contributor

Choose a reason for hiding this comment

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

If reading autopep8 --version works well, I'd go with that approach. Seems like it will.

Copy link
Contributor Author

@actionless actionless Jan 24, 2015

Choose a reason for hiding this comment

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

btw, while i gonna store cached value in Flag, then it will be possible to set it manually

or Flags are not suitable for such purpose and intended to be only for storing some default settings, but not any variable data?

Copy link
Contributor

Choose a reason for hiding this comment

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

Using a flag like that wouldn't be unreasonable, except I figured it should be lazy and flag initialization should be eager (once at plugin installation time). Even though it's a quick check, doing it for N formatters plus the executable() checks all at once might not be.

Copy link
Contributor Author

@actionless actionless Jan 24, 2015

Choose a reason for hiding this comment

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

i mean to add that version check not on plugin initialization but inside FormatRange function, like:

if !s:plugin.Flag('autopep8_version')
 s:plugin.Flag('autopep8_version', GetVersion())

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I thought lazy flag initialization like that might get confusing, but maybe not. Anyway, my vote would be to wait to add a flag until someone reports they need to override the behavior.

Copy link
Contributor Author

@actionless actionless Jan 25, 2015

Choose a reason for hiding this comment

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

am i understood right, you mean to initialize version flag like that but not to set it manually by default?

Copy link
Contributor

Choose a reason for hiding this comment

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

What I was suggesting is instead of using a flag, for now use a script-local variable like

let l:executable = s:plugin.Flag('autopep8_executable')
if !exists('s:autopep8_supports_range')
 let l:version_output =
 \ maktaba#syscall#Create([l:executable, '--version']).Call().stderr
 let s:autopep8_supports_range =
 \ matchlist(l:version_output, '\m\Cautopep8 \(\d\+\)\.')[1] >= 1
endif

Then, if for some reason a user reports the version check is not right for them and they'd rather configure it manually, it's easy to replace the script-local variable with flag operations.

Copy link
Contributor Author

@actionless actionless Jan 25, 2015

Choose a reason for hiding this comment

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

got it, thanks

Copy link
Contributor

There's a list of formatters on line 28 that should be updated to include python, and then if you can run vimdoc on it after that it will update the help file in doc/ to match.

Copy link
Contributor Author

@actionless actionless Jan 25, 2015

Choose a reason for hiding this comment

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

oops, just noticed what autopep8 don't output errors like that.

actually i am not even sure if it can return unsuccessful result when using stdin at all (when it faces wrong syntax or smth it is just ignoring it)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's fine to get rid of the try/catch and just let the ShellError bubble up. It's caught and handled in codefmt. You can add a @throws ShellError line into the vimdoc for good measure.

@actionless actionless force-pushed the add-autopep8 branch 2 times, most recently from 69c6c1e to 7a7b2c1 Compare January 26, 2015 15:25
Copy link
Contributor Author

i think it's ready for review

btw, i already signed CLA (you need my e-mail to verify it, or what?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment that the '-' argument means stdin and put the '-' at the end of the list of args (I got a bit confused by the '-', '--range' list)

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't find it too confusing, but it could be more obvious at a glance if the lines were broken up differently:

 let l:cmd = [
 \ l:executable,
 \ '--range', ''.a:startline, ''.a:endline,
 \ '-' ]

Matt, you still think a comment would be necessary like that? Was it more that you didn't notice the '-' or just didn't know what to make of it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't know what to make of it. I thought it was similar to the bash things
which say "all arguments after this one are files" which confused me and
sent me off to read the docs.

Matt
On Jan 26, 2015 11:51 AM, "David Barnett" notifications@github.com wrote:

In autoload/codefmt.vim
#4 (comment):

  • " @throws ShellError
  • function s:autopep8.FormatRange(startline, endline) abort
  • " Hack range formatting by formatting range individually, ignoring context.
  • let l:executable = s:plugin.Flag('autopep8_executable')
  • if !exists('s:autopep8_supports_range')
  •  let l:version_output =
    
  •  \ maktaba#syscall#Create([l:executable, '--version']).Call().stderr
    
  •  let s:autopep8_supports_range =
    
  •  \ matchlist(l:version_output, '\m\Cautopep8 (\d+).')[1] >= 1
    
  • endif
  • call maktaba#ensure#IsNumber(a:startline)
  • call maktaba#ensure#IsNumber(a:endline)
  • let l:lines = getline(1, line('$'))
  • if s:autopep8_supports_range

I didn't find it too confusing, but it could be more obvious at a glance
if the lines were broken up differently:

 let l:cmd = [
 \ l:executable,
 \ '--range', ''.a:startline, ''.a:endline,
 \ '-' ]

Matt, you still think a comment would be necessary like that? Was it more
that you didn't notice the '-' or just didn't know what to make of it?


Reply to this email directly or view it on GitHub
https://github.com/google/vim-codefmt/pull/4/files#r23544410.

Copy link
Contributor

fowles commented Jan 26, 2015

I am going to wait for dbarnett's LGTM because he knows vimscripts subtleties bettter than I do.

I see that you did sign the CLA, thanks for doing that! The good news is that the CLA is good for all google stuff (except android), so you won't ever have to bother with that again.

Copy link
Contributor

LGTM. You can merge when you're happy with the l:cmd part.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment on what cases you're handling here? To my eye the logic looks a little weird without any info about expected output.

BTW, it reads a little weird not having a space after the \.

Copy link
Contributor Author

@actionless actionless Jan 26, 2015

Choose a reason for hiding this comment

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

so as i described in commit message, in some configurations version is being output into stdout, in some others -- to stderr.
i have no clue why that happens (it seems what i have the same library versions on both PCs there i tested it, but maybe some different environment variables or smth)

yup, that's a typo, i will fix it

fowles added a commit that referenced this pull request Jan 26, 2015
Add support for python via autopep8.
@fowles fowles merged commit 65fc13a into google:master Jan 26, 2015
Copy link
Contributor

fowles commented Jan 26, 2015

Thanks for the great patch!

@actionless actionless deleted the add-autopep8 branch January 26, 2015 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /