Skip to content

Commit c567561

Browse files
committedFeb 26, 2021
use Eldev and test.
1 parent 1a15b79 commit c567561

File tree

5 files changed

+69
-46
lines changed

5 files changed

+69
-46
lines changed
 

‎.github/workflows/ci.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
push:
55
paths-ignore:
66
- '**.md'
7+
pull_request:
8+
paths-ignore:
9+
- '**.md'
710

811
jobs:
912
build:
@@ -19,10 +22,17 @@ jobs:
1922
- snapshot
2023

2124
steps:
22-
- uses: purcell/setup-emacs@master
25+
- name: Setup GNU Emacs
26+
uses: purcell/setup-emacs@master
2327
with:
2428
version: ${{ matrix.emacs_version }}
2529

26-
- uses: actions/checkout@v2
27-
- name: Byte compile
28-
run: make
30+
- name: Install Eldev
31+
run: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/github-eldev | sh
32+
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
36+
- name: Test
37+
run: |
38+
eldev -p -dtT test

‎Eldev

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; -*- mode: emacs-lisp; lexical-binding: t; no-byte-compile: t -*-
2+
3+
;; Autodetermined by `eldev init'.
4+
(eldev-use-package-archive 'melpa)
5+
6+
(eldev-use-plugin 'autoloads)

‎Makefile

-31
This file was deleted.

‎numpydoc.el

+19-11
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,23 @@ The argument takes on one of four possible styles:
153153
(setq cursor i)))))
154154
(setq strs (append strs (list (substring fnargs (1+ cursor)))))))
155155

156-
(defun numpydoc--parse-def ()
157-
"Parse a Python function definition; return instance of numpydoc--def."
156+
157+
(defun numpydoc--extract-def ()
158+
"Extract function definition string from the buffer.
159+
This function expects the cursor to be in the function body."
160+
(save-excursion
161+
(buffer-substring-no-properties
162+
(progn
163+
(python-nav-beginning-of-defun)
164+
(point))
165+
(progn
166+
(python-nav-end-of-statement)
167+
(point)))))
168+
169+
(defun numpydoc--parse-def (buffer-substr)
170+
"Parse the BUFFER-SUBSTR; return instance of numpydoc--def."
158171
(save-excursion
159-
(let* ((fnsig (buffer-substring-no-properties
160-
(progn
161-
(python-nav-beginning-of-defun)
162-
(point))
163-
(progn
164-
(python-nav-end-of-statement)
165-
(point))))
172+
(let* ((fnsig buffer-substr)
166173
;; trimmed string of the function signature
167174
(trimmed (s-collapse-whitespace fnsig))
168175
;; split into parts (args and return type)
@@ -357,7 +364,8 @@ MODES is the list of modes where the function is interactive in
357364
(defun numpydoc-generate ()
358365
"Generate NumPy style docstring for Python function."
359366
(numpydoc--interactive nil python-mode)
360-
(let ((good-to-go t))
367+
(let ((good-to-go t)
368+
(fnsig (numpydoc--extract-def)))
361369
(when (numpydoc--has-existing-docstring-p)
362370
(if (y-or-n-p "Docstring exists; destroy and start new? ")
363371
(numpydoc--delete-existing)
@@ -366,7 +374,7 @@ MODES is the list of modes where the function is interactive in
366374
(python-nav-beginning-of-defun)
367375
(python-nav-end-of-statement)
368376
(numpydoc--insert-docstring (numpydoc--detect-indent)
369-
(numpydoc--parse-def)))))
377+
(numpydoc--parse-def fnsig)))))
370378

371379
(provide 'numpydoc)
372380
;;; numpydoc.el ends here

‎tests/test-numpydoc.el

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(require 'buttercup)
2+
(require 'numpydoc)
3+
4+
(defvar fsig1
5+
"def f(a: int, b: float = 5.5, c: Optional[Union[str, int]] = None) -> float:")
6+
7+
(defvar fsig2 "def f(x, y=5, z=None):")
8+
9+
(describe "Arg check"
10+
(it "Checks arg parsing 1"
11+
(let ((manual-a (make-numpydoc--arg :name "a" :type "int" :defval nil))
12+
(manual-b (make-numpydoc--arg :name "b" :type "float" :defval "5.5"))
13+
(manual-c (make-numpydoc--arg :name "c"
14+
:type "Optional[Union[str, int]]"
15+
:defval "None"))
16+
(parsed (numpydoc--parse-def fsig1)))
17+
(expect manual-a :to-equal (car (numpydoc--def-args parsed)))
18+
(expect manual-b :to-equal (nth 1 (numpydoc--def-args parsed)))
19+
(expect manual-c :to-equal (nth 2 (numpydoc--def-args parsed)))
20+
(expect "float" :to-equal (numpydoc--def-rtype parsed))))
21+
22+
(it "Checks arg parsing 2"
23+
(let ((manual-x (make-numpydoc--arg :name "x" :type nil :defval nil))
24+
(manual-y (make-numpydoc--arg :name "y" :type nil :defval "5"))
25+
(manual-z (make-numpydoc--arg :name "z" :type nil :defval "None"))
26+
(parsed (numpydoc--parse-def fsig2)))
27+
(expect manual-x :to-equal (car (numpydoc--def-args parsed)))
28+
(expect manual-y :to-equal (nth 1 (numpydoc--def-args parsed)))
29+
(expect manual-z :to-equal (nth 2 (numpydoc--def-args parsed)))
30+
(expect (numpydoc--def-rtype parsed) :to-be nil))))

0 commit comments

Comments
 (0)
Please sign in to comment.