From 6dcc652d758af8b5e9e30f6b8203c0e0770cbeeb Mon Sep 17 00:00:00 2001 From: Philip McGrath Date: Mon, 25 Jul 2022 08:16:16 -0400 Subject: gnu: Add ruby-wapiti. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/ruby.scm (ruby-wapiti): New variable. Signed-off-by: Ludovic Courtès --- gnu/packages/ruby.scm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'gnu/packages/ruby.scm') diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm index c1e3dca807..9a75118946 100644 --- a/gnu/packages/ruby.scm +++ b/gnu/packages/ruby.scm @@ -28,6 +28,7 @@ ;;; Copyright © 2021 EuAndreh ;;; Copyright © 2020 Tomás Ortín Fernández ;;; Copyright © 2021 Giovanni Biscuolo +;;; Copyright © 2022 Philip McGrath ;;; ;;; This file is part of GNU Guix. ;;; @@ -12984,3 +12985,48 @@ using Nokogiri.") (description "Blather is a XMPP DSL for Ruby written on top of EventMachine and Nokogiri.") (license license:expat))) + +(define-public ruby-wapiti + (package + (name "ruby-wapiti") + (version "2.0.0") + ;; the gem archive lacks tests + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/inukshuk/wapiti-ruby") + (commit version))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "1kawqw45j7mqk5zmwbn67x1vxiapdgm2ypqqz2bs9l5s7nglzr5b")))) + (build-system ruby-build-system) + (propagated-inputs + (list ruby-builder + ruby-rexml)) + (native-inputs + (list ruby-byebug + ruby-pry + ruby-rake-compiler + ruby-rspec + ruby-simplecov)) + (arguments + (list + #:test-target "spec" + #:phases + #~(modify-phases %standard-phases + (add-after 'replace-git-ls-files 'replace-another-git-ls-files + (lambda args + (substitute* "wapiti.gemspec" + (("`git ls-files spec`") + "`find spec -type f | sort`")))) + (add-before 'build 'compile + (lambda args + (invoke "rake" "compile")))))) + (home-page "https://github.com/inukshuk/wapiti-ruby") + (synopsis "Wicked fast Conditional Random Fields for Ruby") + (description + "The Wapiti-Ruby gem provides a wicked fast linear-chain @acronym{CRF, +Conditional Random Fields} API for sequence segmentation and labelling. It is +based on the codebase of @url{https://wapiti.limsi.fr, Wapiti}.") + (license license:bsd-2))) -- cgit v1.2.3 From ea4bb1bde670f53ef926272c6f8d37ba9bf20bd8 Mon Sep 17 00:00:00 2001 From: Philip McGrath Date: Mon, 25 Jul 2022 08:16:17 -0400 Subject: gnu: Add ruby-namae. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/ruby.scm (ruby-namae): New variable. Signed-off-by: Ludovic Courtès --- gnu/packages/ruby.scm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'gnu/packages/ruby.scm') diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm index 9a75118946..2f47d898db 100644 --- a/gnu/packages/ruby.scm +++ b/gnu/packages/ruby.scm @@ -13030,3 +13030,42 @@ and Nokogiri.") Conditional Random Fields} API for sequence segmentation and labelling. It is based on the codebase of @url{https://wapiti.limsi.fr, Wapiti}.") (license license:bsd-2))) + +(define-public ruby-namae + (package + (name "ruby-namae") + (version "1.1.1") + (source (origin + (method url-fetch) + (uri (rubygems-uri "namae" version)) + (sha256 + (base32 + "1j3nl1klkx3gymrdxfc1hlq4a8qlvhhl9aj5v1v08b9fz27sky0l")))) + (build-system ruby-build-system) + (native-inputs + (list ruby-cucumber + ruby-rspec + ruby-simplecov)) + (arguments + (list + #:phases + #~(modify-phases %standard-phases + (add-after 'extract-gemspec 'allow-newer-cucumber + (lambda args + (substitute* "Gemfile" + (("'cucumber', '[^']*'") + "'cucumber'")))) + (replace 'check + ;; Avoid 'rake' so we don't need jeweler. + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (apply invoke + "rspec" + (find-files "spec" "_spec\\.rb$")))))))) + (home-page "https://github.com/berkmancenter/namae") + (synopsis "Parser for human names") + (description + "Namae (名前) is a parser for human names. It recognizes personal names +of various cultural backgrounds and tries to split them into their component +parts (e.g., given and family names, honorifics etc.).") + (license (list license:bsd-2 license:agpl3+)))) -- cgit v1.2.3 From 7ffea0822a25c54591b3cfeee0affd4d84afddca Mon Sep 17 00:00:00 2001 From: Philip McGrath Date: Mon, 25 Jul 2022 08:16:19 -0400 Subject: gnu: Add ruby-ritex. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/ruby.scm (ruby-ritex): New variable. Signed-off-by: Ludovic Courtès --- gnu/packages/ruby.scm | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'gnu/packages/ruby.scm') diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm index 2f47d898db..746bb9b6ce 100644 --- a/gnu/packages/ruby.scm +++ b/gnu/packages/ruby.scm @@ -13069,3 +13069,45 @@ based on the codebase of @url{https://wapiti.limsi.fr, Wapiti}.") of various cultural backgrounds and tries to split them into their component parts (e.g., given and family names, honorifics etc.).") (license (list license:bsd-2 license:agpl3+)))) + +(define-public ruby-ritex + (package + (name "ruby-ritex") + (version "1.0.1") + (source (origin + (method url-fetch) + (uri (rubygems-uri "ritex" version)) + (sha256 + (base32 + "07rlm3nyz9sxzy1srxs6a31hw81r6w7swrb85fiwi393z8npwc3a")))) + (build-system ruby-build-system) + (native-inputs + (list itex2mml)) + (arguments + ;; thanks to the Gentoo packagers for figuring this out + (list + #:phases + #~(modify-phases %standard-phases + (add-after 'extract-gemspec 'fix-tests + (lambda* (#:key native-inputs inputs #:allow-other-keys) + (substitute* "test/mathml.rb" + (("\\./itex2MML") + ;; don't use the absolute path to avoid keeping a reference + "itex2MML") + (("cmp ',\\\\,\\\\,,,\\\\,'" orig) + (string-append "# " orig " # patched for Guix"))) + (substitute* "test/answer-key.yaml" + (("- ,\\\\,\\\\,,,\\\\," orig) + (string-append "# " orig " # patched for Guix"))))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (invoke "ruby" "-Ilib:." "test/all.rb"))))))) + (home-page "https://rubygems.org/gems/ritex") + (synopsis "Convert expressions from WebTeX into MathML") + (description + "Ritex converts expressions from WebTeX into MathML. WebTeX is an +adaptation of TeX math syntax for web display. Ritex makes inserting math +into HTML pages easy. It supports most TeX math syntax as well as macros.") + ;; doesn't clearly state -only vs -or-later + (license license:gpl2))) -- cgit v1.2.3 From cc5b8cb3c09fd56834bc9ddcb823ce0be9c84b87 Mon Sep 17 00:00:00 2001 From: Philip McGrath Date: Mon, 25 Jul 2022 08:16:20 -0400 Subject: gnu: Add ruby-latex-decode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/patches/ruby-latex-decode-fix-test.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/ruby.scm (ruby-latex-decode): New variable. Signed-off-by: Ludovic Courtès --- gnu/local.mk | 1 + .../patches/ruby-latex-decode-fix-test.patch | 66 ++++++++++++++++++++++ gnu/packages/ruby.scm | 52 +++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 gnu/packages/patches/ruby-latex-decode-fix-test.patch (limited to 'gnu/packages/ruby.scm') diff --git a/gnu/local.mk b/gnu/local.mk index cbfe880d6e..ca3b83c550 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1782,6 +1782,7 @@ dist_patch_DATA = \ %D%/packages/patches/rocm-comgr-3.1.0-dependencies.patch \ %D%/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch \ %D%/packages/patches/rocm-opencl-runtime-4.3-noopencl.patch \ + %D%/packages/patches/ruby-latex-decode-fix-test.patch \ %D%/packages/patches/ruby-mustache-1.1.1-fix-race-condition-tests.patch \ %D%/packages/patches/ruby-sanitize-system-libxml.patch \ %D%/packages/patches/rustc-1.39.0-src.patch \ diff --git a/gnu/packages/patches/ruby-latex-decode-fix-test.patch b/gnu/packages/patches/ruby-latex-decode-fix-test.patch new file mode 100644 index 0000000000..58d7d16258 --- /dev/null +++ b/gnu/packages/patches/ruby-latex-decode-fix-test.patch @@ -0,0 +1,66 @@ +From 698e39a251d433e2cd2934586a2dfc5e6582c4f9 Mon Sep 17 00:00:00 2001 +From: Philip McGrath +Date: Sun, 24 Jul 2022 09:12:55 -0400 +Subject: [PATCH] Improve readability of whitespace tests + +This change fixes the test for `~x` in some environments in which it +was previously failing. + +Related to https://github.com/inukshuk/latex-decode/issues/13 +--- + features/step_definitions/latex.rb | 5 +++++ + features/symbols.feature | 7 ------- + features/whitespace.feature | 13 +++++++++++++ + 3 files changed, 18 insertions(+), 7 deletions(-) + create mode 100644 features/whitespace.feature + +diff --git a/features/step_definitions/latex.rb b/features/step_definitions/latex.rb +index 4b1b595..fca63c0 100644 +--- a/features/step_definitions/latex.rb ++++ b/features/step_definitions/latex.rb +@@ -5,3 +5,8 @@ end + Then /^the result should be ('|")(.*)\1$/ do |quote,value| + expect(@result).to eq(value) + end ++ ++# For whitespace or other characters that are hard to read in source code: ++Then /^I should get '([^']*)' \+ U\+(\h{4,}) \+ '([^']*)'$/ do |pre,code,post| ++ expect(@result).to eq(pre + code.hex.chr(Encoding::UTF_8) + post) ++end +diff --git a/features/symbols.feature b/features/symbols.feature +index 46d9a51..f8a5e84 100644 +--- a/features/symbols.feature ++++ b/features/symbols.feature +@@ -12,10 +12,3 @@ Feature: Decode LaTeX symbol directives + | \\uparrow | ↑ | + | \\downarrow | ↓ | + | \\rightarrow | → | +- +- Scenarios: Whitespace +- | latex | unicode | description | +- | x\\,x | x x | small space | +- | x~x | x x | non-breaking space | +- | ~x |  x | non-breaking space | +- +diff --git a/features/whitespace.feature b/features/whitespace.feature +new file mode 100644 +index 0000000..fe5b208 +--- /dev/null ++++ b/features/whitespace.feature +@@ -0,0 +1,13 @@ ++Feature: Decode LaTeX whitespace directives ++ As a hacker who works with LaTeX ++ I want to be able to decode LaTeX whitespace ++ ++ Scenario Outline: LaTeX to Unicode transformation ++ When I decode the string '' ++ Then I should get
 + U+ + 
++
++  Scenarios: Whitespace
++    | latex | pre | code | post | description                |
++    | x~x   | 'x' | 00A0 | 'x'  | non-breaking space         |
++    | ~y    | ''  | 00A0 | 'y'  | leading non-breaking space |
++    | z\\,z | 'z' | 2009 | 'z'  | small space                |
+-- 
+2.32.0
+
diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 746bb9b6ce..5111b9ae2b 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13111,3 +13111,55 @@ adaptation of TeX math syntax for web display.  Ritex makes inserting math
 into HTML pages easy.  It supports most TeX math syntax as well as macros.")
     ;; doesn't clearly state -only vs -or-later
     (license license:gpl2)))
+
+(define-public ruby-latex-decode
+  (package
+    (name "ruby-latex-decode")
+    (version "0.4.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/inukshuk/latex-decode")
+                    (commit (string-append "v" version))))
+              (sha256
+               (base32
+                "1f5j67ayd04pjkmzvn0hk7cr8yqvn0gyg9ns6a0vhzj2gwna9ihy"))
+              (file-name (git-file-name name version))))
+    (build-system ruby-build-system)
+    (native-inputs
+     (list ruby-cucumber
+           ruby-ritex
+           ruby-rspec))
+    (arguments
+     (list
+      #:test-target "cucumber"
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'extract-gemspec 'avoid-bundler
+            (lambda args
+              (substitute* "Rakefile"
+                (("require 'bundler" orig)
+                 (string-append "# " orig " # patched for Guix"))
+                (("Cucumber::Rake::Task\\.new[(]:cucumber[)]" orig)
+                 (string-append orig " do |c|\n"
+                                "  c.bundler = false # patched for Guix\n"
+                                "end"))
+                (("Bundler\\.setup" orig)
+                 (string-append "true # " orig " # patched for Guix")))
+              (substitute* "cucumber.yml"
+                ;; thanks to avoiding bundler, we can't use this option
+                ((" --publish-quiet")
+                 ""))))
+          (add-after 'replace-git-ls-files 'replace-another-git-ls-files
+            (lambda args
+              (substitute* "latex-decode.gemspec"
+                (("`git ls-files -- [{]test,spec,features[}]/\\*`")
+                 "`find {test,spec,features} -type f | sort`")))))))
+    (home-page "https://github.com/inukshuk/latex-decode")
+    (synopsis "Convert LaTeX to Unicode")
+    (description
+     "This package provides a gem to convert LaTeX input to Unicode.  Its
+original use was as an input filter for BibTeX-Ruby, but it can be used
+independently to decode LaTeX.  Many of the patterns used by this Ruby gem are
+based on François Charette's equivalent Perl module @code{LaTeX::Decode}.")
+    (license license:gpl3+)))
-- 
cgit v1.2.3


From 5e27bcf358bc57c735ca38e5a87f645529db26a2 Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:21 -0400
Subject: gnu: Add ruby-link-header.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-link-header): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 5111b9ae2b..bab120f8e0 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13163,3 +13163,24 @@ original use was as an input filter for BibTeX-Ruby, but it can be used
 independently to decode LaTeX.  Many of the patterns used by this Ruby gem are
 based on François Charette's equivalent Perl module @code{LaTeX::Decode}.")
     (license license:gpl3+)))
+
+(define-public ruby-link-header
+  (package
+    (name "ruby-link-header")
+    (version "0.0.8")
+    (source (origin
+              (method url-fetch)
+              (uri (rubygems-uri "link_header" version))
+              (sha256
+               (base32
+                "1yamrdq4rywmnpdhbygnkkl9fdy249fg5r851nrkkxr97gj5rihm"))))
+    (build-system ruby-build-system)
+    (home-page "https://github.com/asplake/link_header")
+    (synopsis "Parse and format HTTP @code{Link} headers")
+    (description
+     "This gem provides the classes @code{LinkHeader} and
+@code{LinkHeader::Link}, which represent HTTP @code{Link} headers conforming
+to RFC 5988.  Objects can be constructed from and converted to text or a
+JSON-friendly @code{Array} representation.  They can also be used to generate
+corresponding HTML @code{link} elements.")
+    (license license:expat)))
-- 
cgit v1.2.3


From 033b2e61627957fb959cde113fa0868bb0e61f1f Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:22 -0400
Subject: gnu: Add ruby-rdf.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-rdf): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index bab120f8e0..f6d95604f4 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13184,3 +13184,25 @@ to RFC 5988.  Objects can be constructed from and converted to text or a
 JSON-friendly @code{Array} representation.  They can also be used to generate
 corresponding HTML @code{link} elements.")
     (license license:expat)))
+
+(define-public ruby-rdf
+  (package
+    (name "ruby-rdf")
+    (version "3.2.8")
+    (source (origin
+              (method url-fetch)
+              (uri (rubygems-uri "rdf" version))
+              (sha256
+               (base32
+                "1cj0k8ryd8hgbkgqb5swvy6fiygxny3y5bln0my5gv6dbfv3gm20"))))
+    (build-system ruby-build-system)
+    (propagated-inputs (list ruby-link-header))
+    (arguments
+     (list #:tests? #f)) ;; tests have many cyclic dependencies
+    (home-page "https://ruby-rdf.github.io/")
+    (synopsis "Linked Data for Ruby")
+    (description
+     "This gem contains the core algorithms and classes used for doing basic
+programming with @acronym{RDF, Resource Description Framework} data,
+implemented in pure Ruby.")
+    (license license:unlicense)))
-- 
cgit v1.2.3


From e8335360268b8ea16b4e0eda1a3dd98bc2fdaaee Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:23 -0400
Subject: gnu: Add ruby-rdf-vocab.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-rdf-vocab): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index f6d95604f4..01244bb35c 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13206,3 +13206,25 @@ corresponding HTML @code{link} elements.")
 programming with @acronym{RDF, Resource Description Framework} data,
 implemented in pure Ruby.")
     (license license:unlicense)))
+
+(define-public ruby-rdf-vocab
+  (package
+    (name "ruby-rdf-vocab")
+    (version "3.2.1")
+    (source (origin
+              (method url-fetch)
+              (uri (rubygems-uri "rdf-vocab" version))
+              (sha256
+               (base32
+                "1bqmp9rfjvd56ajjz68ij6jla1wjf1fqg7bi4dpnjrsmn4pwaq7l"))))
+    (build-system ruby-build-system)
+    (propagated-inputs
+     (list ruby-rdf))
+    (arguments
+     (list #:tests? #f)) ;; tests have many cyclic dependencies
+    (home-page "https://github.com/ruby-rdf/rdf-vocab")
+    (synopsis "Common RDF vocabularies")
+    (description
+     "This gem extends @code{ruby-rdf} with several common @acronym{RDF,
+Resource Description Framework} vocabularies.")
+    (license license:unlicense)))
-- 
cgit v1.2.3


From 07dcbc767a0a844d0dd51ede273b815886d4e4fc Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:24 -0400
Subject: gnu: Add ruby-bibtex-ruby.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-bibtex-ruby): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 01244bb35c..28e5ea0b7e 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13228,3 +13228,46 @@ implemented in pure Ruby.")
      "This gem extends @code{ruby-rdf} with several common @acronym{RDF,
 Resource Description Framework} vocabularies.")
     (license license:unlicense)))
+
+(define-public ruby-bibtex-ruby
+  (package
+    (name "ruby-bibtex-ruby")
+    (version "6.0.0")
+    (source (origin
+              (method url-fetch)
+              (uri (rubygems-uri "bibtex-ruby" version))
+              (sha256
+               (base32
+                "0vynqa8q9hwghw6sdljr304b5gh11nqzy5nwqqwxmgy7pqyf7qw5"))))
+    (build-system ruby-build-system)
+    (propagated-inputs
+     (list ruby-latex-decode
+           ruby-rdf
+           ruby-rdf-vocab))
+    (native-inputs
+     (list ruby-byebug
+           ruby-cucumber
+           ruby-minitest
+           ruby-yard))
+    (arguments
+     (list
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'extract-gemspec 'avoid-bundler
+            (lambda args
+              (substitute* "Rakefile"
+                (("require 'bundler" orig)
+                 (string-append "# " orig " # patched for Guix"))
+                (("Bundler\\.setup" orig)
+                 (string-append "true # " orig " # patched for Guix"))))))))
+    (home-page "https://github.com/inukshuk/bibtex-ruby")
+    (synopsis "Rubyist's Swiss Army knife for all things BibTeX")
+    (description
+     "BibTeX-Ruby is the Rubyist's Swiss Army knife for all things BibTeX.
+It includes a parser for all common BibTeX objects and a sophisticated name
+parser that tokenizes correctly formatted names.  BibTeX-Ruby recognizes
+BibTeX string replacements, joins values containing multiple strings or
+variables, supports cross-references, and decodes common LaTeX formatting
+instructions to unicode.  If you are in a hurry, it also allows for easy
+export/conversion to formats such as YAML, JSON, CSL, and XML (BibTeXML).")
+    (license license:gpl3+)))
-- 
cgit v1.2.3


From 5f7db95215ca71d2f09a54fda6b881749b6ad2ba Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:25 -0400
Subject: gnu: Add ruby-unicode-scripts.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-unicode-scripts): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 28e5ea0b7e..25e3cbcd97 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13271,3 +13271,25 @@ variables, supports cross-references, and decodes common LaTeX formatting
 instructions to unicode.  If you are in a hurry, it also allows for easy
 export/conversion to formats such as YAML, JSON, CSL, and XML (BibTeXML).")
     (license license:gpl3+)))
+
+(define-public ruby-unicode-scripts
+  (package
+    (name "ruby-unicode-scripts")
+    (version "1.7.0")
+    (source (origin
+              (method url-fetch)
+              (uri (rubygems-uri "unicode-scripts" version))
+              (sha256
+               (base32
+                "1k7kbfk806zam129bp7pdiqkfb5hn51x149irzvjhs4xf22m4yvi"))))
+    (build-system ruby-build-system)
+    (native-inputs
+     (list ruby-minitest))
+    (arguments
+     (list #:test-target "spec"))
+    (home-page "https://github.com/janlelis/unicode-scripts")
+    (synopsis "Unicode script classification library")
+    (description
+     "This gem provides a simple interface for classifying Ruby strings using
+the Unicode @code{Script} and @code{Script_Extensions} properties.")
+    (license license:expat)))
-- 
cgit v1.2.3


From cb585754f3dafa63215ef76ab45ae682bf632c46 Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:26 -0400
Subject: gnu: Add ruby-citeproc.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-citeproc): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 25e3cbcd97..e3d9572bec 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13293,3 +13293,27 @@ export/conversion to formats such as YAML, JSON, CSL, and XML (BibTeXML).")
      "This gem provides a simple interface for classifying Ruby strings using
 the Unicode @code{Script} and @code{Script_Extensions} properties.")
     (license license:expat)))
+
+(define-public ruby-citeproc
+  (package
+    (name "ruby-citeproc")
+    (version "1.0.10")
+    (source (origin
+              (method url-fetch)
+              (uri (rubygems-uri "citeproc" version))
+              (sha256
+               (base32
+                "13vl5sjmksk5a8kjcqnjxh7kn9gn1n4f9p1rvqfgsfhs54p0m6l2"))))
+    (build-system ruby-build-system)
+    (propagated-inputs
+     (list ruby-namae))
+    (arguments
+     (list #:tests? #f)) ;; tests have a cyclic dependency
+    (home-page "https://github.com/inukshuk/citeproc")
+    (synopsis "Interface for Ruby citation processors")
+    (description
+     "CiteProc is a citation processor interface and citation data API based
+on the @acronym{CSL, Citation Style Language} specifications.  To actually
+process citations, a dedicated processor engine is required: a pure Ruby
+engine is available in the @code{citeproc-ruby} gem.")
+    (license (list license:agpl3+ license:bsd-2))))
-- 
cgit v1.2.3


From e708f7f8b0f273eb5d9b1ee2e4c50ab9042a71f7 Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:27 -0400
Subject: gnu: Add ruby-edtf.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-edtf): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index e3d9572bec..914c7e859c 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13317,3 +13317,63 @@ on the @acronym{CSL, Citation Style Language} specifications.  To actually
 process citations, a dedicated processor engine is required: a pure Ruby
 engine is available in the @code{citeproc-ruby} gem.")
     (license (list license:agpl3+ license:bsd-2))))
+
+(define-public ruby-edtf
+  (package
+    (name "ruby-edtf")
+    (version "3.1.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/inukshuk/edtf-ruby")
+                    (commit (string-append "v" version))))
+              (sha256
+               (base32
+                "18j8xq8zmrn41cs2gpd1i87agi9905asvnjqndky2cqb5zg3q14g"))
+              (snippet
+               ;; remove generated file
+               #~(delete-file "lib/edtf/parser.rb"))
+              (file-name (git-file-name name version))))
+    (build-system ruby-build-system)
+    (propagated-inputs
+     (list ruby-activesupport))
+    (native-inputs
+     (list ruby-cucumber
+           ruby-rspec))
+    (arguments
+     (list
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'extract-gemspec 'avoid-bundler
+            (lambda args
+              (substitute* "Rakefile"
+                (("require 'bundler" orig)
+                 (string-append "# " orig " # patched for Guix"))
+                (("bundle exec racc")
+                 "racc")
+                (("Cucumber::Rake::Task\\.new[(]:cucumber[)]" orig)
+                 (string-append orig " do |c|\n"
+                                "  c.bundler = false # patched for Guix\n"
+                                "end"))
+                (("Bundler\\.setup" orig)
+                 (string-append "true # " orig " # patched for Guix")))))
+          (add-after 'avoid-bundler 'patch-cucumber-options
+            (lambda args
+              (substitute* "cucumber.yml"
+                ;; this option is not supported, at least in our configuration
+                ((" --publish-quiet")
+                 ""))))
+          (add-before 'build 'compile
+            (lambda args
+              (invoke "rake" "racc")))
+          (replace 'check
+            (lambda* (#:key tests? #:allow-other-keys)
+              (when tests?
+                (invoke "rake")))))))
+    (home-page "https://github.com/inukshuk/edtf-ruby")
+    (synopsis "Ruby implementation of Extended Date/Time Format")
+    (description
+     "EDTF-Ruby provides a parser and an API for the @acronym{EDTF, Extended
+Date/Time Format} standard, implemented as an extension to Ruby's @code{Date}
+class.")
+    (license license:bsd-2)))
-- 
cgit v1.2.3


From fc1f561432161718d9fa88cbcfc3f0fbff51b397 Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:28 -0400
Subject: gnu: Add ruby-gli.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-gli): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 914c7e859c..af19bf7701 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13377,3 +13377,55 @@ engine is available in the @code{citeproc-ruby} gem.")
 Date/Time Format} standard, implemented as an extension to Ruby's @code{Date}
 class.")
     (license license:bsd-2)))
+
+(define-public ruby-gli
+  (package
+    (name "ruby-gli")
+    (version "2.21.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/davetron5000/gli")
+                    (commit (string-append "v" version))))
+              (sha256
+               (base32
+                "09b1r9hlx4dy2yq036nk7hc2nbswhia6q3na9v11z94yibc8mgja"))
+              (file-name (git-file-name name version))))
+    (build-system ruby-build-system)
+    (native-inputs
+     (list ruby-minitest
+           ruby-rainbow
+           ruby-rdoc
+           ruby-sdoc))
+    (arguments
+     (list
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'extract-gemspec 'patch-gemspec-version
+            (lambda args
+              (substitute* "gli.gemspec"
+                ;; this trick fails in our build environment
+                (("require File\\.join[(]\\[" orig)
+                 (string-append "# patched for Guix # " orig))
+                (("s\\.version = GLI::VERSION")
+                 #$(string-append "s.version = '"
+                                  (package-version this-package)
+                                  "' # patched for Guix")))))
+          (add-after 'replace-git-ls-files 'replace-another-git-ls-files
+            (lambda args
+              (substitute* "gli.gemspec"
+                (("`git ls-files -- [{]test,spec,features[}]/\\*`")
+                 "`find {test,spec,features} -type f | sort`"))))
+          (add-after 'replace-another-git-ls-files 'fix-rubyopt
+            (lambda args
+              (substitute* "Rakefile"
+                (("ENV\\[\"RUBYOPT\"]")
+                 "(ENV['RUBYOPT'] || '')")))))))
+    (home-page "https://davetron5000.github.io/gli/")
+    (synopsis "Git-Like Interface command-line parser")
+    (description
+     "GLI allows you to create command-line applications in Ruby with Git-Like
+Interfaces: that is, they take subcommands in the style of @command{git} and
+@command{gem}.  GLI uses a simple domain-specific language, but retains all
+the power of the built-in @code{OptionParser}.")
+    (license license:asl2.0)))
-- 
cgit v1.2.3


From 8d4670f4d18a9c57a6300eb3c11fbc26825f7a61 Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:29 -0400
Subject: gnu: Add ruby-anystyle-data.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-anystyle-data): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index af19bf7701..6b312d1b4d 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13429,3 +13429,54 @@ Interfaces: that is, they take subcommands in the style of @command{git} and
 @command{gem}.  GLI uses a simple domain-specific language, but retains all
 the power of the built-in @code{OptionParser}.")
     (license license:asl2.0)))
+
+(define-public ruby-anystyle-data
+  (package
+    (name "ruby-anystyle-data")
+    (version "1.2.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/inukshuk/anystyle-data")
+                    (commit version)))
+              (sha256
+               (base32
+                "025mxa7r9d7izqn6bc1wr40ijp64da0jh211prlpjl6svilgd6rm"))
+              (snippet
+               ;; remove pre-built file
+               #~(delete-file "lib/anystyle/data/dict.txt.gz"))
+              (file-name (git-file-name name version))))
+    (build-system ruby-build-system)
+    (arguments
+     (list
+      #:tests? #f ;; there are none
+      #:modules
+      `((guix build ruby-build-system)
+        (guix build utils)
+        (srfi srfi-26))
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'replace-git-ls-files 'replace-another-git-ls-files
+            (lambda args
+              (substitute* "anystyle-data.gemspec"
+                (("`git ls-files lib README\\.md LICENSE`\\.split[(][^)]*[)]")
+                 (string-append
+                  "["
+                  (string-join
+                   (map (cut string-append "\"" <> "\"")
+                        `("README.md"
+                          "LICENSE"
+                          "lib/anystyle/data.rb"
+                          "lib/anystyle/data/dict.txt.gz"
+                          "lib/anystyle/data/setup.rb"
+                          "lib/anystyle/data/version.rb"))
+                   ", ")
+                  "]")))))
+          (add-before 'build 'compile-dict
+            (lambda args
+              (invoke "rake" "compile"))))))
+    (home-page "https://anystyle.io")
+    (synopsis "AnyStyle parser dictionary data")
+    (description
+     "This gem provides parser dictionary data for AnyStyle.")
+    (license license:bsd-2)))
-- 
cgit v1.2.3


From 3b017b9400978a7f351fd8a75e33d1eefb079d08 Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:30 -0400
Subject: gnu: Add ruby-anystyle.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (ruby-anystyle): New variable.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 6b312d1b4d..39d8d9e1ef 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13480,3 +13480,74 @@ the power of the built-in @code{OptionParser}.")
     (description
      "This gem provides parser dictionary data for AnyStyle.")
     (license license:bsd-2)))
+
+(define-public ruby-anystyle
+  (let ((commit "50f1dd547d28ab4b830e45d70e840cb1898a37b0")
+        (revision "1"))
+    ;; Releases point to specific commits, but recent releases haven't been
+    ;; tagged in Git.  Meanwhile, the rubygems archive lacks tests.
+    (package
+      (name "ruby-anystyle")
+      (version (git-version "1.3.14" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/inukshuk/anystyle")
+                      (commit commit)))
+                (sha256
+                 (base32
+                  "0f4qcrywl1kl6qysn24lj3yp85ln4i7za7b7ld2fglyzwcggxwb0"))
+                (snippet
+                 ;; There is an optional dependency on
+                 ;; , which
+                 ;; seems like it was intended to be free software, but
+                 ;; doesn't have a clear license statement.  Maybe someone can
+                 ;; do more sleuthing, or else find a replacement?  See also
+                 ;; .  For
+                 ;; now, patch it out, but leave a pointer to follow up.
+                 #~(begin
+                     (use-modules (guix build utils))
+                     (substitute* "Gemfile"
+                       (("gem 'language_detector', github: '[^']*'" orig)
+                        (string-append "# " orig " # unclear license")))
+                     (substitute* "spec/anystyle/parser_spec.rb"
+                       (("language: 'en'," orig)
+                        (string-append "# " orig " # no lanugage_detector")))))
+                (file-name (git-file-name name version))))
+      (build-system ruby-build-system)
+      (propagated-inputs
+       (list ruby-anystyle-data
+             ruby-bibtex-ruby
+             ruby-namae
+             ruby-wapiti))
+      (native-inputs
+       (list ruby-byebug
+             ruby-citeproc
+             ruby-edtf
+             ruby-rspec
+             ruby-unicode-scripts))
+      (arguments
+       (list
+        #:test-target "spec"
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'extract-gemspec 'avoid-bundler
+              (lambda args
+                (substitute* "Rakefile"
+                  (("require 'bundler" orig)
+                   (string-append "# " orig " # patched for Guix"))
+                  (("Bundler\\.setup" orig)
+                   (string-append "true # " orig " # patched for Guix")))))
+            (add-after 'replace-git-ls-files 'replace-another-git-ls-files
+              (lambda args
+                (substitute* "anystyle.gemspec"
+                  (("`git ls-files spec`")
+                   "`find spec -type f | sort`")))))))
+      (home-page "https://anystyle.io")
+      (synopsis "Fast and smart citation reference parsing (Ruby library)")
+      (description
+       "AnyStyle is a very fast and smart parser for academic reference lists
+and bibliographies.  AnyStyle uses powerful machine learning heuristics based
+on Conditional Random Fields and aims to make it easy to train the model with
+data that is relevant to your parsing needs.")
+      (license license:bsd-2))))
-- 
cgit v1.2.3


From 3ee5460b6338246b0b1e97c77b3f4b676f8a92bc Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:31 -0400
Subject: gnu: Add anystyle.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (anystyle): New variable.
(ruby-anystyle)[description]: Mention it.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 125 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 124 insertions(+), 1 deletion(-)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 39d8d9e1ef..cdb9f53830 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -66,6 +66,7 @@
   #:use-module (gnu packages libidn)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages lsof)
+  #:use-module (gnu packages man)
   #:use-module (gnu packages maths)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages networking)
@@ -13549,5 +13550,127 @@ the power of the built-in @code{OptionParser}.")
        "AnyStyle is a very fast and smart parser for academic reference lists
 and bibliographies.  AnyStyle uses powerful machine learning heuristics based
 on Conditional Random Fields and aims to make it easy to train the model with
-data that is relevant to your parsing needs.")
+data that is relevant to your parsing needs.
+
+This package provides the Ruby module @code{AnyStyle}.  AnyStyle can also be
+used via the @command{anystyle} command-line utility or a web application,
+though the later has not yet been packaged for Guix.")
       (license license:bsd-2))))
+
+(define-public anystyle
+  (package
+    (name "anystyle")
+    (version "1.3.1")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/inukshuk/anystyle-cli")
+                    (commit version)))
+              (sha256
+               (base32
+                "1bazzms04cra8516q7vydmcm31yd0a7si1pxk4waffqy7lh0pksg"))
+              (file-name (git-file-name name version))))
+    (build-system ruby-build-system)
+    (propagated-inputs
+     (list ruby-anystyle
+           ruby-bibtex-ruby
+           ruby-gli))
+    (native-inputs
+     (list txt2man))
+    (arguments
+     (list
+      #:modules
+      `((guix build ruby-build-system)
+        (ice-9 popen)
+        (guix build utils))
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'extract-gemspec 'less-strict-dependencies
+            (lambda args
+              (substitute* "anystyle-cli.gemspec"
+                (("'bibtex-ruby', '[^']*'")
+                 "'bibtex-ruby'"))))
+          (delete 'check) ;; there are no upstream tests
+          (add-after 'wrap 'check-cli
+            (lambda* (#:key tests? outputs #:allow-other-keys)
+              (when tests?
+                (with-output-to-file "check-cli.in"
+                  (lambda ()
+                    (for-each
+                     display
+                     '("Derrida, J. (1967). L’écriture et la différence "
+                       "(1 éd.). Paris: Éditions du Seuil.\n"))))
+                (invoke (search-input-file outputs "/bin/anystyle")
+                        "parse"
+                        "check-cli.in"))))
+          (add-after 'wrap 'generate-man-page
+            ;; generating a man page also tests that the command actually runs
+            (lambda args
+              (define (run-with-output-file file command . args)
+                (format (current-output-port)
+                        "running: ~s\nwith output to: ~s\n"
+                        (cons command args)
+                        file)
+                (unless (zero?
+                         (with-output-to-file file
+                           (lambda ()
+                             (status:exit-val
+                              (close-pipe
+                               (apply open-pipe* OPEN_WRITE command args))))))
+                  (error "command failed")))
+              (let ((anystyle (string-append #$output "/bin/anystyle")))
+                (run-with-output-file "intro.txt"
+                                      anystyle "--help")
+                (for-each (lambda (cmd)
+                            (let ((file (string-append cmd ".txt")))
+                              (run-with-output-file file
+                                                    anystyle cmd "--help")
+                              ;; indent headings to create subsections
+                              (substitute* file
+                                (("^[A-Z]" orig)
+                                 (string-append " " orig)))
+                              ;; generate a section heading
+                              (call-with-output-file
+                                  (string-append "section-" file)
+                                (lambda (out)
+                                  (format out "\n\n~a COMMAND\n\n"
+                                          (string-upcase cmd))))))
+                          '("check" "find" "parse" "train"))
+                (substitute* `("intro.txt"
+                               "check.txt" "find.txt" "parse.txt" "train.txt")
+                  ;; format "tag list" for txt2man"
+                  ((" - ")
+                   "    ")
+                  ;; restore formatting of the "name" sections
+                  (("(anystyle|check|find|parse|train)    ([A-Z])" _ cmd post)
+                   (string-append cmd " - " post)))
+                (run-with-output-file "anystyle.txt"
+                                      "cat"
+                                      "intro.txt"
+                                      "section-check.txt" "check.txt"
+                                      "section-find.txt" "find.txt"
+                                      "section-parse.txt" "parse.txt"
+                                      "section-train.txt" "train.txt")
+                (run-with-output-file
+                 "anystyle.1"
+                 "txt2man"
+                 "-v" "General Commands Manual" "-t" "anystyle" "-s" "1"
+                 "-r" #$(string-append "anystyle-cli "
+                                       (package-version this-package))
+                 "-B" "check" "-B" "find" "-B" "parse" "-B" "train"
+                 "anystyle.txt")
+                (install-file "anystyle.1"
+                              (string-append #$output "/share/man/man1"))))))))
+    (home-page "https://anystyle.io")
+    (synopsis "Fast and smart citation reference parsing")
+    (description
+     "AnyStyle is a very fast and smart parser for academic reference lists
+and bibliographies.  AnyStyle uses powerful machine learning heuristics based
+on Conditional Random Fields and aims to make it easy to train the model with
+data that is relevant to your parsing needs.
+
+This package provides the @command{anystyle} command-line utility.  AnyStyle
+can also be used as a Ruby library or as a web application, though the later
+has not yet been packaged for Guix.")
+    (license license:bsd-2)
+    (properties `((upstream-name . "anystyle-cli")))))
-- 
cgit v1.2.3


From bc2de56572872eefdc2992b34cce69c77deb485a Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:32 -0400
Subject: gnu: ruby-anystyle-data: Don't write to installed gem.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/patches/ruby-anystyle-data-immutable-install.patch: New
patch.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/ruby.scm (ruby-anystyle-data)[patches]: Use it.

Signed-off-by: Ludovic Courtès 
---
 gnu/local.mk                                       |  1 +
 .../ruby-anystyle-data-immutable-install.patch     | 40 ++++++++++++++++++++++
 gnu/packages/ruby.scm                              |  2 ++
 3 files changed, 43 insertions(+)
 create mode 100644 gnu/packages/patches/ruby-anystyle-data-immutable-install.patch

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/local.mk b/gnu/local.mk
index ca3b83c550..32ee102943 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1782,6 +1782,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/rocm-comgr-3.1.0-dependencies.patch \
   %D%/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch \
   %D%/packages/patches/rocm-opencl-runtime-4.3-noopencl.patch \
+  %D%/packages/patches/ruby-anystyle-data-immutable-install.patch	\
   %D%/packages/patches/ruby-latex-decode-fix-test.patch		\
   %D%/packages/patches/ruby-mustache-1.1.1-fix-race-condition-tests.patch \
   %D%/packages/patches/ruby-sanitize-system-libxml.patch	\
diff --git a/gnu/packages/patches/ruby-anystyle-data-immutable-install.patch b/gnu/packages/patches/ruby-anystyle-data-immutable-install.patch
new file mode 100644
index 0000000000..d5d7149a67
--- /dev/null
+++ b/gnu/packages/patches/ruby-anystyle-data-immutable-install.patch
@@ -0,0 +1,40 @@
+From a6f5b37cd22daa6069d8fbef8cba9dc60a6731f6 Mon Sep 17 00:00:00 2001
+From: Philip McGrath 
+Date: Sun, 24 Jul 2022 23:54:19 -0400
+Subject: [PATCH] `AnyStyle::Data.setup()`: adjust for immutable install
+
+Don't override the default paths for `Dictionary::Marshal`,
+`Dictionary::GDBM`, and `Dictionary:LDBM` to point to this gem: we can't
+populate such files without the 'anystyle' gem (which depends on this
+one), and we won't be able to write to the directory where this gem is
+installed later, so the files will never exist at those locations.
+---
+ lib/anystyle/data/setup.rb | 12 ------------
+ 1 file changed, 12 deletions(-)
+
+diff --git a/lib/anystyle/data/setup.rb b/lib/anystyle/data/setup.rb
+index 17efdf8..08246fa 100644
+--- a/lib/anystyle/data/setup.rb
++++ b/lib/anystyle/data/setup.rb
+@@ -4,18 +4,6 @@ module AnyStyle
+ 
+     def self.setup
+       Dictionary.defaults[:source] = File.join(ROOT, 'dict.txt.gz')
+-
+-      if defined? Dictionary::Marshal
+-        Dictionary::Marshal.defaults[:path] = File.join(ROOT, 'dict.marshal')
+-      end
+-
+-      if defined? Dictionary::GDBM
+-        Dictionary::GDBM.defaults[:path] = File.join(ROOT, 'dict.db')
+-      end
+-
+-      if defined? Dictionary::LDBM
+-        Dictionary::LDBM.defaults[:path] = ROOT
+-      end
+     end
+   end
+ end
+-- 
+2.32.0
+
diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index cdb9f53830..6e0b2dd14c 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13446,6 +13446,8 @@ the power of the built-in @code{OptionParser}.")
               (snippet
                ;; remove pre-built file
                #~(delete-file "lib/anystyle/data/dict.txt.gz"))
+              (patches
+               (search-patches "ruby-anystyle-data-immutable-install.patch"))
               (file-name (git-file-name name version))))
     (build-system ruby-build-system)
     (arguments
-- 
cgit v1.2.3


From 14a50b62d4e8765b794861226d79f6872d6c434c Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:33 -0400
Subject: gnu: ruby-anystyle: Initialize dictionary files.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

For the GDBM and Marshal dictionary adapters to be useful with their
default settings, we must initialize their data files during the package
build: upstream would initialize them lazily, but that doesn't work with
an immutable installation directory (at least, not without more complex
patches). Otherwise, we would always end up rebuilding the dictionary at
startup, which is “slow” and “not recommended”.

* gnu/packages/patches/ruby-anystyle-fix-dictionary-populate.patch: New
patch.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/ruby.scm (ruby-anystyle)[patches]: Use it.
[arguments]<#:phases>: Add 'populate-dictionaries' phase.

Signed-off-by: Ludovic Courtès 
---
 gnu/local.mk                                       |  1 +
 .../ruby-anystyle-fix-dictionary-populate.patch    | 94 ++++++++++++++++++++++
 gnu/packages/ruby.scm                              | 31 ++++++-
 3 files changed, 125 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/ruby-anystyle-fix-dictionary-populate.patch

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/local.mk b/gnu/local.mk
index 32ee102943..0e8b7b0447 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1783,6 +1783,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch \
   %D%/packages/patches/rocm-opencl-runtime-4.3-noopencl.patch \
   %D%/packages/patches/ruby-anystyle-data-immutable-install.patch	\
+  %D%/packages/patches/ruby-anystyle-fix-dictionary-populate.patch	\
   %D%/packages/patches/ruby-latex-decode-fix-test.patch		\
   %D%/packages/patches/ruby-mustache-1.1.1-fix-race-condition-tests.patch \
   %D%/packages/patches/ruby-sanitize-system-libxml.patch	\
diff --git a/gnu/packages/patches/ruby-anystyle-fix-dictionary-populate.patch b/gnu/packages/patches/ruby-anystyle-fix-dictionary-populate.patch
new file mode 100644
index 0000000000..b2e0498e8d
--- /dev/null
+++ b/gnu/packages/patches/ruby-anystyle-fix-dictionary-populate.patch
@@ -0,0 +1,94 @@
+From fae622c8b77feebac66a538d76e4211de8bd8eb3 Mon Sep 17 00:00:00 2001
+From: Philip McGrath 
+Date: Sun, 24 Jul 2022 21:50:44 -0400
+Subject: [PATCH] fix saving `AnyStyle::Dictionary` after `populate!`
+
+Some of these fixes are more generally applicable.
+
+A more robust solution might find data files using
+e.g. `Gem.find_files()`.
+---
+ lib/anystyle/dictionary/gdbm.rb    |  6 ++++++
+ lib/anystyle/dictionary/marshal.rb | 31 ++++++++++++++++++++++++------
+ 2 files changed, 31 insertions(+), 6 deletions(-)
+
+diff --git a/lib/anystyle/dictionary/gdbm.rb b/lib/anystyle/dictionary/gdbm.rb
+index 754903c..c814df2 100644
+--- a/lib/anystyle/dictionary/gdbm.rb
++++ b/lib/anystyle/dictionary/gdbm.rb
+@@ -1,5 +1,6 @@
+ module AnyStyle
+   require 'gdbm'
++  require 'fileutils'
+ 
+   class Dictionary
+     class GDBM < Dictionary
+@@ -17,8 +18,13 @@ module AnyStyle
+ 
+       def open
+         close
++        FileUtils.mkdir_p(File.dirname(options[:path]))
+         @db = ::GDBM.new(*options.values_at(:path, :mode, :flags))
+         self
++      rescue Errno::EACCES
++        # GDBM.new tries this if :flags is nil, but not necessarily otherwise
++        @db = ::GDBM.new(options[:path],options[:mode],::GDBM::READER)
++        self
+       ensure
+         populate! if empty?
+       end
+diff --git a/lib/anystyle/dictionary/marshal.rb b/lib/anystyle/dictionary/marshal.rb
+index 761ca36..b9529d0 100644
+--- a/lib/anystyle/dictionary/marshal.rb
++++ b/lib/anystyle/dictionary/marshal.rb
+@@ -1,4 +1,6 @@
+ module AnyStyle
++  require 'fileutils'
++  require 'tempfile'
+   class Dictionary
+     class Marshal < Dictionary
+       @defaults = {
+@@ -10,17 +12,34 @@ module AnyStyle
+       end
+ 
+       def open
+-        if File.exists?(options[:path])
+-          @db = ::Marshal.load(File.open(options[:path]))
+-        else
+-          @db = {}
++        File.open(options[:path]) do |file|
++          @db = ::Marshal.load(file)
+         end
+         self
++      rescue Errno::ENOENT
++        @db = {}
++        self
+       ensure
+         if empty?
+           populate!
+-          if File.writable?(options[:path])
+-            ::Marshal.dump(db, File.open(options[:path], 'wb'))
++          tmp = nil
++          begin
++            FileUtils.mkdir_p(File.dirname(options[:path]))
++            tmp = Tempfile.create(File.basename(options[:path]),
++                                  File.dirname(options[:path]),
++                                  mode: File::Constants::BINARY)
++            pth = tmp.path()
++            ::Marshal.dump(db, tmp)
++            tmp.close()
++            File.rename(tmp.path, options[:path]) # will overwrite if exists
++            tmp = nil
++          rescue SystemCallError => e
++            warn(e.message)
++          ensure
++            if tmp then
++              tmp.close()
++              tmp.unlink()
++            end
+           end
+         end
+       end
+-- 
+2.32.0
+
diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 6e0b2dd14c..0b558de6db 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13516,6 +13516,9 @@ the power of the built-in @code{OptionParser}.")
                      (substitute* "spec/anystyle/parser_spec.rb"
                        (("language: 'en'," orig)
                         (string-append "# " orig " # no lanugage_detector")))))
+                (patches
+                 (search-patches
+                  "ruby-anystyle-fix-dictionary-populate.patch"))
                 (file-name (git-file-name name version))))
       (build-system ruby-build-system)
       (propagated-inputs
@@ -13545,7 +13548,33 @@ the power of the built-in @code{OptionParser}.")
               (lambda args
                 (substitute* "anystyle.gemspec"
                   (("`git ls-files spec`")
-                   "`find spec -type f | sort`")))))))
+                   "`find spec -type f | sort`"))))
+            (add-after 'wrap 'populate-dictionaries
+              (lambda args
+                ;; We must initiallize these files here, or they will never be
+                ;; usable with the default settings. A more flexible approach
+                ;; might use something like `Gem.find_files()` or
+                ;; XDG_DATA_DIRS.
+                (with-output-to-file "initialize-dictionaries.rb"
+                  (lambda ()
+                    (display "
+require 'anystyle/dictionary' # must come before 'anystyle/data'
+require 'anystyle/data'
+[:marshal, :gdbm].each do |adapter|
+  AnyStyle::Dictionary.create({adapter: adapter}).open().close()
+end
+")))
+                (let* ((old-gems (getenv "GEM_PATH"))
+                       (new-gems (string-append #$output
+                                                "/lib/ruby/vendor_ruby:"
+                                                old-gems)))
+                  (dynamic-wind
+                    (lambda ()
+                      (setenv "GEM_PATH" new-gems))
+                    (lambda ()
+                      (invoke "ruby" "initialize-dictionaries.rb"))
+                    (lambda ()
+                      (setenv "GEM_PATH" old-gems)))))))))
       (home-page "https://anystyle.io")
       (synopsis "Fast and smart citation reference parsing (Ruby library)")
       (description
-- 
cgit v1.2.3


From 9c124671ce0eafe50c1d913976ad6bc619475f9a Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:34 -0400
Subject: gnu: anystyle: Add tests for dictionary adapters.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/ruby.scm (anystyle)[arguments]: Instead of deleting the
'check' phase, replace it with a few tests. Add SRFI 1 to '#:modules'.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 0b558de6db..2dba81c2a1 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13613,6 +13613,7 @@ though the later has not yet been packaged for Guix.")
       #:modules
       `((guix build ruby-build-system)
         (ice-9 popen)
+        (srfi srfi-1)
         (guix build utils))
       #:phases
       #~(modify-phases %standard-phases
@@ -13621,7 +13622,30 @@ though the later has not yet been packaged for Guix.")
               (substitute* "anystyle-cli.gemspec"
                 (("'bibtex-ruby', '[^']*'")
                  "'bibtex-ruby'"))))
-          (delete 'check) ;; there are no upstream tests
+          (replace 'check
+            (lambda* (#:key tests? #:allow-other-keys)
+              ;; There are no tests, but let's use this opportunity to do a
+              ;; basic test of our own that things run ok. It works especially
+              ;; well to test this here since we know the 'ruby-anystile'
+              ;; package is in its final, immutable installed form.
+              (when tests?
+                (let ((common
+                       `("require 'anystyle'"
+                         ,(string-append
+                           "pp AnyStyle.parse 'Derrida, J. (1967). L’écriture"
+                           " et la différence (1 éd.). Paris: Éditions du"
+                           " Seuil.'"))))
+                  (for-each
+                   (lambda (lines)
+                     (apply invoke "ruby"
+                            (fold-right (lambda (line lst)
+                                          (cons* "-e" line lst))
+                                        '()
+                                        lines)))
+                   `(,common
+                     ("require 'anystyle/dictionary'"
+                      "AnyStyle::Dictionary.defaults[:adapter] = :gdbm"
+                      ,@common)))))))
           (add-after 'wrap 'check-cli
             (lambda* (#:key tests? outputs #:allow-other-keys)
               (when tests?
-- 
cgit v1.2.3


From c90c1698e1e256f8c42558caed077850e92c6434 Mon Sep 17 00:00:00 2001
From: Philip McGrath 
Date: Mon, 25 Jul 2022 08:16:35 -0400
Subject: gnu: anystyle: Use GDBM by default.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since we have GDBM available, it offers a smaller memory footprint
and faster start-up.

* gnu/packages/ruby.scm (anystyle)[arguments]<#:phases>: Add phase
'change-default-dictionary-adapter'.

Signed-off-by: Ludovic Courtès 
---
 gnu/packages/ruby.scm | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'gnu/packages/ruby.scm')

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index 2dba81c2a1..cc95bd8d6e 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -13622,6 +13622,14 @@ though the later has not yet been packaged for Guix.")
               (substitute* "anystyle-cli.gemspec"
                 (("'bibtex-ruby', '[^']*'")
                  "'bibtex-ruby'"))))
+          (add-before 'build 'change-default-dictionary-adapter
+            (lambda args
+              ;; Since we always have gdbm available, using it will give a
+              ;; faster startup time, which is particularly worth-while for
+              ;; a command-line tool.
+              (substitute* "bin/anystyle"
+                (("default_value: 'ruby',")
+                 "default_value: 'gdbm', # patched for Guix"))))
           (replace 'check
             (lambda* (#:key tests? #:allow-other-keys)
               ;; There are no tests, but let's use this opportunity to do a
-- 
cgit v1.2.3