From 326b8d9031af2859b879eb1dcd63512517a8fa3d Mon Sep 17 00:00:00 2001 From: Thomas Sawyer Date: Mon, 30 Nov 2026 01:08:50 -0500 Subject: [PATCH] Modernize: Ruby 3.1+, plain gemspec, tests on Spectrum, CI The tests move from Citron to Spectrum with no change but the require, and run in CI on Ruby 3.1 to 4.0. TomParse::VERSION is added. Fixes a line break that was left in the description of an argument's option when it ran over more than one line. The History's 0.4.3 entry, which was never published, becomes part of 0.5.0. The old build files are removed. Co-Authored-By: Claude Fable 5.2 --- .gemspec | 307 --------------------------------------- .github/workflows/ci.yml | 30 ++++ .gitignore | 14 +- .index | 70 --------- .travis.yml | 13 -- Assembly | 22 --- CONTRIBUTING.md | 19 +-- Gemfile | 2 +- HISTORY.md | 14 +- INDEX.yml | 51 ------- MANIFEST.txt | 22 --- README.md | 18 +-- Rakefile | 21 +++ Rulebook | 48 ------ lib/tomparse.rb | 1 + lib/tomparse.yml | 1 - lib/tomparse/argument.rb | 2 +- lib/tomparse/version.rb | 4 + test/helper.rb | 1 - test/test_arguments.rb | 29 ++++ tomparse.gemspec | 32 ++++ 21 files changed, 155 insertions(+), 566 deletions(-) delete mode 100644 .gemspec create mode 100644 .github/workflows/ci.yml delete mode 100644 .index delete mode 100644 .travis.yml delete mode 100644 Assembly delete mode 100644 INDEX.yml delete mode 100644 MANIFEST.txt create mode 100644 Rakefile delete mode 100644 Rulebook delete mode 120000 lib/tomparse.yml create mode 100644 lib/tomparse/version.rb create mode 100644 tomparse.gemspec diff --git a/.gemspec b/.gemspec deleted file mode 100644 index ea0db60..0000000 --- a/.gemspec +++ /dev/null @@ -1,307 +0,0 @@ -# encoding: utf-8 - -require 'yaml' -require 'pathname' - -module Indexer - - # Convert index data into a gemspec. - # - # Notes: - # * Assumes all executables are in bin/. - # * Does not yet handle default_executable setting. - # * Does not yet handle platform setting. - # * Does not yet handle required_ruby_version. - # * Support for rdoc entries is weak. - # - class GemspecExporter - - # File globs to include in package --unless a manifest file exists. - FILES = ".index .yardopts alt bin data demo ext features lib man spec test try* [A-Z]*.*" unless defined?(FILES) - - # File globs to omit from FILES. - OMIT = "Config.rb" unless defined?(OMIT) - - # Standard file patterns. - PATTERNS = { - :root => '{.index,Gemfile}', - :bin => 'bin/*', - :lib => 'lib/{**/}*', #.rb', - :ext => 'ext/{**/}extconf.rb', - :doc => '*.{txt,rdoc,md,markdown,tt,textile}', - :test => '{test,spec}/{**/}*.rb' - } unless defined?(PATTERNS) - - # For which revision of indexer spec is this converter intended? - REVISION = 2013 unless defined?(REVISION) - - # - def self.gemspec - new.to_gemspec - end - - # - attr :metadata - - # - def initialize(metadata=nil) - @root_check = false - - if metadata - root_dir = metadata.delete(:root) - if root_dir - @root = root_dir - @root_check = true - end - metadata = nil if metadata.empty? - end - - @metadata = metadata || YAML.load_file(root + '.index') - - if @metadata['revision'].to_i != REVISION - warn "This gemspec exporter was not designed for this revision of index metadata." - end - end - - # - def has_root? - root ? true : false - end - - # - def root - return @root if @root || @root_check - @root_check = true - @root = find_root - end - - # - def manifest - return nil unless root - @manifest ||= Dir.glob(root + 'manifest{,.txt}', File::FNM_CASEFOLD).first - end - - # - def scm - return nil unless root - @scm ||= %w{git hg}.find{ |m| (root + ".#{m}").directory? }.to_sym - end - - # - def files - return [] unless root - @files ||= \ - if manifest - File.readlines(manifest). - map{ |line| line.strip }. - reject{ |line| line.empty? || line[0,1] == '#' } - else - list = [] - Dir.chdir(root) do - FILES.split(/\s+/).each do |pattern| - list.concat(glob(pattern)) - end - OMIT.split(/\s+/).each do |pattern| - list = list - glob(pattern) - end - end - list - end.select{ |path| File.file?(path) }.uniq - end - - # - def glob_files(pattern) - return [] unless root - Dir.chdir(root) do - Dir.glob(pattern).select do |path| - File.file?(path) && files.include?(path) - end - end - end - - def patterns - PATTERNS - end - - def executables - @executables ||= \ - glob_files(patterns[:bin]).map do |path| - File.basename(path) - end - end - - def extensions - @extensions ||= \ - glob_files(patterns[:ext]).map do |path| - File.basename(path) - end - end - - def name - metadata['name'] || metadata['title'].downcase.gsub(/\W+/,'_') - end - - def homepage - page = ( - metadata['resources'].find{ |r| r['type'] =~ /^home/i } || - metadata['resources'].find{ |r| r['name'] =~ /^home/i } || - metadata['resources'].find{ |r| r['name'] =~ /^web/i } - ) - page ? page['uri'] : false - end - - def licenses - metadata['copyrights'].map{ |c| c['license'] }.compact - end - - def require_paths - paths = metadata['paths'] || {} - paths['load'] || ['lib'] - end - - # - # Convert to gemnspec. - # - def to_gemspec - if has_root? - Gem::Specification.new do |gemspec| - to_gemspec_data(gemspec) - to_gemspec_paths(gemspec) - end - else - Gem::Specification.new do |gemspec| - to_gemspec_data(gemspec) - to_gemspec_paths(gemspec) - end - end - end - - # - # Convert pure data settings. - # - def to_gemspec_data(gemspec) - gemspec.name = name - gemspec.version = metadata['version'] - gemspec.summary = metadata['summary'] - gemspec.description = metadata['description'] - - metadata['authors'].each do |author| - gemspec.authors << author['name'] - - if author.has_key?('email') - if gemspec.email - gemspec.email << author['email'] - else - gemspec.email = [author['email']] - end - end - end - - gemspec.licenses = licenses - - requirements = metadata['requirements'] || [] - requirements.each do |req| - next if req['optional'] - next if req['external'] - - name = req['name'] - groups = req['groups'] || [] - - version = gemify_version(req['version']) - - if groups.empty? or groups.include?('runtime') - # populate runtime dependencies - if gemspec.respond_to?(:add_runtime_dependency) - gemspec.add_runtime_dependency(name,*version) - else - gemspec.add_dependency(name,*version) - end - else - # populate development dependencies - if gemspec.respond_to?(:add_development_dependency) - gemspec.add_development_dependency(name,*version) - else - gemspec.add_dependency(name,*version) - end - end - end - - # convert external dependencies into gemspec requirements - requirements.each do |req| - next unless req['external'] - gemspec.requirements << ("%s-%s" % req.values_at('name', 'version')) - end - - gemspec.homepage = homepage - gemspec.require_paths = require_paths - gemspec.post_install_message = metadata['install_message'] - end - - # - # Set gemspec settings that require a root directory path. - # - def to_gemspec_paths(gemspec) - gemspec.files = files - gemspec.extensions = extensions - gemspec.executables = executables - - if Gem::VERSION < '1.7.' - gemspec.default_executable = gemspec.executables.first - end - - gemspec.test_files = glob_files(patterns[:test]) - - unless gemspec.files.include?('.document') - gemspec.extra_rdoc_files = glob_files(patterns[:doc]) - end - end - - # - # Return a copy of this file. This is used to generate a local - # .gemspec file that can automatically read the index file. - # - def self.source_code - File.read(__FILE__) - end - - private - - def find_root - root_files = patterns[:root] - if Dir.glob(root_files).first - Pathname.new(Dir.pwd) - elsif Dir.glob("../#{root_files}").first - Pathname.new(Dir.pwd).parent - else - #raise "Can't find root of project containing `#{root_files}'." - warn "Can't find root of project containing `#{root_files}'." - nil - end - end - - def glob(pattern) - if File.directory?(pattern) - Dir.glob(File.join(pattern, '**', '*')) - else - Dir.glob(pattern) - end - end - - def gemify_version(version) - case version - when /^(.*?)\+$/ - ">= #{$1}" - when /^(.*?)\-$/ - "< #{$1}" - when /^(.*?)\~$/ - "~> #{$1}" - else - version - end - end - - end - -end - -Indexer::GemspecExporter.gemspec \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8d5fbaa --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + # Monthly, to catch breakage from new Ruby or dependency releases + # when nothing has been pushed. + schedule: + - cron: '0 6 1 * *' + +permissions: + contents: read + +jobs: + test: + name: Ruby ${{ matrix.ruby }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['3.1', '3.2', '3.3', '3.4', '4.0'] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Tests + run: bundle exec rake test diff --git a/.gitignore b/.gitignore index 8f83e19..c494295 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -.ergo/digest/ -.yardoc/ -log/ -pkg/ -web/ -/Gemfile.lock +.yardoc +log +pkg +tmp +doc +web +*.gem +Gemfile.lock diff --git a/.index b/.index deleted file mode 100644 index 0dc00c1..0000000 --- a/.index +++ /dev/null @@ -1,70 +0,0 @@ ---- -revision: 2013 -type: ruby -sources: -- INDEX.yml -authors: -- name: trans - email: transfire@gmail.com -organizations: -- name: Rubyworks - website: http://rubyworks.github.com -requirements: -- groups: - - test - development: true - name: rubytest -- groups: - - test - development: true - name: rubytest-cli -- groups: - - test - development: true - name: citron -- groups: - - test - development: true - name: ae -- groups: - - build - development: true - name: rulebow -conflicts: [] -alternatives: [] -resources: -- type: home - uri: http://rubyworks.github.com/tomparse - label: Homepage -- type: code - uri: http://github.com/rubyworks/tomparse - label: Source Code -- type: api - uri: http://rubydoc.info/gems/tomparse/frames - label: API Guide -- type: chat - uri: http://chat.us.freenode.net/rubyworks - label: IRC Channel -repositories: -- name: upstream - scm: git - uri: https://github.com/rubyworks/tomparse/tomparse.git -categories: -- documentation -copyrights: -- holder: Rubyworks - year: '2012' - license: BSD-2-Clause -customs: [] -paths: - lib: - - lib -name: tomparse -title: TomParse -version: 0.4.3 -summary: TomDoc parser for Ruby -description: TomParse provides no other functionality than to take a code comment - and parse it in to a convenient object-oriented structure in accordance with TomDoc - standard. -created: '2012-03-04' -date: '2015-03-21' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1894b5c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -language: ruby -script: "bundle exec rubytest -Ilib test/" -rvm: - - 2.1.0 - - 2.0.0 - - 1.9.3 - - rbx - - jruby -matrix: - allow_failures: - - rvm: rbx -cache: bundler diff --git a/Assembly b/Assembly deleted file mode 100644 index 5f68b83..0000000 --- a/Assembly +++ /dev/null @@ -1,22 +0,0 @@ ---- -github: - gh_pages: web - -gem: - active: true - -dnote: - title: Source Notes - output: log/notes.html - -vclog: - output: - - log/history.html - - log/changes.html - active: false - -email: - mailto: - - ruby-talk@ruby-lang.org - - rubyworks-mailinglist@googlegroups.com - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c4aefec..04a725f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,25 +1,22 @@ # CONTRIBUTING -## Build Requirements +## Requirements -* [Rubytest](http://rubyworks.github.com/rubytest) (testing) -* [Citron](http://rubyworks.github.com/citron) (testing) -* [AE](http://rubyworks.github.com/ae) (testing) -* [Rulebow](http://detroit.github.com/rulebow) (building) -* [Detroit](http://detroit.github.com/detroit) (building) +* [Rubytest](https://github.com/rubyworks/rubytest) (testing) +* [Spectrum](https://github.com/rubyworks/spectrum) (testing) +* [AE](https://github.com/rubyworks/ae) (testing) -The last is not being used currently, but will be once it is fixed. +Install them with `bundle install`. ## Running Tests To run the test suite use: - $ bundle exec rubytest -Ilib test/ + $ bundle exec rake test -To add test coverage use: - - $ bundle exec rubytest -c simplecov -Ilib test/ +To add test coverage, install SimpleCov and use: + $ coverage=1 bundle exec rake test diff --git a/Gemfile b/Gemfile index 1aa98e4..3be9c3c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ -source "http://rubygems.org" +source "https://rubygems.org" gemspec diff --git a/HISTORY.md b/HISTORY.md index 3e24240..e780489 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,12 +1,20 @@ # Release History -## 0.4.3 / 2015-03-21 +## 0.5.0 / UNRELEASED -This release fixes option parsing. +TomParse is brought up to date: it needs Ruby 3.1 or newer. This release +also carries the fixes made since 0.4.2, which were never published +(a 0.4.3 was prepared in 2015 but not released). Changes: -* Fix option parsing. +* Fix parsing of options that run over more than one line. (Faraz Yashar) +* Fix a line break left in the description of an argument's option when + it ran over more than one line. +* Add `TomDoc#labels` as an alias of `#tags`. +* Add `TomParse::VERSION`. +* Fix typos in the documentation. (Chayoung You) +* Tests run on Spectrum, in CI on Ruby 3.1 to 4.0. ## 0.4.2 / 2013-02-15 diff --git a/INDEX.yml b/INDEX.yml deleted file mode 100644 index 17a91ff..0000000 --- a/INDEX.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -name: - tomparse - -version: - 0.4.3 - -title: - TomParse - -summary: - TomDoc parser for Ruby - -description: - TomParse provides no other functionality than to take a code comment - and parse it in to a convenient object-oriented structure in accordance - with TomDoc standard. - -resources: - home: http://rubyworks.github.com/tomparse - code: http://github.com/rubyworks/tomparse - api: http://rubydoc.info/gems/tomparse/frames - chat: http://chat.us.freenode.net/rubyworks - -requirements: - - rubytest (test) - - rubytest-cli (test) - - citron (test) - - ae (test) - - rulebow (build) - #- detroit (build) - -authors: - - trans - -organizations: - - name: Rubyworks - website: http://rubyworks.github.com - -repositories: - upstream: https://github.com/rubyworks/tomparse/tomparse.git - -categories: - - documentation - -created: - 2012-03-04 - -copyrights: - - Copyright 2012 Rubyworks (BSD-2-Clause) - diff --git a/MANIFEST.txt b/MANIFEST.txt deleted file mode 100644 index 7f2c5aa..0000000 --- a/MANIFEST.txt +++ /dev/null @@ -1,22 +0,0 @@ -#!mast .index .yardopts bin demo lib man test spec *.md *.txt -.index -.yardopts -lib/tomparse/argument.rb -lib/tomparse/option.rb -lib/tomparse/parse_error.rb -lib/tomparse/parser.rb -lib/tomparse.rb -lib/tomparse.yml -test/helper.rb -test/test_arguments.rb -test/test_description.rb -test/test_examples.rb -test/test_options.rb -test/test_prefixes.rb -test/test_signatures.rb -test/test_tags.rb -test/test_tomdoc.rb -test/test_yields.rb -README.md -HISTORY.md -LICENSE.txt diff --git a/README.md b/README.md index 8dd51f4..8b7736f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# [TomParse](http://rubyworks.github.io//tomparse) +# [TomParse](https://rubyworks.github.io/tomparse) [![Version](https://img.shields.io/gem/v/tomparse.svg)](https://rubygems.org/gems/tomparse) -[![Build Status](https://travis-ci.org/rubyworks/tomparse.svg?branch=master)](https://travis-ci.org/rubyworks/tomparse) +[![CI](https://github.com/rubyworks/tomparse/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyworks/tomparse/actions/workflows/ci.yml) [![Issues](https://img.shields.io/github/issues-raw/rubyworks/tomparse.svg)](https://github.com/rubyworks/tomparse/issues) TomParse is a TomDoc parser for Ruby. It provides no other functionality than @@ -52,6 +52,8 @@ TomParse is available as a Ruby gem. $ gem install tomparse +TomParse needs Ruby 3.1 or newer. + Use with Bundler by adding to your Gemfile (gems.rb file in the future). gem "tomparse" @@ -164,11 +166,9 @@ with the more traditional concept of method signatures. ## Resources -* [Website](http://rubyworks.github.com/tomparse) -* [Source Code](http://github.com/rubyworks/tomparse) (Github) -* [API Reference](http://rubydoc.info/gems/tomparse/frames") -* [IRC Chat](http://chat.us.freenode.net/rubyworks) -* [Upstream Repo](http://github.com/rubyworks/tomparse/tomparse.git) +* [Website](https://rubyworks.github.io/tomparse) +* [Source Code](https://github.com/rubyworks/tomparse) +* [API Reference](https://rubydoc.info/gems/tomparse) ## Authors @@ -186,9 +186,9 @@ with the more traditional concept of method signatures. TomParse is copyrighted open-source software. -Copyright (c) 2012 [Rubyworks](http://rubyworks.github.com). All rights reserved. +Copyright (c) 2012 [Rubyworks](https://github.com/rubyworks). All rights reserved. -TomParse is distributable under the terms of the [BSD-2-Clause]((http://www.spdx.org/licenses/BSD-2-Clause) license. +TomParse is distributable under the terms of the [BSD-2-Clause](https://spdx.org/licenses/BSD-2-Clause) license. See LICENSE.txt for details. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2807f35 --- /dev/null +++ b/Rakefile @@ -0,0 +1,21 @@ +require 'rake/clean' +CLOBBER.include 'pkg' + +require 'bundler/gem_helper' + +# Bundler tags releases as v1.2.3, but TomParse's tags have always been +# plain version numbers, so keep it that way. +class Bundler::GemHelper + def version_tag + version.to_s + end +end + +Bundler::GemHelper.install_tasks + +desc 'run tests' +task 'test' do + sh 'rubytest -Ilib -r spectrum/testcase -r ./test/helper test/test_*.rb' +end + +task 'default' => 'test' diff --git a/Rulebook b/Rulebook deleted file mode 100644 index aa21cea..0000000 --- a/Rulebook +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env ruby - -# global ignore -ignore 'pkg', 'doc', 'site', 'log' - -## -# Default -# -ruleset :default => [:index, :manifest, :demo] - -ruleset :manifest do - desc "update manifest" - - fact :need_manifest? do - ! system 'mast --quiet --verify' - end - - rule :need_manifest? do - sh 'mast -u' - end -end - -ruleset :test do - desc "run tests" - - rule 'test/test_*.rb' do |files| - sh 'rubytest -Ilib ' + files.join(' ') - #require 'rubytest' - #Test::Runner.run do |run| - # run.loadpath << 'lib' - # run.files << files - #end - end - - rule 'lib/**/*.rb' do |files| - sh 'rubytest -Ilib test/test_*.rb', 'coverage'=>'true' - end -end - -ruleset :index do - desc "update .index file" - - rule 'INDEX.yml' do - shell "index -u INDEX.yml" - end -end - - diff --git a/lib/tomparse.rb b/lib/tomparse.rb index e7a3cec..c411cd0 100644 --- a/lib/tomparse.rb +++ b/lib/tomparse.rb @@ -1,4 +1,5 @@ module TomParse + require 'tomparse/version' require 'tomparse/parser' require 'tomparse/parse_error' require 'tomparse/argument' diff --git a/lib/tomparse.yml b/lib/tomparse.yml deleted file mode 120000 index f018114..0000000 --- a/lib/tomparse.yml +++ /dev/null @@ -1 +0,0 @@ -../.index \ No newline at end of file diff --git a/lib/tomparse/argument.rb b/lib/tomparse/argument.rb index 3dcff8d..a4c48e2 100644 --- a/lib/tomparse/argument.rb +++ b/lib/tomparse/argument.rb @@ -53,7 +53,7 @@ def parse(description) indent = line.scan(/^\s*/)[0].to_s.size if last_indent && indent > last_indent - opts.last.description << line.squeeze(" ") + opts.last.description << " " << line.strip.squeeze(" ") else param, d = line.split(" - ") opts << Option.new(param.strip, d.strip) if param && d diff --git a/lib/tomparse/version.rb b/lib/tomparse/version.rb new file mode 100644 index 0000000..779b59b --- /dev/null +++ b/lib/tomparse/version.rb @@ -0,0 +1,4 @@ +module TomParse + # The version of TomParse. + VERSION = '0.5.0' +end diff --git a/test/helper.rb b/test/helper.rb index 0dcf578..cdc4e9f 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,4 +1,3 @@ -require 'citron' require 'ae' if ENV['coverage'] diff --git a/test/test_arguments.rb b/test/test_arguments.rb index c774a2e..e3fdb74 100644 --- a/test/test_arguments.rb +++ b/test/test_arguments.rb @@ -214,4 +214,33 @@ end end + context "argument with options of its own" do + setup do + @comment = TomParse::TomDoc.new %{ + # Duplicate some text an arbitrary number of times. + # + # text - The String to be duplicated. + # opts - Options for how it is done: + # :sep - A String to put between the copies, + # which may go on to another line. + # :count - The Integer number of copies. Required. + # + # Returns the duplicated String. + } + end + test "knows the argument's description" do + @comment.args[1].description.assert == "Options for how it is done:" + end + test "knows the argument's options" do + @comment.args[1].options.map(&:name).assert == [:":sep", :":count"] + end + test "joins an option's description over lines" do + @comment.args[1].options[0].description.assert == + "A String to put between the copies, which may go on to another line." + end + test "knows which options are required" do + @comment.args[1].options.map(&:required?).assert == [false, true] + end + end + end diff --git a/tomparse.gemspec b/tomparse.gemspec new file mode 100644 index 0000000..467d87a --- /dev/null +++ b/tomparse.gemspec @@ -0,0 +1,32 @@ +require_relative 'lib/tomparse/version' + +Gem::Specification.new do |s| + s.name = 'tomparse' + s.version = TomParse::VERSION + s.summary = 'TomDoc parser for Ruby' + s.description = 'TomParse provides no other functionality than to take a code ' \ + 'comment and parse it in to a convenient object-oriented ' \ + 'structure in accordance with TomDoc standard.' + + s.authors = ['Trans'] + s.email = ['transfire@gmail.com'] + s.homepage = 'https://github.com/rubyworks/tomparse' + s.license = 'BSD-2-Clause' + + s.metadata = { + 'source_code_uri' => 'https://github.com/rubyworks/tomparse', + 'bug_tracker_uri' => 'https://github.com/rubyworks/tomparse/issues', + 'changelog_uri' => 'https://github.com/rubyworks/tomparse/blob/master/HISTORY.md', + 'documentation_uri' => 'https://rubydoc.info/gems/tomparse' + } + + s.required_ruby_version = '>= 3.1' + + s.files = Dir['lib/**/*.rb', 'README.md', 'HISTORY.md', 'LICENSE.txt'] + s.require_paths = ['lib'] + + s.add_development_dependency 'rake', '>= 13' + s.add_development_dependency 'rubytest', '>= 0.11.1' + s.add_development_dependency 'spectrum', '>= 0.2' + s.add_development_dependency 'ae', '>= 1.9' +end