Skip to content

Reformat with YAPF #11956

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

Closed

Conversation

jorisvandenbossche
Copy link
Member

Just as an example (using the default configuration). The same files are adjusted as in #11951

@jreback jreback added the Code Style Code style, linting, code_checks label Jan 4, 2016
@wesm
Copy link
Member

wesm commented Jan 4, 2016

Oof, the handling of long strings inside exceptions is pretty ugly, would benefit from manual fixes. Is there any way to get it to automatically fix them?

e.g.

raise ValueError("this is a really long message"
                 " and continued here")

@jorisvandenbossche
Copy link
Member Author

Not sure, I just quickly tried it with the default settings. There are some configuration options: https://github.com/google/yapf#knobs
And I suppose you could change some of the penalties, but of course that will apply to all opening brackets, and not only to exceptions.

@jreback
Copy link
Contributor

jreback commented Jan 6, 2016

where are we on this @jorisvandenbossche is this 'enough' to make a default formatter?

@wesm
Copy link
Member

wesm commented Jan 6, 2016

I think we can use yapf for "fixing" code but I don't think we should use it on any automated basis. The output I see here would need quite a bit of manual fixing (cleaning up long strings in particular)

@jreback
Copy link
Contributor

jreback commented Jan 6, 2016

right. I think we are ok with the flake8 checks via Travis CI. I just want to document a 'method' of how people should go about conforming to our standard. A configurable tool is prob the best bet here (if it gets most of the way there). I was personally using autopep8 then manually fixing things. Happy to move to this tool.

@wesm
Copy link
Member

wesm commented Jan 6, 2016

I actually think it's good for people to fix their code manually (using flake8 on the command line) as a "learn good style the hard way" -- after a while (at least for me) you stop making style errors as you code.

@wesm
Copy link
Member

wesm commented Jan 6, 2016

I have this in my .emacs which show up red when I have flake8 problems

(add-hook 'python-mode-hook
      '(lambda ()
         (define-key python-mode-map "\C-m" 'newline-and-indent)
         (pylint-python-hook)
         (flymake-mode)
         (define-key python-mode-map "\M-n" 'flymake-goto-next-error)
         (define-key python-mode-map "\M-p" 'flymake-goto-prev-error)
))


;; Configure flymake for python
(when (load "flymake" t)
  (defun flymake-pylint-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-inplace))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
      (list "flake8" (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
               '("\\.py\\'" flymake-pylint-init)))

@jreback
Copy link
Contributor

jreback commented Jan 6, 2016

ok with that as well. maybe we need to provide more config for flake8? (its already in setup.cfg)

not sure if you can control the backslash breaking (versus parens)

@wesm
Copy link
Member

wesm commented Jan 7, 2016

We should put instructions in the developer docs. I looked through flake8 and I didn't see an option to check for usage of backslashes, so we may need to periodically review the codebase for cases that don't get caught during code review

@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

closing in favor of #11951

@jreback jreback closed this Jan 7, 2016
@hayd
Copy link
Contributor

hayd commented Jan 7, 2016

How long did it take to run yapf on pandas? I remember it being super slow. In fact: google/yapf#96

@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

that is crazy long for that file, very weird! flaking it only takes a second (500 errors though :<)

@jorisvandenbossche
Copy link
Member Author

@hayd It was only a matter of seconds, but only tested on these 3 files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants