Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop pry as a runtime dependency #1259

Merged
merged 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem("minitest")
gem("minitest-hooks")
gem("minitest-reporters")
gem("debug", require: false)
gem("pry")
gem("pry-byebug")
gem("rubocop-shopify", require: false)
gem("rubocop-sorbet", ">= 0.4.1")
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ PATH
bundler (>= 1.17.3)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
pry (>= 0.12.2)
rbi (~> 0.0.0, >= 0.0.16)
sorbet-static-and-runtime (>= 0.5.9204)
spoom (~> 1.1.0, >= 1.1.11)
Expand Down Expand Up @@ -380,6 +379,7 @@ DEPENDENCIES
minitest-reporters
net-smtp (= 0.3.3)
nokogiri
pry
pry-byebug
rails
rake
Expand Down
10 changes: 4 additions & 6 deletions lib/tapioca/gem/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def compile_superclass(constant)

sig { params(constant: Module, strict: T::Boolean).returns(T::Boolean) }
def defined_in_gem?(constant, strict: true)
files = Set.new(get_file_candidates(constant))
files = get_file_candidates(constant)
.merge(Runtime::Trackers::ConstantDefinition.files_for(constant))

return !strict if files.empty?
Expand All @@ -352,13 +352,11 @@ def defined_in_gem?(constant, strict: true)
end
end

sig { params(constant: Module).returns(T::Array[String]) }
sig { params(constant: Module).returns(T::Set[String]) }
def get_file_candidates(constant)
wrapped_module = Pry::WrappedModule.new(constant)

wrapped_module.send(:method_candidates).flatten.filter_map(&:source_file).uniq
file_candidates_for(constant)
rescue ArgumentError, NameError
[]
Set.new
end

sig { params(name: String).void }
Expand Down
55 changes: 55 additions & 0 deletions lib/tapioca/runtime/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,61 @@ def attached_class_of(singleton_class)

T.cast(result, Module)
end

sig { params(constant: Module).returns(T::Set[String]) }
def file_candidates_for(constant)
relevant_methods_for(constant).filter_map do |method|
method.source_location&.first
end.to_set
end

private

sig { params(constant: Module).returns(T::Array[UnboundMethod]) }
def relevant_methods_for(constant)
methods = methods_for(constant).select(&:source_location)
.reject { |x| method_defined_by_forwardable_module?(x) }

return methods unless methods.empty?

constants_of(constant).flat_map do |const_name|
paracycle marked this conversation as resolved.
Show resolved Hide resolved
if (mod = child_module_for_parent_with_name(constant, const_name.to_s))
relevant_methods_for(mod)
else
[]
end
end
end

sig { params(constant: Module).returns(T::Array[UnboundMethod]) }
def methods_for(constant)
modules = [constant, singleton_class_of(constant)]
method_list_methods = [
PUBLIC_INSTANCE_METHODS_METHOD,
PROTECTED_INSTANCE_METHODS_METHOD,
PRIVATE_INSTANCE_METHODS_METHOD,
]

modules.product(method_list_methods).flat_map do |mod, method_list_method|
method_list_method.bind_call(mod, false).map { |name| mod.instance_method(name) }
end
end

sig { params(parent: Module, name: String).returns(T.nilable(Module)) }
def child_module_for_parent_with_name(parent, name)
return if parent.autoload?(name)

child = constantize(name, inherit: true, namespace: parent)
return unless Module === child
return unless name_of(child) == "#{name_of(parent)}::#{name}"

child
end

sig { params(method: UnboundMethod).returns(T::Boolean) }
def method_defined_by_forwardable_module?(method)
method.source_location&.first == Object.const_source_location(:Forwardable)&.first
end
end
end
end
1 change: 0 additions & 1 deletion tapioca.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
spec.add_dependency("bundler", ">= 1.17.3")
spec.add_dependency("netrc", ">= 0.11.0")
spec.add_dependency("parallel", ">= 1.21.0")
spec.add_dependency("pry", ">= 0.12.2")
spec.add_dependency("rbi", "~> 0.0.0", ">= 0.0.16")
spec.add_dependency("sorbet-static-and-runtime", ">= 0.5.9204")
spec.add_dependency("spoom", "~> 1.1.0", ">= 1.1.11")
Expand Down