Skip to content

Commit

Permalink
Fix issue #32 Parent dirs in elfeed-score-rule-stats-file are not
Browse files Browse the repository at this point in the history
Setting `elfeed-score-rule-stats-file` to a path with intermediate
directories that don't exist will error-out. This fix will at
least attempt to create them.

Also, update the CI workflow & generally prep for the merge
(new version &c)

As an aside, the regression test was originally written using
`file-name-concat' which was only introduced in Emacs 28.1
(we support 26.1). It now uses a purpose-build Emacs Lisp
replacement.
  • Loading branch information
sp1ff committed Jul 28, 2023
1 parent fb59215 commit cb17443
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 34 deletions.
64 changes: 56 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Simple workflow to build the package & execute unit tests. Runs:
# Simple workflow to build the package, execute unit tests & test the tarball. Runs:
#
# - on demand
# - on push
Expand All @@ -19,38 +19,86 @@ on:
- cron: '35 01 * * *'

jobs:

# These all seem to run in `/home/runner/work/elfeed-score/elfeed-score`
lint_and_test:
name: Lint & Test
runs-on: ubuntu-latest
steps:

- name: Checkout repo
uses: actions/checkout@v2

- name: Install tooling
shell: bash
run: |
set -ex
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y autoconf automake emacs texlive
sudo apt-get install -y autoconf automake texlive
git clone https://github.com/skeeto/elfeed.git
- name: Install least version of Emacs supported by elfeed-score
shel: bash
run: |
set -ex
cd /tmp
curl -LO http://mirrors.ocf.berkeley.edu/gnu/emacs/emacs-26.1.tar.gz
tar xf emacs-26.1.tar.gz && cd emacs-26.1
./configure --prefix=/usr/local && make
sudo make install
hash -r
echo "Will now use the emacs at $(type -p emacs): $(emacs --version|head -n1)"
- name: Install a modern version of automake
shell: bash
run: |
set -x
set -ex
cd /tmp
curl -L -O https://ftp.gnu.org/gnu/automake/automake-1.16.4.tar.xz
tar -xf automake-1.16.4.tar.xz
cd automake-1.16.4
./configure && make
sudo make install
- name: Run unit tests
hash -r
echo "Will now use the automake at $(type -p automake): $(automake --version|head -n1)"
- name: Get the current version number from configure.ac
run: |
set -ex
export version=`awk '/^AC_INIT/ {print substr($2, 2, length($2)-3)}' configure.ac`
echo "ELFEED_SCORE_VERSION=${version}" >> $GITHUB_ENV
echo "version is ${{ env.ELFEED_SCORE_VERSION }}"
- name: Configure & make
shell: bash
run: |
set -x
export EMACSLOADPATH=$(pwd):$(pwd)/elfeed:$(pwd)/elfeed/tests:$(ls -d /usr/share/emacs/2*)/lisp
set -ex
export EMACSLOADPATH=$(pwd):$(pwd)/elfeed:$(pwd)/elfeed/tests:$(ls -d /usr/local/share/emacs/2*)/lisp
./bootstrap
./configure
make
make check
make distcheck
- name: Run the unit tests
shell: bash
run: |
set -x
export EMACSLOADPATH=$(pwd):$(pwd)/elfeed:$(pwd)/elfeed/tests:$(ls -d /usr/local/share/emacs/2*)/lisp
make check || cat test/test-suite.log
- name: Check the Autotools distribution
shell: bash
run: |
set -x
pwd
export EMACSLOADPATH=$(pwd):$(pwd)/elfeed:$(pwd)/elfeed/tests:$(ls -d /usr/share/emacs/2*)/lisp
if ! make distcheck; then
cand_build="elfeed-score-${{ env.ELFEED_SCORE_VERSION }}/_build/sub/test/test-suite.log"
cand_inst="elfeed-score-${{ env.ELFEED_SCORE_VERSION }}/_inst/sub/test/test-suite.log"
if -f ${cand_build}; then
cat ${cand_build}
elif -f ${cand_inst}; then
cat {$cand_inst}
fi
fi
2 changes: 1 addition & 1 deletion .github/workflows/melpazoid.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# melpazoid <https://github.com/riscy/melpazoid> build checks.
name: melpazoid
name: Run melpazoid

on:
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Setting up a release workflow for `elfeed-score'. Much thanks to
# BurntShushi from whom I shamelessly copied a lot of this
# <https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml>
name: release
name: Cut a release
on:
# allow this workflow to be triggered manually, which is what this
# event allegedly does
Expand Down
58 changes: 53 additions & 5 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,21 +1,70 @@
2023-07-27 Michael Herstine <sp1ff@pobox.com>

Fix issue #32 Parent dirs in elfeed-score-rule-stats-file are not
Setting `elfeed-score-rule-stats-file` to a path with intermediate
directories that don't exist will error-out. This fix will at
least attempt to create them.

Also, update the CI workflow & generally prep for the merge
(new version &c)

As an aside, the regression test was originally written using
`file-name-concat' which was only introduced in Emacs 28.1
(we support 26.1).

2023-07-27 Michael Herstine <sp1ff@pobox.com>

Fix the Continuous Integration job.
I neglected to do `sudo apt-get update` before doing an `apt-get
install`. This commit remedies that.

2023-07-12 Michael Herstine <sp1ff@pobox.com>

Fix the Continuous Integration job.
I neglected to do `sudo apt-get update` before doing an `apt-get
install`. This commit remedies that.

2023-06-17 Michael Herstine <sp1ff@pobox.com>

Allow the melpazoid check to run on-demand as well as nightly

2023-06-14 Michael Herstine <sp1ff@pobox.com>

Fix make distcheck

2023-06-13 Michael Herstine <sp1ff@pobox.com>

Fix CI

2023-05-06 Michael Herstine <sp1ff@pobox.com>

- Updated the elfeed-score manual to reflect this
- Fixed a unit test that was broken by the previous merge
- Added swflint to AUTHORS
Updating project workflows.

Make release 1.2.6.

Merge branch 'elfeed-enable-configurably'

- Updated the elfeed-score manual to reflect this - Fixed a unit test that was broken by the previous merge - Added swflint to AUTHORS

2023-05-02 Samuel W. Flint <swflint@flintfam.org>

Add configurability to elfeed-score-scoring-score-entry depth

2023-04-18 Michael Herstine <sp1ff@pobox.com>
2023-04-19 Michael <sp1ff@pobox.com>

Merge pull request #29 from sp1ff/pr-process
Maintenance commit. This commit:

2023-04-19 Michael Herstine <sp1ff@pobox.com>

Maintenance commit. This commit:
- fixes the unit tests
- updates copyrights
- adds a new workflow for PRs
- changes the logic for the "melpazoid" workflow

2023-04-18 Michael Herstine <sp1ff@pobox.com>

Merge branch 'master' of github.com:sp1ff/elfeed-score

Updating the Python version in the Melpazoid checks.
Expand All @@ -25,7 +74,6 @@
Merge pull request #28 from swflint/master
Use with-help-window to make the explanation buffer easily quittable


2023-03-09 Samuel W. Flint <swflint@flintfam.org>

Use with-help-window to make the explanation buffer easily quittable
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ elfeed-score News -- history of user-visible changes -*- outline -*-

* elfeed-score 1.2

** changes in elfeed-score 1.2.7

*** address issue #32 Parent dirs in elfeed-score-rule-stats-file are not created automatically

If you set `elfeed-score-rule-stats-file` to a path in which some intermediate directories don't exist, elfeed-score will error on saving stats.
** changes in elfeed-score 1.2.6

*** make the depth at which the scoring function runs configurable in the new entry hook
Expand Down
16 changes: 8 additions & 8 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#+DESCRIPTION: Gnus-style scoring for Elfeed
#+AUTHOR: Michael Herstine
#+EMAIL: sp1ff@pobox.com
#+DATE: <2023-05-06 Sat 08:17>
#+DATE: <2023-07-26 Wed 07:28>
#+AUTODATE: t
#+OPTIONS: toc:nil org-md-headline-style:setext *:t ^:nil
#+STARTUP: overview
Expand Down Expand Up @@ -73,7 +73,7 @@ The easiest way to install elfeed-score is [[https://github.com/melpa/melpa][MEL
If you would prefer to install the package manually, you can also download the Emacs package file on the GitHub releases [[https://github.com/sp1ff/elfeed-score/releases][page]] or from my personal [[https://www.unwoundstack/distros.html][page]]. Then say:

#+BEGIN_SRC elisp
(package-install-file "elfeed-score-1.2.6.tar")
(package-install-file "elfeed-score-1.2.7.tar")
#+END_SRC

** Autotools Source Distributions
Expand All @@ -82,8 +82,8 @@ You can also download Autotools source tarballs (again available either on the G

#+BEGIN_SRC bash
cd /tmp
curl -L --output elfeed-score-1.2.6.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/1.2.6/elfeed-score-1.2.6.tar.gz
tar xvf elfeed-score-1.2.6.tar.gz && cd elfeed-score-1.2.6
curl -L --output elfeed-score-1.2.7.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/1.2.7/elfeed-score-1.2.7.tar.gz
tar xvf elfeed-score-1.2.7.tar.gz && cd elfeed-score-1.2.7
export EMACSLOADPATH=$HOME/.emacs.d/elpa/elfeed-20200209.1942:$EMACSLOADPATH
./configure
make
Expand All @@ -98,16 +98,16 @@ The unit tests require some macros defined by the [[https://github.com/skeeto/el
#+BEGIN_SRC bash
cd /tmp
git clone https://github.com/skeeto/elfeed.git
curl -L --output=elfeed-score-1.2.6.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/1.2.6/elfeed-score-1.2.6.tar.gz
tar xvf elfeed-score-1.2.6.tar.gz && cd elfeed-score-1.2.6
export EMACSLOADPATH=/tmp/elfeed-score-1.2.6:/tmp/elfeed:/tmp/elfeed/tests:$EMACSLOADPATH
curl -L --output=elfeed-score-1.2.7.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/1.2.7/elfeed-score-1.2.7.tar.gz
tar xvf elfeed-score-1.2.7.tar.gz && cd elfeed-score-1.2.7
export EMACSLOADPATH=/tmp/elfeed-score-1.2.7:/tmp/elfeed:/tmp/elfeed/tests:$EMACSLOADPATH
./configure
make
make check
sudo make install
#+END_SRC

Again, unless you already use =EMACSLOADPATH=, you'll need to set =EMACSLOADPATH= appropriately to your system, something like =EMACSLOADPATH=/tmp/elfeed-score-1.2.6:/tmp/elfeed:/tmp/elfeed/tests:/usr/share/emacs/25.2/lisp=.
Again, unless you already use =EMACSLOADPATH=, you'll need to set =EMACSLOADPATH= appropriately to your system, something like =EMACSLOADPATH=/tmp/elfeed-score-1.2.7:/tmp/elfeed:/tmp/elfeed/tests:/usr/share/emacs/25.2/lisp=.
** Building From Source

Finally, you can of course just clone this repo & build there. I've started a [[https://github.com/sp1ff/elfeed-score/wiki][wiki]], whose intended audience are people looking to hack on elfeed-score, that includes build instructions.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
AC_INIT([elfeed-score], [1.2.6], [sp1ff@pobox.com], [elfeed-score], [https://github.com/sp1ff/elfeed-score])
AC_INIT([elfeed-score], [1.2.7], [sp1ff@pobox.com], [elfeed-score], [https://github.com/sp1ff/elfeed-score])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_SRCDIR([./elfeed-score.el])
AC_PROG_MAKE_SET
Expand Down
4 changes: 2 additions & 2 deletions doc/version.texi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@set UPDATED 6 May 2023
@set UPDATED-MONTH May 2023
@set EDITION 1.2.6
@set VERSION 1.2.6
@set EDITION 1.2.7
@set VERSION 1.2.7
2 changes: 1 addition & 1 deletion elfeed-score-pkg.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(define-package
"elfeed-score"
"1.2.6"
"1.2.7"
"Gnus-style scoring for Elfeed"
'((emacs "26.1") (elfeed "3.3.0")))
15 changes: 10 additions & 5 deletions elfeed-score-rule-stats.el
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ This is a utility function for persisting LISP S-expressions to
file. If possible, it will write SEXP to a temporary file in the
same directory as FILE-NAME and then rename the temporary file to
replace the original. Since the move operation is usually atomic
\(so long as both the source & the target are on the same volume)
any error leaves the original untouched, and there is never any
instant where the file is nonexistent.
\(so long as both the source & the target are on the same
filesystem) any error leaves the original untouched, and there is
never any instant where the file is nonexistent.
This implementation will first check that the target file is
writable and signal an error if it is not. Note that it will not
Expand All @@ -145,7 +145,7 @@ heavily derivative of `basic-save-buffer-2'."
(if (not (file-directory-p dir))
(if (file-exists-p dir)
(error "%s is not a directory" dir)
(error "%s: no such directory" dir))
(make-directory dir t))
(if (not (file-exists-p file-name))
(error "Directory %s write-protected" dir)
(error "Attempt to save to a file that you aren't allowed to write")))))
Expand Down Expand Up @@ -181,7 +181,11 @@ heavily derivative of `basic-save-buffer-2'."
"Current count of in-memory stats changes.")

(defun elfeed-score-rule-stats-write (stats-file)
"Write the in-memory stats to STATS-FILE."
"Write the in-memory stats to STATS-FILE.
If STATS-FILE doesn't exist, it will be created. If any parent
directories in its path don't exist, and the caller has
permission to create them, they will be created."
(interactive
(list
(read-file-name "stats file: " nil elfeed-score-rule-stats-file t
Expand Down Expand Up @@ -254,6 +258,7 @@ Returns a default-constructed stats object if RULE isn't in the table."
;; `elfeed-update-init-hooks' & restore it here, but I'm uncomfortable
;; with the risk that the update may be interrupted somehow, leaving
;; `elfeed-score-rule-stats-dirty-threshold' "stuck" from then on.

(defun elfeed-score-rule-stats-update-hook (_url)
"Write stats when an elfeed update is complete."
(when (and (eq (elfeed-queue-count-total) 0)
Expand Down
4 changes: 2 additions & 2 deletions elfeed-score.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Copyright (C) 2019-2023 Michael Herstine <sp1ff@pobox.com>

;; Author: Michael Herstine <sp1ff@pobox.com>
;; Version: 1.2.6
;; Version: 1.2.7
;; Package-Requires: ((emacs "26.1") (elfeed "3.3.0"))
;; Keywords: news
;; URL: https://github.com/sp1ff/elfeed-score
Expand Down Expand Up @@ -44,7 +44,7 @@
(require 'elfeed-score-scoring)
(require 'elfeed-score-maint)

(defconst elfeed-score-version "1.2.6")
(defconst elfeed-score-version "1.2.7")

(defgroup elfeed-score nil
"Gnus-style scoring for Elfeed entries."
Expand Down
37 changes: 37 additions & 0 deletions test/test-stats.el
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,43 @@
(delete-file "test-sexp")
(delete-file "test-sexp-2"))

;; `file-name-concat' was only introduced in Emacs 28.1, and we want to support
;; 26.1. Write a replacement in Emacs Lisp.
(defun file-name-concat-1 (&rest components)
"Concatenate file name COMPONENTS into a single path."
(let ((result ""))
(dolist (component components)
(setq result (expand-file-name component result)))
result))

(ert-deftest test-issue-32 ()
"Regression test against elfeed-score issue #32
\"Parent dirs in elfeed-score-rule-stats-file are not created
automatically\"
If `elfeed-score-rule-stats-write' is invoked with an argument
for which some parent directories don't exist, and the caller has
permissions, they should be created automatically."

;; Whip-up a few rules...
(let ((r1 (elfeed-score-title-rule--create
:text "Bar" :value 1 :type 's))
(r2 (elfeed-score-feed-rule--create
:text "feed" :value 1 :type 's :attr 't)))
;; & generate some stats for 'em.
(elfeed-score-rule-stats-on-match r1)
(elfeed-score-rule-stats-on-match r2)
(should (eq 2 (hash-table-count elfeed-score-rule-stats--table)))
;; and send 'em to a target file whose parent directories don't exist (yet)
(let ((stats-file
(file-name-concat-1 (make-temp-file "iss-32-" t)
"a"
"b"
"test-stats-file")))
(elfeed-score-rule-stats-write stats-file)
(should (file-exists-p stats-file)))
(elfeed-score-serde-cleanup-stats)))

(provide 'test-stats)

;;; test-stats.el ends here.

0 comments on commit cb17443

Please sign in to comment.