Skip to content

Commit

Permalink
Relative loading for easier development (#821)
Browse files Browse the repository at this point in the history
This patch makes sure we only load relative code. Hence when coding or
testing rdoc, we'll be sure to always be using the correct code.

Discussion started at #817.

Signed-off-by: Ulysse Buonomo <buonomo.ulysse@gmail.com>

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
  • Loading branch information
BuonOmo and nobu authored Feb 10, 2022
1 parent 6600f2d commit aa41bd4
Show file tree
Hide file tree
Showing 43 changed files with 147 additions and 163 deletions.
9 changes: 5 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$:.unshift File.expand_path 'lib'
require 'rdoc/task'
# frozen_string_literal: true

require_relative 'lib/rdoc/task'
require 'bundler/gem_tasks'
require 'rake/testtask'

Expand Down Expand Up @@ -34,14 +35,14 @@ task ghpages: :rdoc do
end

Rake::TestTask.new(:normal_test) do |t|
t.libs << "test/rdoc"
t.libs = []
t.verbose = true
t.deps = :generate
t.test_files = FileList["test/**/test_*.rb"].exclude("test/rdoc/test_rdoc_rubygems_hook.rb")
end

Rake::TestTask.new(:rubygems_test) do |t|
t.libs << "test/rdoc"
t.libs = []
t.verbose = true
t.deps = :generate
t.pattern = "test/rdoc/test_rdoc_rubygems_hook.rb"
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "rdoc"
require_relative "../lib/rdoc"

require "irb"
IRB.start
1 change: 0 additions & 1 deletion exe/rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ rescue Exception => e

exit 1
end

92 changes: 46 additions & 46 deletions lib/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module RDoc

class Error < RuntimeError; end

require 'rdoc/version'
require_relative 'rdoc/version'

##
# Method visibilities
Expand Down Expand Up @@ -141,61 +141,61 @@ def self.home
end
end

autoload :RDoc, 'rdoc/rdoc'
autoload :RDoc, "#{__dir__}/rdoc/rdoc"

autoload :CrossReference, 'rdoc/cross_reference'
autoload :ERBIO, 'rdoc/erbio'
autoload :ERBPartial, 'rdoc/erb_partial'
autoload :Encoding, 'rdoc/encoding'
autoload :Generator, 'rdoc/generator'
autoload :Options, 'rdoc/options'
autoload :Parser, 'rdoc/parser'
autoload :Servlet, 'rdoc/servlet'
autoload :RI, 'rdoc/ri'
autoload :Stats, 'rdoc/stats'
autoload :Store, 'rdoc/store'
autoload :Task, 'rdoc/task'
autoload :Text, 'rdoc/text'
autoload :CrossReference, "#{__dir__}/rdoc/cross_reference"
autoload :ERBIO, "#{__dir__}/rdoc/erbio"
autoload :ERBPartial, "#{__dir__}/rdoc/erb_partial"
autoload :Encoding, "#{__dir__}/rdoc/encoding"
autoload :Generator, "#{__dir__}/rdoc/generator"
autoload :Options, "#{__dir__}/rdoc/options"
autoload :Parser, "#{__dir__}/rdoc/parser"
autoload :Servlet, "#{__dir__}/rdoc/servlet"
autoload :RI, "#{__dir__}/rdoc/ri"
autoload :Stats, "#{__dir__}/rdoc/stats"
autoload :Store, "#{__dir__}/rdoc/store"
autoload :Task, "#{__dir__}/rdoc/task"
autoload :Text, "#{__dir__}/rdoc/text"

autoload :Markdown, 'rdoc/markdown'
autoload :Markup, 'rdoc/markup'
autoload :RD, 'rdoc/rd'
autoload :TomDoc, 'rdoc/tom_doc'
autoload :Markdown, "#{__dir__}/rdoc/markdown"
autoload :Markup, "#{__dir__}/rdoc/markup"
autoload :RD, "#{__dir__}/rdoc/rd"
autoload :TomDoc, "#{__dir__}/rdoc/tom_doc"

autoload :KNOWN_CLASSES, 'rdoc/known_classes'
autoload :KNOWN_CLASSES, "#{__dir__}/rdoc/known_classes"

autoload :TokenStream, 'rdoc/token_stream'
autoload :TokenStream, "#{__dir__}/rdoc/token_stream"

autoload :Comment, 'rdoc/comment'
autoload :Comment, "#{__dir__}/rdoc/comment"

require 'rdoc/i18n'
require_relative 'rdoc/i18n'

# code objects
#
# We represent the various high-level code constructs that appear in Ruby
# programs: classes, modules, methods, and so on.
autoload :CodeObject, 'rdoc/code_object'

autoload :Context, 'rdoc/context'
autoload :TopLevel, 'rdoc/top_level'

autoload :AnonClass, 'rdoc/anon_class'
autoload :ClassModule, 'rdoc/class_module'
autoload :NormalClass, 'rdoc/normal_class'
autoload :NormalModule, 'rdoc/normal_module'
autoload :SingleClass, 'rdoc/single_class'

autoload :Alias, 'rdoc/alias'
autoload :AnyMethod, 'rdoc/any_method'
autoload :MethodAttr, 'rdoc/method_attr'
autoload :GhostMethod, 'rdoc/ghost_method'
autoload :MetaMethod, 'rdoc/meta_method'
autoload :Attr, 'rdoc/attr'

autoload :Constant, 'rdoc/constant'
autoload :Mixin, 'rdoc/mixin'
autoload :Include, 'rdoc/include'
autoload :Extend, 'rdoc/extend'
autoload :Require, 'rdoc/require'
autoload :CodeObject, "#{__dir__}/rdoc/code_object"

autoload :Context, "#{__dir__}/rdoc/context"
autoload :TopLevel, "#{__dir__}/rdoc/top_level"

autoload :AnonClass, "#{__dir__}/rdoc/anon_class"
autoload :ClassModule, "#{__dir__}/rdoc/class_module"
autoload :NormalClass, "#{__dir__}/rdoc/normal_class"
autoload :NormalModule, "#{__dir__}/rdoc/normal_module"
autoload :SingleClass, "#{__dir__}/rdoc/single_class"

autoload :Alias, "#{__dir__}/rdoc/alias"
autoload :AnyMethod, "#{__dir__}/rdoc/any_method"
autoload :MethodAttr, "#{__dir__}/rdoc/method_attr"
autoload :GhostMethod, "#{__dir__}/rdoc/ghost_method"
autoload :MetaMethod, "#{__dir__}/rdoc/meta_method"
autoload :Attr, "#{__dir__}/rdoc/attr"

autoload :Constant, "#{__dir__}/rdoc/constant"
autoload :Mixin, "#{__dir__}/rdoc/mixin"
autoload :Include, "#{__dir__}/rdoc/include"
autoload :Extend, "#{__dir__}/rdoc/extend"
autoload :Require, "#{__dir__}/rdoc/require"

end
3 changes: 1 addition & 2 deletions lib/rdoc/code_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
# This file was used to load all the RDoc::CodeObject subclasses at once. Now
# autoload handles this.

require 'rdoc'

require_relative '../rdoc'
2 changes: 1 addition & 1 deletion lib/rdoc/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,6 @@ def upgrade_to_class mod, class_type, enclosing
klass
end

autoload :Section, 'rdoc/context/section'
autoload :Section, "#{__dir__}/context/section"

end
10 changes: 5 additions & 5 deletions lib/rdoc/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@

module RDoc::Generator

autoload :Markup, 'rdoc/generator/markup'
autoload :Markup, "#{__dir__}/generator/markup"

autoload :Darkfish, 'rdoc/generator/darkfish'
autoload :JsonIndex, 'rdoc/generator/json_index'
autoload :RI, 'rdoc/generator/ri'
autoload :POT, 'rdoc/generator/pot'
autoload :Darkfish, "#{__dir__}/generator/darkfish"
autoload :JsonIndex, "#{__dir__}/generator/json_index"
autoload :RI, "#{__dir__}/generator/ri"
autoload :POT, "#{__dir__}/generator/pot"

end
2 changes: 1 addition & 1 deletion lib/rdoc/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module RDoc::I18n

autoload :Locale, 'rdoc/i18n/locale'
autoload :Locale, "#{__dir__}/i18n/locale"
require_relative 'i18n/text'

end
8 changes: 4 additions & 4 deletions lib/rdoc/markdown.kpeg
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@

%% {

require 'rdoc'
require 'rdoc/markup/to_joined_paragraph'
require 'rdoc/markdown/entities'
require_relative '../rdoc'
require_relative 'markup/to_joined_paragraph'
require_relative 'markdown/entities'

require 'rdoc/markdown/literals'
require_relative 'markdown/literals'

##
# Supported extensions
Expand Down
67 changes: 33 additions & 34 deletions lib/rdoc/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -822,46 +822,45 @@ def convert input, formatter
document.accept formatter
end

autoload :Parser, 'rdoc/markup/parser'
autoload :PreProcess, 'rdoc/markup/pre_process'
autoload :Parser, "#{__dir__}/markup/parser"
autoload :PreProcess, "#{__dir__}/markup/pre_process"

# Inline markup classes
autoload :AttrChanger, 'rdoc/markup/attr_changer'
autoload :AttrSpan, 'rdoc/markup/attr_span'
autoload :Attributes, 'rdoc/markup/attributes'
autoload :AttributeManager, 'rdoc/markup/attribute_manager'
autoload :RegexpHandling, 'rdoc/markup/regexp_handling'
autoload :AttrChanger, "#{__dir__}/markup/attr_changer"
autoload :AttrSpan, "#{__dir__}/markup/attr_span"
autoload :Attributes, "#{__dir__}/markup/attributes"
autoload :AttributeManager, "#{__dir__}/markup/attribute_manager"
autoload :RegexpHandling, "#{__dir__}/markup/regexp_handling"

# RDoc::Markup AST
autoload :BlankLine, 'rdoc/markup/blank_line'
autoload :BlockQuote, 'rdoc/markup/block_quote'
autoload :Document, 'rdoc/markup/document'
autoload :HardBreak, 'rdoc/markup/hard_break'
autoload :Heading, 'rdoc/markup/heading'
autoload :Include, 'rdoc/markup/include'
autoload :IndentedParagraph, 'rdoc/markup/indented_paragraph'
autoload :List, 'rdoc/markup/list'
autoload :ListItem, 'rdoc/markup/list_item'
autoload :Paragraph, 'rdoc/markup/paragraph'
autoload :Table, 'rdoc/markup/table'
autoload :Raw, 'rdoc/markup/raw'
autoload :Rule, 'rdoc/markup/rule'
autoload :Verbatim, 'rdoc/markup/verbatim'
autoload :BlankLine, "#{__dir__}/markup/blank_line"
autoload :BlockQuote, "#{__dir__}/markup/block_quote"
autoload :Document, "#{__dir__}/markup/document"
autoload :HardBreak, "#{__dir__}/markup/hard_break"
autoload :Heading, "#{__dir__}/markup/heading"
autoload :Include, "#{__dir__}/markup/include"
autoload :IndentedParagraph, "#{__dir__}/markup/indented_paragraph"
autoload :List, "#{__dir__}/markup/list"
autoload :ListItem, "#{__dir__}/markup/list_item"
autoload :Paragraph, "#{__dir__}/markup/paragraph"
autoload :Table, "#{__dir__}/markup/table"
autoload :Raw, "#{__dir__}/markup/raw"
autoload :Rule, "#{__dir__}/markup/rule"
autoload :Verbatim, "#{__dir__}/markup/verbatim"

# Formatters
autoload :Formatter, 'rdoc/markup/formatter'
autoload :Formatter, "#{__dir__}/markup/formatter"

autoload :ToAnsi, 'rdoc/markup/to_ansi'
autoload :ToBs, 'rdoc/markup/to_bs'
autoload :ToHtml, 'rdoc/markup/to_html'
autoload :ToHtmlCrossref, 'rdoc/markup/to_html_crossref'
autoload :ToHtmlSnippet, 'rdoc/markup/to_html_snippet'
autoload :ToLabel, 'rdoc/markup/to_label'
autoload :ToMarkdown, 'rdoc/markup/to_markdown'
autoload :ToRdoc, 'rdoc/markup/to_rdoc'
autoload :ToTableOfContents, 'rdoc/markup/to_table_of_contents'
autoload :ToTest, 'rdoc/markup/to_test'
autoload :ToTtOnly, 'rdoc/markup/to_tt_only'
autoload :ToAnsi, "#{__dir__}/markup/to_ansi"
autoload :ToBs, "#{__dir__}/markup/to_bs"
autoload :ToHtml, "#{__dir__}/markup/to_html"
autoload :ToHtmlCrossref, "#{__dir__}/markup/to_html_crossref"
autoload :ToHtmlSnippet, "#{__dir__}/markup/to_html_snippet"
autoload :ToLabel, "#{__dir__}/markup/to_label"
autoload :ToMarkdown, "#{__dir__}/markup/to_markdown"
autoload :ToRdoc, "#{__dir__}/markup/to_rdoc"
autoload :ToTableOfContents, "#{__dir__}/markup/to_table_of_contents"
autoload :ToTest, "#{__dir__}/markup/to_test"
autoload :ToTtOnly, "#{__dir__}/markup/to_tt_only"

end

4 changes: 2 additions & 2 deletions lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ def initialize top_level, file_name, content, options, stats
@preprocess.options = @options
end

autoload :RubyTools, 'rdoc/parser/ruby_tools'
autoload :Text, 'rdoc/parser/text'
autoload :RubyTools, "#{__dir__}/parser/ruby_tools"
autoload :Text, "#{__dir__}/parser/text"

end

Expand Down
7 changes: 3 additions & 4 deletions lib/rdoc/rd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ def self.parse rd
document
end

autoload :BlockParser, 'rdoc/rd/block_parser'
autoload :InlineParser, 'rdoc/rd/inline_parser'
autoload :Inline, 'rdoc/rd/inline'
autoload :BlockParser, "#{__dir__}/rd/block_parser"
autoload :InlineParser, "#{__dir__}/rd/inline_parser"
autoload :Inline, "#{__dir__}/rd/inline"

end

2 changes: 1 addition & 1 deletion lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'rdoc'
require_relative '../rdoc'

require 'find'
require 'fileutils'
Expand Down
9 changes: 4 additions & 5 deletions lib/rdoc/ri.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'rdoc'
require_relative '../rdoc'

##
# Namespace for the ri command line tool's implementation.
Expand All @@ -13,9 +13,8 @@ module RDoc::RI

class Error < RDoc::Error; end

autoload :Driver, 'rdoc/ri/driver'
autoload :Paths, 'rdoc/ri/paths'
autoload :Store, 'rdoc/ri/store'
autoload :Driver, "#{__dir__}/ri/driver"
autoload :Paths, "#{__dir__}/ri/paths"
autoload :Store, "#{__dir__}/ri/store"

end

2 changes: 1 addition & 1 deletion lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
rescue LoadError
end

require 'rdoc'
require_relative '../../rdoc'

##
# For RubyGems backwards compatibility
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/rubygems_hook.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'rubygems/user_interaction'
require 'fileutils'
require 'rdoc'
require_relative '../rdoc'

##
# Gem::RDoc provides methods to generate RDoc and ri data for installed gems
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/servlet.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'rdoc'
require_relative '../rdoc'
require 'erb'
require 'time'
require 'json'
Expand Down
7 changes: 3 additions & 4 deletions lib/rdoc/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,8 @@ def undoc_params method
[params.length, undoc]
end

autoload :Quiet, 'rdoc/stats/quiet'
autoload :Normal, 'rdoc/stats/normal'
autoload :Verbose, 'rdoc/stats/verbose'
autoload :Quiet, "#{__dir__}/stats/quiet"
autoload :Normal, "#{__dir__}/stats/normal"
autoload :Verbose, "#{__dir__}/stats/verbose"

end

2 changes: 1 addition & 1 deletion lib/rdoc/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
rescue Gem::LoadError
end unless defined?(Rake)

require 'rdoc'
require_relative '../rdoc'
require 'rake'
require 'rake/tasklib'

Expand Down
2 changes: 2 additions & 0 deletions lib/rdoc/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module RDoc

##
Expand Down
Loading

0 comments on commit aa41bd4

Please sign in to comment.