aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-09-01 21:22:27 -0400
committerKyle Meyer <kyle@kyleam.com>2016-09-01 21:24:10 -0400
commit6b39982b66f8b37e9999859ddd4302e93c5afbd3 (patch)
tree0fee523ff613e93808888d396e3466c5a88a308f
parent8886280685b63983be8101d98cf9dc6b203d4eac (diff)
downloadsnakemake-mode-6b39982b66f8b37e9999859ddd4302e93c5afbd3.tar.gz
Change approach to handling errors
The approach from 7b210fc (Ignore standard error stream when digesting output, 2016-09-01) does not work well because, depending on the snakemake subcommand, the text of interest may be in the stderr stream. Instead, use lines with spaces as a way to detect non-target lines.
-rw-r--r--snakemake-test.el23
-rw-r--r--snakemake.el42
2 files changed, 48 insertions, 17 deletions
diff --git a/snakemake-test.el b/snakemake-test.el
index f70b284..25713af 100644
--- a/snakemake-test.el
+++ b/snakemake-test.el
@@ -763,6 +763,29 @@ rule abc:
(let ((default-directory "subdir"))
(snakemake-snakefile-directory)))))))
+(ert-deftest snakemake-test-split-lines ()
+ (should
+ (equal '("abc" "123")
+ (snakemake--split-lines "\
+abc
+123
+two words")))
+ (should
+ (equal '("abc" "123")
+ (snakemake--split-lines "\
+abc
+
+123
+
+two words")))
+ (should
+ (equal '("abc")
+ (snakemake--split-lines "\
+abc
+123
+two words"
+ 'remove-num))))
+
(ert-deftest snakemake-test-rule-targets ()
(should
(equal '("aa" "bb" "dd_subdir")
diff --git a/snakemake.el b/snakemake.el
index 3f4dff4..61cfa24 100644
--- a/snakemake.el
+++ b/snakemake.el
@@ -206,23 +206,31 @@ with DIRECTORY and the Snakefile's modification time."
(defun snakemake-insert-output (&rest args)
"Call `snakemake-program' with ARGS and insert output."
- (apply #'call-process snakemake-program nil '(t nil) nil args))
+ (apply #'call-process snakemake-program nil t nil args))
+
+(defun snakemake--split-lines (str &optional remove-num)
+ (cl-remove-if
+ (lambda (x) (or (and remove-num (string-match-p "\\`[0-9]+\\'" x))
+ ;; There is not a clean separation of stderr/stdout
+ ;; streams for warnings, so this is a hacky way to
+ ;; filter non-target lines from the output.
+ (string-match-p " " x)))
+ (split-string str "\n" t)))
(defun snakemake--split-rules (type)
"Return rules of TYPE.
TYPE can be `all' or `target'."
- (cl-remove-if
- (lambda (x) (string-match-p "\\`[0-9]+\\'" x))
- (split-string
- (with-temp-buffer
- (if (= 0 (snakemake-insert-output
- "--nocolor"
- (cl-case type
- (all "--list")
- (target "--list-target-rules")
- (t (user-error "Invalid rule type: %s" type)))))
- (buffer-string)
- (error "Error finding rules"))))))
+ (snakemake--split-lines
+ (with-temp-buffer
+ (if (= 0 (snakemake-insert-output
+ "--nocolor"
+ (cl-case type
+ (all "--list")
+ (target "--list-target-rules")
+ (t (user-error "Invalid rule type: %s" type)))))
+ (buffer-string)
+ (error "Error finding rules")))
+ t))
(defun snakemake-all-rules (&optional directory)
"Return list of rules for DIRECTORY's Snakefile."
@@ -240,9 +248,9 @@ The file list is determined by the output of
`snakemake-file-target-program'."
(when snakemake-file-target-program
(snakemake-with-cache directory ("target-files")
- (split-string
+ (snakemake--split-lines
(with-temp-buffer
- (if (= 0 (call-process snakemake-file-target-program nil '(t nil)))
+ (if (= 0 (call-process snakemake-file-target-program nil t))
(buffer-string)
(error "Error finding file targets")))))))
@@ -413,7 +421,7 @@ $ snakemake --{dag,rulegraph} -- RULES | display"
(setq default-directory dir)
(let ((inhibit-read-only t))
(erase-buffer)
- (apply #'call-process snakemake-program nil '(t nil) nil
+ (apply #'call-process snakemake-program nil t nil
(if rule-graph "--rulegraph" "--dag")
rules))
(image-mode)
@@ -463,7 +471,7 @@ $ snakemake -s <current file> --{dag,rulegraph} | display"
(setq default-directory dir)
(let ((inhibit-read-only t))
(erase-buffer)
- (setq ret-val (call-process snakemake-program nil '(t nil) nil
+ (setq ret-val (call-process snakemake-program nil t nil
(if rule-graph "--rulegraph" "--dag")
"--snakefile" file)))
(if (= 0 ret-val)