summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--snakemake-test.el10
-rw-r--r--snakemake.el17
2 files changed, 22 insertions, 5 deletions
diff --git a/snakemake-test.el b/snakemake-test.el
index 25713af..213d13c 100644
--- a/snakemake-test.el
+++ b/snakemake-test.el
@@ -812,7 +812,15 @@ two words"
(snakemake-check-target "aa.out")))
(should-not
(snakemake-with-temp-dir
- (snakemake-check-target "aa.out.not-target"))))
+ (snakemake-check-target "aa.out.not-target")))
+ ;; Write-protected targets should be recognized as valid targets
+ ;; despite Snakemake throwing an error.
+ (should
+ (snakemake-with-temp-dir
+ (with-temp-file "bb.out" (insert ""))
+ (set-file-modes "bb.out" (file-modes-symbolic-to-number "u=r"))
+ (with-temp-file "aa.out" (insert ""))
+ (snakemake-check-target "bb.out"))))
(ert-deftest snakemake-test-org-link-file-targets ()
(should (equal '("/path/to/fname")
diff --git a/snakemake.el b/snakemake.el
index 9a93f9e..9ec7b42 100644
--- a/snakemake.el
+++ b/snakemake.el
@@ -258,15 +258,24 @@ The file list is determined by the output of
(regexp-opt (list "MissingRuleException"
"RuleException")))
+(defconst snakemake-valid-target-re "ProtectedOutputException"
+ "Regular expression indicating valid target.
+If this matches, the target will be considered valid even if the
+exit status is non-zero.")
+
(defun snakemake-check-target (target &optional directory)
"Return non-nil if TARGET is a valid target for DIRECTORY's Snakefile."
(snakemake-with-cache directory (target)
(with-temp-buffer
- (when (= 0 (snakemake-insert-output "--quiet" "--dryrun" target))
+ (let ((ex-code (snakemake-insert-output "--quiet" "--dryrun" target)))
(goto-char (point-min))
- ;; Lean towards misclassifying targets as valid rather than
- ;; silently dropping valid targets as invalid.
- (not (re-search-forward snakemake-invalid-target-re nil t))))))
+ (cond
+ ((re-search-forward snakemake-valid-target-re nil t))
+ ((and (= ex-code 0)
+ ;; Lean towards misclassifying targets as valid rather
+ ;; than silently dropping valid targets as invalid.
+ (not (re-search-forward snakemake-invalid-target-re
+ nil t)))))))))
(declare-function org-element-context "org-element")
(declare-function org-element-property "org-element")