Fix some bugs in python linting on devserver

This commit is contained in:
John Doty 2017-03-15 08:25:50 -07:00
parent 2d92526d24
commit de8429de5d
5 changed files with 155 additions and 51 deletions

View file

@ -124,6 +124,9 @@
'tss ; Typescript, ala https://github.com/aki2o/emacs-tss 'tss ; Typescript, ala https://github.com/aki2o/emacs-tss
'web-mode ; Mixed mode web editing 'web-mode ; Mixed mode web editing
'zencoding-mode ; http://www.emacswiki.org/emacs/ZenCoding 'zencoding-mode ; http://www.emacswiki.org/emacs/ZenCoding
'tuareg ; ocaml
'merlin ; ocaml completion stuff
) )
"Libraries that should be installed by default.") "Libraries that should be installed by default.")
@ -606,7 +609,7 @@
(flycheck-define-checker python-fb-flake8 (flycheck-define-checker python-fb-flake8
"A Python syntax and style checker using FB's Flake8." "A Python syntax and style checker using FB's Flake8."
:command ("flake8") :command ("flake8" source-original)
:standard-input nil :standard-input nil
:error-filter (lambda (errors) :error-filter (lambda (errors)
(let ((errors (flycheck-sanitize-errors errors))) (let ((errors (flycheck-sanitize-errors errors)))
@ -614,11 +617,12 @@
errors)) errors))
:error-patterns :error-patterns
((warning line-start ((warning line-start
"stdin:" line ":" (optional column ":") " " (file-name) ":" line ":" (optional column ":") " "
(id (one-or-more (any alpha)) (one-or-more digit)) " " (id (one-or-more (any alpha)) (one-or-more digit)) " "
(message (one-or-more not-newline)) (message (one-or-more not-newline))
line-end)) line-end))
:modes python-mode) :modes python-mode)
(add-to-list 'flycheck-checkers 'python-fb-flake8)
(when is-fb-environment (when is-fb-environment
(add-hook 'python-mode-hook (add-hook 'python-mode-hook
@ -843,5 +847,10 @@
;; ;;
(global-set-key (kbd "C-/") 'comment-or-uncomment-region) (global-set-key (kbd "C-/") 'comment-or-uncomment-region)
;; =================================================================
;; OCAML stuff
;; =================================================================
(require 'opam-user-setup "~/.emacs.d/opam-user-setup.el")
(provide 'core) (provide 'core)
;;; core.el ends here ;;; core.el ends here

View file

@ -33,11 +33,17 @@
'(js2-strict-trailing-comma-warning nil) '(js2-strict-trailing-comma-warning nil)
'(make-backup-files nil) '(make-backup-files nil)
'(mouse-buffer-menu-mode-mult 0) '(mouse-buffer-menu-mode-mult 0)
'(org-export-with-toc nil)
'(org-hide-leading-stars t) '(org-hide-leading-stars t)
'(org-odd-levels-only t) '(org-odd-levels-only t)
'(org-todo-keywords
(quote
((sequence "TODO" "|" "DONE" "ABANDONED" "DEFERRED"))))
'(package-selected-packages '(package-selected-packages
(quote (quote
(dockerfile-mode js2-mode ## web-mode ahg zencoding-mode tss switch-window python-mode paredit monky magit lua-mode go-mode go-autocomplete flycheck exec-path-from-shell csharp-mode color-theme-solarized color-theme-monokai auto-complete-nxml))) (merlin tuareg markdown-mode thrift dockerfile-mode js2-mode ## web-mode ahg zencoding-mode tss switch-window python-mode paredit monky magit lua-mode go-mode go-autocomplete flycheck exec-path-from-shell csharp-mode color-theme-solarized color-theme-monokai auto-complete-nxml)))
'(quip-api-key
"UU9RQU1Ba0pjR08=|1517609175|FmwD/EJT5K//+ntQqzVopKmzq/juUmBQsS2hsNi8MeQ=")
'(rmail-mail-new-frame t) '(rmail-mail-new-frame t)
'(safe-local-variable-values '(safe-local-variable-values
(quote (quote

View file

@ -1,33 +1,39 @@
;;; ox-quip.el -- Publish from org-mode to Quip.
;;; Commentary:
;; Publisher from org-mode to Quip. (Export as markdown, push as a new ;; Publisher from org-mode to Quip. (Export as markdown, push as a new
;; thread or amend to existing quip thread.) ;; thread or amend to existing quip thread.)
;;; Code:
(require 'cl-extra) (require 'cl-extra)
(require 'ox-md) (require 'ox-md)
(require 'quip-api) (require 'quip)
(defun org-quip--get-thread-identifier ()
(defun org-quip-get-thread-identifier () "Get the Quip thread identifier from the doc in the current buffer, if any."
(org-entry-get nil "quip-id" t)) (org-entry-get nil "quip-id" t))
(defun org-quip-put-thread-identifier (identifier) (defun org-quip--put-thread-identifier (identifier)
"Put the Quip thread identifier in IDENTIFIER into the doc."
(save-excursion (save-excursion
(while (org-up-heading-safe)) (while (org-up-heading-safe))
(org-entry-put nil "quip-id" identifier))) (org-entry-put nil "quip-id" identifier)))
(defun org-quip-publish-quip (content) (defun org-quip--publish-quip (content)
"Publish content as a new Quip document. Returns the ID of the new document." "Publish CONTENT as a new Quip document. Return the ID of the new document."
(let ((response (quip-new-document content))) (let ((response (quip-new-document content)))
(cdr (assoc 'id (cdr (assoc 'thread response)))))) (cdr (assoc 'id (cdr (assoc 'thread response))))))
(defun org-quip-publish-to-quip () (defun org-quip-publish-to-quip ()
"Publish the current buffer to Quip."
(interactive) (interactive)
(let (let
((quip-id (org-quip-get-thread-identifier)) ((quip-id (org-quip--get-thread-identifier))
(content (org-export-as 'md))) (content (org-export-as 'md)))
(if quip-id (if quip-id
(org-quip-update-quip quip-id content) (org-quip-update-quip quip-id content)
(let ((new-quip-id (org-quip-publish-quip content))) (let ((new-quip-id (org-quip--publish-quip content)))
(org-quip-put-thread-identifier new-quip-id))))) (org-quip--put-thread-identifier new-quip-id)))))
;; ;;
@ -50,3 +56,4 @@
(provide 'ox-quip) (provide 'ox-quip)
;;; ox-quip.el ends here

View file

@ -1,19 +1,33 @@
;; Quip API ;;; quip.el --- Quip API client for emacs -*- lexical-binding: t; -*-
;;; Commentary:
(require 'cl-extra) ;;; Code:
(require 'cl-lib)
(require 'json) (require 'json)
(require 'url) (require 'url)
;; Customization groups ;; Customization groups
(defgroup quip-api nil (defgroup quip-api nil
"Customization options for using the Quip API") "Customization options for using the Quip API"
:prefix "quip-"
:group 'external
:tag "Quip")
(defcustom quip-api-key nil (defcustom quip-api-key ""
"Your API key for Quip. Get it from https://fb.quip.com/api/personal-token" "Your API key for Quip.
:type 'string)
Get it from https://fb.quip.com/api/personal-token."
:type 'string
:group 'quip-api)
(defun quip-invoke-json (path method params) (defun quip-invoke-json (path method params)
"Submit a request to the Quip API. Returns the parsed JSON from the response." "Make a request to the Quip API, and return the parsed JSON from the response.
A Quip API call involves issuing an HTTP request to path PATH,
with method METHOD, and parameters PARAMS. This routine knows the
base URL and adds the necessary headers."
(if (not quip-api-key) (if (not quip-api-key)
(error "%s" (error "%s"
"The custom variable quip-api-key is undefined. Use custom-set-variable to set it before using quip.")) "The custom variable quip-api-key is undefined. Use custom-set-variable to set it before using quip."))
@ -32,14 +46,18 @@
(json-read)))) (json-read))))
(defun quip-new-document (content &optional format) (defun quip-new-document (content &optional format)
"Create a new Quip document with the provided content. Returns the parsed JSON response." "Create a new Quip document with the provided CONTENT.
This function returns the parsed JSON response. The optional
FORMAT argument is one of 'html' or 'markdown', and indicates
that the content should be interpreted as such."
(quip-invoke-json "threads/new-document" (quip-invoke-json "threads/new-document"
"POST" "POST"
`((format . ,(or format "markdown")) `((format . ,(or format "markdown"))
(content . ,content)))) (content . ,content))))
(defun quip-get-thread (id) (defun quip-get-thread (id)
"Get the Quip thread with the specified ID. Returns the parsed JSON response." "Get the Quip thread with the specified ID. Return the parsed JSON response."
(quip-invoke-json (concat "threads/" id) "GET" nil)) (quip-invoke-json (concat "threads/" id) "GET" nil))
(defconst quip-location-append 0) (defconst quip-location-append 0)
@ -50,7 +68,11 @@
(defconst quip-location-delete-section 5) (defconst quip-location-delete-section 5)
(defun quip-thread-append (thread content &optional format) (defun quip-thread-append (thread content &optional format)
"Append the content to the specified thread." ; checkdoc-order: nil
"Append CONTENT to the specified THREAD.
The optional FORMAT argument is one of 'html' or 'markdown', and
indicates how the content is to be interpreted."
(quip-invoke-json "threads/edit-document" (quip-invoke-json "threads/edit-document"
"POST" "POST"
`((format . ,(or format "markdown")) `((format . ,(or format "markdown"))
@ -59,7 +81,11 @@
(thread_id . ,thread)))) (thread_id . ,thread))))
(defun quip-thread-prepend (thread content &optional format) (defun quip-thread-prepend (thread content &optional format)
"Prepend the content to the specified thread." ; checkdoc-order: nil
"Prepend CONTENT to the specified THREAD.
The optional FORMAT argument is one of 'html' or 'markdown', and
indicates how the content is to be interpreted."
(quip-invoke-json "threads/edit-document" (quip-invoke-json "threads/edit-document"
"POST" "POST"
`((format . ,(or format "markdown")) `((format . ,(or format "markdown"))
@ -68,27 +94,43 @@
(thread_id . ,thread)))) (thread_id . ,thread))))
(defun quip-thread-append-after (thread section content &optional format) (defun quip-thread-append-after (thread section content &optional format)
"Append the content to the specified thread after the specified section." ; checkdoc-order: nil
"Append CONTENT to specified SECTION in the specified THREAD.
The content is appended after the specified section.
The optional FORMAT argument is one of 'html' or 'markdown', and
indicates how the content is to be interpreted."
(quip-invoke-json "threads/edit-document" (quip-invoke-json "threads/edit-document"
"POST" "POST"
`((format . ,(or format "markdown")) `((format . ,(or format "markdown"))
(content . ,content) (content . ,content)
(location . ,quip-location-append-section) (location . ,quip-location-after-section)
(section_id . ,section) (section_id . ,section)
(thread_id . ,thread)))) (thread_id . ,thread))))
(defun quip-thread-prepend-before (thread section content &optional format) (defun quip-thread-prepend-before (thread section content &optional format)
"Prepend the content to the specified thread before the specified section." ; checkdoc-order: nil
"Prepend CONTENT to the specified SECTION of THREAD.
The content is added before the specified section.
The optional FORMAT argument is one of 'html' or 'markdown', and
indicates how the content is to be interpreted."
(quip-invoke-json "threads/edit-document" (quip-invoke-json "threads/edit-document"
"POST" "POST"
`((format . ,(or format "markdown")) `((format . ,(or format "markdown"))
(content . ,content) (content . ,content)
(location . ,quip-location-prepend-section) (location . ,quip-location-before-section)
(section_id . ,section) (section_id . ,section)
(thread_id . ,thread)))) (thread_id . ,thread))))
(defun quip-thread-replace-section (thread section content &optional format) (defun quip-thread-replace-section (thread section content &optional format)
"Replace the content of the specified section." ; checkdoc-order: nil
"Replace the specified SECTION of THREAD with the specified CONTENT.
The optional FORMAT argument is one of 'html' or 'markdown', and
indicates how the content is to be interpreted."
(quip-invoke-json "threads/edit-document" (quip-invoke-json "threads/edit-document"
"POST" "POST"
`((format . ,(or format "markdown")) `((format . ,(or format "markdown"))
@ -97,13 +139,12 @@
(section_id . ,section) (section_id . ,section)
(thread_id . ,thread)))) (thread_id . ,thread))))
(defun quip-thread-delete-section (thread section &optional format) (defun quip-thread-delete-section (thread section)
"Delete the specified section." ; checkdoc-order: nil
"Delete the specified SECTION of THREAD."
(quip-invoke-json "threads/edit-document" (quip-invoke-json "threads/edit-document"
"POST" "POST"
`((format . ,(or format "markdown")) `((location . ,quip-location-delete-section)
(content . ,content)
(location . ,quip-location-delete-section)
(section_id . ,section) (section_id . ,section)
(thread_id . ,thread)))) (thread_id . ,thread))))
@ -111,8 +152,8 @@
;;; Content parsing functions ;;; Content parsing functions
(defun quip-get-item-type (item) (defun quip-get-item-type (item)
(let ((elem-type (car item)) "Classify the specified HTML ITEM."
(attribs (cadr item))) (let ((elem-type (car item)))
(cond (cond
((eq elem-type 'p) 'paragraph) ((eq elem-type 'p) 'paragraph)
((eq elem-type 'h1) 'h1) ((eq elem-type 'h1) 'h1)
@ -124,8 +165,7 @@
((eq elem-type 'li) 'list-item) ((eq elem-type 'li) 'list-item)
((eq elem-type 'span) 'span) ((eq elem-type 'span) 'span)
((eq elem-type 'div) ((eq elem-type 'div)
(letrec ((style (assoc-default 'data-section-style attribs)) (letrec ((inner (cl-caddr item))
(inner (caddr item))
(inner-elem-type (car inner))) (inner-elem-type (car inner)))
(cond (cond
((eq inner-elem-type 'ul) 'ul) ((eq inner-elem-type 'ul) 'ul)
@ -133,40 +173,49 @@
(t 'unrecognized-inner)))) (t 'unrecognized-inner))))
(t 'unrecognized)))) (t 'unrecognized))))
(defun quip-get-item-id (type item) (defun quip-get-item-id (item type)
"Extract the ID from the provided ITEM given its TYPE."
(let ((attribs (cadr item))) (let ((attribs (cadr item)))
(cond (cond
((or (eq type 'ul) ;; Nested IDs. ((or (eq type 'ul) ;; Nested IDs.
(eq type 'ol)) (eq type 'ol))
(letrec ((inner (caddr item)) (letrec ((inner (cl-caddr item))
(inner-attribs (cadr inner))) (inner-attribs (cadr inner)))
(assoc-default 'id inner-attribs))) (assoc-default 'id inner-attribs)))
(t (assoc-default 'id attribs))))) (t (assoc-default 'id attribs)))))
(defun quip-get-item-content (type item) (defun quip-get-item-content (item type)
"Extract the content from the provided ITEM given its TYPE."
(cond (cond
((or (eq type 'ul) ;; Nested Content ((or (eq type 'ul) ;; Nested Content
(eq type 'ol)) (eq type 'ol))
(letrec ((inner (caddr item)) (letrec ((inner (cl-caddr item))
(inner-elems (cddr inner))) (inner-elems (cddr inner)))
(mapcar #'quip-get-item-from-element inner-elems))) (mapcar #'quip-get-item-from-element inner-elems)))
(t (caddr item)))) (t (cl-caddr item))))
(cl-defstruct quip-item type id content)
(defun quip-get-item-from-element (element) (defun quip-get-item-from-element (element)
"Construct a (type, id, content) list from the given ELEMENT."
(letrec (letrec
((item-type (quip-get-item-type element)) ((item-type (quip-get-item-type element))
(item-id (quip-get-item-id item-type element)) (item-id (quip-get-item-id element item-type))
(item-content (quip-get-item-content item-type element))) (item-content (quip-get-item-content element item-type)))
`(,item-type ,item-id ,item-content))) (make-quip-item
:type item-type
:id item-id
:content item-content)))
(defun quip-parse-html-content (content) (defun quip-parse-html-content (html)
"Parse the provided HTML into a list of (type, item, content) lists."
(with-temp-buffer (with-temp-buffer
(insert content) (insert html)
(letrec (letrec
((html (libxml-parse-html-region (point-min) (point-max))) ((parsed-html (libxml-parse-html-region (point-min) (point-max)))
(raw-items (cddr (caddr html))) (raw-items (cddr (cl-caddr parsed-html)))
(html-items (remove-if #'stringp raw-items))) (html-items (cl-remove-if #'stringp raw-items)))
(mapcar #'quip-get-item-from-element html-items) (mapcar #'quip-get-item-from-element html-items)
))) )))
@ -175,4 +224,5 @@
;; (quip-parse-html-content ;; (quip-parse-html-content
;; (assoc-default 'html (quip-get-thread "idflAWG6R6Uu")))) ;; (assoc-default 'html (quip-get-thread "idflAWG6R6Uu"))))
(provide 'quip-api) (provide 'quip)
;;; quip.el ends here

32
.vimrc
View file

@ -91,3 +91,35 @@ if !exists(":DiffOrig")
\ | wincmd p | diffthis \ | wincmd p | diffthis
endif endif
" ## added by OPAM user-setup for vim / base ## 93ee63e278bdfc07d1139a748ed3fff2 ## you can edit, but keep this line
let s:opam_share_dir = system("opam config var share")
let s:opam_share_dir = substitute(s:opam_share_dir, '[\r\n]*$', '', '')
let s:opam_configuration = {}
function! OpamConfOcpIndent()
execute "set rtp^=" . s:opam_share_dir . "/ocp-indent/vim"
endfunction
let s:opam_configuration['ocp-indent'] = function('OpamConfOcpIndent')
function! OpamConfOcpIndex()
execute "set rtp+=" . s:opam_share_dir . "/ocp-index/vim"
endfunction
let s:opam_configuration['ocp-index'] = function('OpamConfOcpIndex')
function! OpamConfMerlin()
let l:dir = s:opam_share_dir . "/merlin/vim"
execute "set rtp+=" . l:dir
endfunction
let s:opam_configuration['merlin'] = function('OpamConfMerlin')
let s:opam_packages = ["ocp-indent", "ocp-index", "merlin"]
let s:opam_check_cmdline = ["opam list --installed --short --safe --color=never"] + s:opam_packages
let s:opam_available_tools = split(system(join(s:opam_check_cmdline)))
for tool in s:opam_packages
" Respect package order (merlin should be after ocp-index)
if count(s:opam_available_tools, tool) > 0
call s:opam_configuration[tool]()
endif
endfor
" ## end of OPAM user-setup addition for vim / base ## keep this line