diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6fddd6..21f57cd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -76,6 +76,16 @@ package-oni-php: paths: - oni-php/dist/ +package-oni-python: + stage: pre-package-multifile + before_script: + - rm -rf oni-elisp/dist + script: + - cask --path oni-python package + artifacts: + paths: + - oni-python/dist/ + test-oni-alert: stage: test script: make test-oni-alert @@ -130,6 +140,7 @@ package: - package-oni-html - package-oni-nxml - package-oni-php + - package-oni-python before_script: - rm -rf bin/ - mkdir bin/ diff --git a/GNUmakefile b/GNUmakefile index 36b22e8..557aa2a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,7 +4,7 @@ PACKAGE_TARGETS := $(addprefix package-,$(FILES)) package: $(PACKAGE_TARGETS) package-oni-conf package-oni-css package-oni-elisp \ package-oni-haml package-oni-html package-oni-nxml package-oni-org \ - package-oni-php + package-oni-php package-oni-python package-%: % emacs --batch \ @@ -60,6 +60,12 @@ package-oni-php: --funcall package-initialize \ --eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-php/dist/*.tar\") #'string>)))" +package-oni-python: + emacs --batch \ + --load oni-package.el \ + --funcall package-initialize \ + --eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-python/dist/*.tar\") #'string>)))" + install-%: emacs --batch \ --load oni-package.el \ @@ -132,6 +138,14 @@ install-oni-php: $(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \ --eval "(package-install-file (car (sort (file-expand-wildcards \"oni-php/dist/*.tar\") #'string>)))" +install-oni-python: + emacs --batch \ + --load oni-package.el \ + --fluncall package-initialize \ + --eval '(package-refresh-contents)' \ + $(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \ + --eval "(package-install-file (car (sort (file-expand-wildcards \"oni-python/dist/*.tar\") #'string>)))" + test-%: install-% emacs --batch \ --load oni-package.el \ diff --git a/oni-python/Cask b/oni-python/Cask new file mode 100644 index 0000000..fe11bbd --- /dev/null +++ b/oni-python/Cask @@ -0,0 +1,18 @@ +(source gnu) +(source melpa) + +(package-file "./oni-python.el") + +(depends-on "oni-yasnippet" :git "../" :files ("oni-yasnippet.el")) +(depends-on "oni-company" :git "../" :files ("oni-company.el")) +(depends-on "company-jedi") +(depends-on "oni-fci" :git "../" :files ("oni-fci.el")) +(depends-on "oni-flycheck" :git "../" :files ("oni-flycheck.el")) +(depends-on "rainbow-delimiters") +(depends-on "reformatter") +(depends-on "traad") +(depends-on "hydra") + +(files + "*.el" + ("snippets" "./snippets/*")) diff --git a/oni-python.el b/oni-python/oni-python.el similarity index 76% rename from oni-python.el rename to oni-python/oni-python.el index 053bbc5..9be51f8 100644 --- a/oni-python.el +++ b/oni-python/oni-python.el @@ -4,8 +4,8 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 20190710075756 -;; Package-Requires: (oni-company company-jedi oni-fci oni-flycheck rainbow-delimiters reformatter traad hydra) +;; Version: 20190828000139 +;; Package-Requires: (oni-yasnippet oni-company company-jedi oni-fci oni-flycheck rainbow-delimiters reformatter traad hydra) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -40,9 +40,20 @@ (require 'reformatter) (require 'traad) (require 'whitespace) +(require 'yasnippet) (autoload 'hl-indent-mode "hl-indent-mode") +(defconst oni-python-root + (file-name-directory + (or load-file-name + (buffer-file-name))) + "The directory where ‘oni-python’ was loaded from.") + +(defconst oni-python-snippets-dir + (expand-file-name "snippets" oni-python-root) + "The directory where ‘oni-python’ stores its snippets.") + (defun oni-python-set-fill-column () "Set the `fill-column' and `comment-fill-column' for the current buffer. @@ -50,6 +61,13 @@ The values are taken from the PEP8 coding standard for Python." (setq-local fill-column 80) (setq-local comment-fill-column 72)) +;;;###autoload +(defun oni-python-snippets-initialize () + "Initialize the snippets for ‘oni-python’." + (when (boundp 'yas-snippet-dirs) + (add-to-list 'yas-snippet-dirs oni-python-snippets-dir)) + (yas-load-directory oni-python-snippets-dir)) + (defun oni-python-whitespace-mode () "Set the `whitespace-style' to show the relevat whitespace. In Python buffers it should show any tabs being used and and used @@ -81,6 +99,11 @@ for indentation." (add-hook 'python-mode-hook 'oni-python-set-fill-column) (add-hook 'python-mode-hook 'oni-python-whitespace-mode) +;;;###autoload +(with-eval-after-load 'python + (with-eval-after-load 'yasnippet + (oni-python-snippets-initialize))) + ;;;###autoload(with-eval-after-load 'python (require 'oni-python)) (provide 'oni-python) diff --git a/oni-python/snippets/python-mode/defm_empty b/oni-python/snippets/python-mode/defm_empty new file mode 100644 index 0000000..baa976e --- /dev/null +++ b/oni-python/snippets/python-mode/defm_empty @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# name: Empty Defmethod +# key: defm +# -- +def ${1:name}(self, *args, **kwargs): + '''$2''' + return super(${3:`(progn (re-search-backward "^[ \t]*class \\(.+\\)(") (match-string 1)))`}, self).$1(*args, **kwargs) \ No newline at end of file diff --git a/oni-python/snippets/python-mode/form b/oni-python/snippets/python-mode/form new file mode 100644 index 0000000..225d5e4 --- /dev/null +++ b/oni-python/snippets/python-mode/form @@ -0,0 +1,9 @@ +# -*- mode: snippet -*- +# name: Model Form +# key: form +# -- +class ${1:Model}Form(forms.ModelForm): + '''Form for the $1 model.''' + + class Meta: + model = $1 \ No newline at end of file diff --git a/oni-python/snippets/python-mode/form_valid b/oni-python/snippets/python-mode/form_valid new file mode 100644 index 0000000..c5a7e58 --- /dev/null +++ b/oni-python/snippets/python-mode/form_valid @@ -0,0 +1,8 @@ +# -*- mode: snippet -*- +# name: Record form +# key: defm +# -- +@record_activity(model=${1:`(progn (re-search-backward "^[ \t]*model = \\([a-zA-Z_].*\\)$") (match-string 1))`}) +def form_valid(self, form): + '''Make sure any changes to the $1 model get logged.''' + return super(${2:`(progn (re-search-backward "^[ \t]*class \\(.+\\)(") (match-string 1)))`}, self).form_valid(form) \ No newline at end of file diff --git a/oni-python/snippets/python-mode/form_valid_with_return b/oni-python/snippets/python-mode/form_valid_with_return new file mode 100644 index 0000000..fac23bc --- /dev/null +++ b/oni-python/snippets/python-mode/form_valid_with_return @@ -0,0 +1,8 @@ +# -*- mode: snippet -*- +# name: form_valid with return +# key: formvalid +# -- +def form_valid(self, form): + rv = super(`(let ((name (python-info-current-defun))) (substring name 0 (cl-position ?. name)))`, self).form_valid(form) + $0 + return rv \ No newline at end of file diff --git a/oni-python/snippets/python-mode/import_from b/oni-python/snippets/python-mode/import_from new file mode 100644 index 0000000..d9cc4e2 --- /dev/null +++ b/oni-python/snippets/python-mode/import_from @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# name: from ... import ... +# contributor: Tom Willemse +# key: from +# -- +from ${1:module} import ${2:class_or_module} diff --git a/oni-python/snippets/python-mode/method b/oni-python/snippets/python-mode/method new file mode 100644 index 0000000..7c033cf --- /dev/null +++ b/oni-python/snippets/python-mode/method @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# name: method +# key: defm +# -- +def $1(self$2): + '''$3''' + $0 \ No newline at end of file diff --git a/oni-python/snippets/python-mode/permission_guard b/oni-python/snippets/python-mode/permission_guard new file mode 100644 index 0000000..ab53895 --- /dev/null +++ b/oni-python/snippets/python-mode/permission_guard @@ -0,0 +1,9 @@ +# -*- mode: snippet -*- +# name: Permission guard +# key: defm +# -- +@method_decorator(permission_required('$1', + raise_exception=True)) +def dispatch(self, *args, **kwargs): + '''Make sure the user has the $1 permission.''' + return super(${3:`(progn (re-search-backward "^[ \t]*class \\(.+\\)(") (match-string 1)))`}, self).dispatch(*args, **kwargs) \ No newline at end of file diff --git a/oni-python/snippets/python-mode/url b/oni-python/snippets/python-mode/url new file mode 100644 index 0000000..00ade72 --- /dev/null +++ b/oni-python/snippets/python-mode/url @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: url +# key: url +# -- +url(r'^$1', $2, name='$3'), \ No newline at end of file