Codebase list pip-requirements-el / 0092e44
Import upstream version 0.5+git20181027.1.216cd16 Debian Janitor 2 years ago
4 changed file(s) with 40 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
0 .cask
2626 [Auto Complete]: https://github.com/auto-complete/auto-complete
2727
2828 ## Changelog
29
30 ### 0.6
31
32 Update pip-requirements completion to handle the move from
33 pypi.python.org to pypi.org (minor HTML difference broke our parsing).
2934
3035 ### 0.5
3136
33 baz>1,<2
44 python-dateutil>=1.5,<=2.1,!=2.0
55 backports.ssl-match-hostname==3.4.0.2
6
7 # https://www.python.org/dev/peps/pep-0440/#version-specifiers
8 quux~=1.2
9 xyx==1.2.*
10 abc===foobar
33 ;;
44 ;; Author: Wilfred Hughes <me@wilfred.me.uk>
55 ;; Created: 11 September 2014
6 ;; Version: 0.5
6 ;; Version: 0.6
77 ;; Package-Requires: ((dash "2.8.0"))
88
99 ;;; License:
5454 :type 'hook
5555 :risky t)
5656
57 (defcustom pip-requirements-index-url
58 "https://pypi.org/simple/"
59 "The URL used to fetch the list of packages used for completion."
60 :group 'pip-requirements
61 :type 'string)
62
5763 ;;;###autoload
5864 (add-to-list 'auto-mode-alist
5965 `(,(rx ".pip" string-end) . pip-requirements-mode))
7177 (group (1+ (or alphanumeric "-" "_" ".")))))
7278
7379 (defconst pip-requirements-version-regex
80 ;; https://www.python.org/dev/peps/pep-0440/#version-specifiers
7481 (rx
75 (group (or "==" ">" ">=" "<" "<=" "!="))
76 (group (1+ (or digit "b" "." "post")))))
82 (group (or "==" ">" ">=" "<" "<=" "!=" "~="))
83 (group (1+ (or digit "b" "." "post" "*")))))
84
85 (defconst pip-requirements-arbitrary-version-regex
86 ;; https://www.python.org/dev/peps/pep-0440/#arbitrary-equality
87 (rx (group "===") (group (1+ not-newline))))
7788
7889 (defconst pip-requirements-operators
7990 (list
8091 (list pip-requirements-name-regex 1 'font-lock-variable-name-face)
8192 (list pip-requirements-version-regex 1 'font-lock-builtin-face)
82 (list pip-requirements-version-regex 2 'font-lock-constant-face)))
93 (list pip-requirements-arbitrary-version-regex 1 'font-lock-builtin-face)
94 (list pip-requirements-version-regex 2 'font-lock-constant-face)
95 (list pip-requirements-arbitrary-version-regex 2 'font-lock-constant-face)))
8396
8497 (defconst pip-requirements-syntax-table
8598 (let ((table (make-syntax-table)))
8699 (modify-syntax-entry ?# "<" table)
87100 (modify-syntax-entry ?\n ">" table)
101 (modify-syntax-entry ?> "." table)
102 (modify-syntax-entry ?< "." table)
103 (modify-syntax-entry ?= "." table)
104 (modify-syntax-entry ?~ "." table)
88105 table))
89106
90107 (defvar pip-http-buffer nil)
97114 (goto-char (point-min))
98115 (re-search-forward "^$" nil 'move)
99116
100 (setq pip-packages
101 (->> (libxml-parse-html-region (point) (point-max))
102 ;; Get the body tag.
103 -last-item
104 ;; Immediate children of the body.
105 cdr cdr cdr
106 ;; Anchor tags.
107 (--filter (eq (car it) 'a))
108 ;; Inner text of anchor tags.
109 (-map #'cl-third))))
117 (let* ((dom (libxml-parse-html-region (point) (point-max)))
118 (body-tag (-last-item dom))
119 (body-children (cdddr body-tag))
120 (a-tags (--filter (eq (car-safe it) 'a) body-children)))
121 (setq pip-packages
122 ;; Inner text of anchor tags.
123 (-map #'cl-third a-tags))))
110124 (kill-buffer pip-http-buffer))
111125
112126 (defun pip-requirements-fetch-packages ()
113127 "Get a list of all packages available on PyPI and store them in `pip-packages'.
114128 Assumes Emacs is compiled with libxml."
115129 (setq pip-http-buffer
116 (url-retrieve "https://pypi.python.org/simple/"
130 (url-retrieve pip-requirements-index-url
117131 #'pip-requirements-callback nil t)))
118132
119133 (defun pip-requirements-complete-at-point ()