Skip to content

Commit

Permalink
Revert "Temporarily remove all sigs"
Browse files Browse the repository at this point in the history
This reverts commit 20df458.
  • Loading branch information
camertron committed Nov 18, 2024
1 parent 20df458 commit 73c2493
Show file tree
Hide file tree
Showing 39 changed files with 678 additions and 678 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 3.3.3
ruby 2.7.4
68 changes: 34 additions & 34 deletions lib/kuby/basic_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@

module Kuby
class BasicLogger < Logger
# extend T::Sig
extend T::Sig

# T::Sig::WithoutRuntime.sig {
# override.params(
# logdev: T.any(String, IO, StringIO, NilClass),
# shift_age: Integer,
# shift_size: Integer,
# level: Integer,
# progname: T.nilable(String),
# formatter: T.nilable(FormatterProcType),
# datetime_format: T.nilable(String),
# shift_period_suffix: T.nilable(String)
# ).void
# }
T::Sig::WithoutRuntime.sig {
override.params(
logdev: T.any(String, IO, StringIO, NilClass),
shift_age: Integer,
shift_size: Integer,
level: Integer,
progname: T.nilable(String),
formatter: T.nilable(FormatterProcType),
datetime_format: T.nilable(String),
shift_period_suffix: T.nilable(String)
).void
}
def initialize(
logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
progname: nil, formatter: nil, datetime_format: nil,
shift_period_suffix: '%Y%m%d')
# @logdev = T.let(@logdev, T.nilable(Logger::LogDevice))
@logdev = T.let(@logdev, T.nilable(Logger::LogDevice))

super

Expand All @@ -32,12 +32,12 @@ def initialize(
end
end

# T::Sig::WithoutRuntime.sig {
# override.params(
# progname_or_msg: T.untyped,
# block: T.nilable(T.proc.returns(T.untyped))
# ).void
# }
T::Sig::WithoutRuntime.sig {
override.params(
progname_or_msg: T.untyped,
block: T.nilable(T.proc.returns(T.untyped))
).void
}
def info(progname_or_msg = nil, &block)
if block
super(progname_or_msg) { ColorizedString[block.call].yellow }
Expand All @@ -46,12 +46,12 @@ def info(progname_or_msg = nil, &block)
end
end

# T::Sig::WithoutRuntime.sig {
# override.params(
# progname_or_msg: T.untyped,
# block: T.nilable(T.proc.returns(T.untyped))
# ).void
# }
T::Sig::WithoutRuntime.sig {
override.params(
progname_or_msg: T.untyped,
block: T.nilable(T.proc.returns(T.untyped))
).void
}
def fatal(progname_or_msg = nil, &block)
if block
super(progname_or_msg) { ColorizedString[block.call].red }
Expand All @@ -61,13 +61,13 @@ def fatal(progname_or_msg = nil, &block)
end

# adhere to the "CLI" interface
# T::Sig::WithoutRuntime.sig {
# params(
# out: T.any(IO, StringIO),
# err: T.any(IO, StringIO),
# block: T.proc.void
# ).void
# }
T::Sig::WithoutRuntime.sig {
params(
out: T.any(IO, StringIO),
err: T.any(IO, StringIO),
block: T.proc.void
).void
}
def with_pipes(out = STDOUT, err = STDERR, &block)
previous_logdev = @logdev&.dev || STDERR
reopen(err)
Expand All @@ -76,7 +76,7 @@ def with_pipes(out = STDOUT, err = STDERR, &block)
reopen(previous_logdev)
end

# T::Sig::WithoutRuntime.sig { returns(T.nilable(Process::Status)) }
T::Sig::WithoutRuntime.sig { returns(T.nilable(Process::Status)) }
def last_status
nil
end
Expand Down
86 changes: 43 additions & 43 deletions lib/kuby/cli_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@

module Kuby
class CLIBase
# extend T::Sig
extend T::Sig

# BeforeCallback = T.type_alias { T.proc.params(cmd: T::Array[String]).void }
# AfterCallback = T.type_alias do
# T.proc.params(cmd: T::Array[String], last_status: T.nilable(Process::Status)).void
# end
BeforeCallback = T.type_alias { T.proc.params(cmd: T::Array[String]).void }
AfterCallback = T.type_alias do
T.proc.params(cmd: T::Array[String], last_status: T.nilable(Process::Status)).void
end

# T::Sig::WithoutRuntime.sig { returns(T.nilable(Process::Status)) }
T::Sig::WithoutRuntime.sig { returns(T.nilable(Process::Status)) }
def last_status
Thread.current[status_key]
end

# T::Sig::WithoutRuntime.sig { params(block: BeforeCallback).void }
T::Sig::WithoutRuntime.sig { params(block: BeforeCallback).void }
def before_execute(&block)
# @before_execute = T.let(@before_execute, T.nilable(T::Array[BeforeCallback]))
@before_execute = T.let(@before_execute, T.nilable(T::Array[BeforeCallback]))
@before_execute ||= []
@before_execute << block
end

# T::Sig::WithoutRuntime.sig { params(block: AfterCallback).void }
T::Sig::WithoutRuntime.sig { params(block: AfterCallback).void }
def after_execute(&block)
# @after_execute = T.let(@after_execute, T.nilable(T::Array[AfterCallback]))
@after_execute = T.let(@after_execute, T.nilable(T::Array[AfterCallback]))
@after_execute ||= []
@after_execute << block
end

# T::Sig::WithoutRuntime.sig {
# params(
# out: T.any(IO, StringIO),
# err: T.any(IO, StringIO),
# block: T.proc.void
# ).void
# }
T::Sig::WithoutRuntime.sig {
params(
out: T.any(IO, StringIO),
err: T.any(IO, StringIO),
block: T.proc.void
).void
}
def with_pipes(out = STDOUT, err = STDERR, &block)
previous_stdout = self.stdout
previous_stderr = self.stderr
Expand All @@ -49,34 +49,34 @@ def with_pipes(out = STDOUT, err = STDERR, &block)
self.stderr = previous_stderr
end

# T::Sig::WithoutRuntime.sig { returns(T.nilable(T.any(IO, StringIO))) }
T::Sig::WithoutRuntime.sig { returns(T.nilable(T.any(IO, StringIO))) }
def stdout
Thread.current[stdout_key] || STDOUT
end

# T::Sig::WithoutRuntime.sig { params(new_stdout: T.nilable(T.any(IO, StringIO))).void }
T::Sig::WithoutRuntime.sig { params(new_stdout: T.nilable(T.any(IO, StringIO))).void }
def stdout=(new_stdout)
Thread.current[stdout_key] = new_stdout
end

# T::Sig::WithoutRuntime.sig { returns(T.nilable(T.any(IO, StringIO))) }
T::Sig::WithoutRuntime.sig { returns(T.nilable(T.any(IO, StringIO))) }
def stderr
Thread.current[stderr_key] || STDERR
end

# T::Sig::WithoutRuntime.sig { params(new_stderr: T.nilable(T.any(IO, StringIO))).void }
T::Sig::WithoutRuntime.sig { params(new_stderr: T.nilable(T.any(IO, StringIO))).void }
def stderr=(new_stderr)
Thread.current[stderr_key] = new_stderr
end

private

# T::Sig::WithoutRuntime.sig {
# params(
# cmd: T::Array[String],
# block: T.proc.params(stdin: IO).void
# ).void
# }
T::Sig::WithoutRuntime.sig {
params(
cmd: T::Array[String],
block: T.proc.params(stdin: IO).void
).void
}
def open3_w(cmd, &block)
run_before_callbacks(cmd)
cmd_s = cmd.join(' ')
Expand All @@ -99,20 +99,20 @@ def open3_w(cmd, &block)
yield(p_stdin)

p_stdin.close
self.last_status = wait_thread.value
self.last_status = T.cast(wait_thread.value, Process::Status)
run_after_callbacks(cmd)
wait_thread.join
end
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
def execc(cmd)
run_before_callbacks(cmd)
cmd_s = cmd.join(' ')
exec(cmd_s)
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
def systemm(cmd)
if stdout == STDOUT && stderr == STDERR
systemm_default(cmd)
Expand All @@ -121,7 +121,7 @@ def systemm(cmd)
end
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
def systemm_default(cmd)
run_before_callbacks(cmd)
cmd_s = cmd.join(' ')
Expand All @@ -131,7 +131,7 @@ def systemm_default(cmd)
end
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
def systemm_open3(cmd)
run_before_callbacks(cmd)
cmd_s = cmd.join(' ')
Expand All @@ -152,14 +152,14 @@ def systemm_open3(cmd)
end

p_stdin.close
self.last_status = wait_thread.value
self.last_status = T.cast(wait_thread.value, Process::Status)
run_after_callbacks(cmd)
wait_thread.join
end
end


# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).returns(String) }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).returns(String) }
def backticks(cmd)
if stdout == STDOUT && stderr == STDERR
backticks_default(cmd)
Expand All @@ -168,7 +168,7 @@ def backticks(cmd)
end
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).returns(String) }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).returns(String) }
def backticks_default(cmd)
run_before_callbacks(cmd)
cmd_s = cmd.join(' ')
Expand All @@ -178,7 +178,7 @@ def backticks_default(cmd)
end
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).returns(String) }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).returns(String) }
def backticks_open3(cmd)
run_before_callbacks(cmd)
cmd_s = cmd.join(' ')
Expand All @@ -200,40 +200,40 @@ def backticks_open3(cmd)
end

p_stdin.close
self.last_status = wait_thread.value
self.last_status = T.cast(wait_thread.value, Process::Status)
run_after_callbacks(cmd)
wait_thread.join
end

result.string
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
def run_before_callbacks(cmd)
(@before_execute || []).each { |cb| cb.call(cmd) }
end

# T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
T::Sig::WithoutRuntime.sig { params(cmd: T::Array[String]).void }
def run_after_callbacks(cmd)
(@after_execute || []).each { |cb| cb.call(cmd, last_status) }
end

# T::Sig::WithoutRuntime.sig { params(status: Process::Status).void }
T::Sig::WithoutRuntime.sig { params(status: Process::Status).void }
def last_status=(status)
Thread.current[status_key] = status
end

# T::Sig::WithoutRuntime.sig { returns(Symbol) }
T::Sig::WithoutRuntime.sig { returns(Symbol) }
def status_key
raise NotImplementedError, "#{__method__} must be defined in derived classes"
end

# T::Sig::WithoutRuntime.sig { returns(Symbol) }
T::Sig::WithoutRuntime.sig { returns(Symbol) }
def stdout_key
raise NotImplementedError, "#{__method__} must be defined in derived classes"
end

# T::Sig::WithoutRuntime.sig { returns(Symbol) }
T::Sig::WithoutRuntime.sig { returns(Symbol) }
def stderr_key
raise NotImplementedError, "#{__method__} must be defined in derived classes"
end
Expand Down
22 changes: 11 additions & 11 deletions lib/kuby/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

module Kuby
class Commands
# extend T::Sig
extend T::Sig
extend GLI::App

# GLI doesn't have a wildcard option, so it's impossible to tell it to
Expand All @@ -22,12 +22,12 @@ class Commands
# avoid the usual series of cryptic alias_method calls (note that there
# is no singleton class version of #prepend in the Ruby language).
singleton_class.send(:prepend, Module.new do
# extend T::Sig
extend T::Sig

# T::Sig::WithoutRuntime.sig { params(args: T::Array[String]).void }
T::Sig::WithoutRuntime.sig { params(args: T::Array[String]).void }
def run(args)
if idx = args.index('rails') || idx = args.index('rake')
# @rails_options = T.let(@rails_options, T.nilable(T::Array[String]))
@rails_options = T.let(@rails_options, T.nilable(T::Array[String]))
@rails_options = args[(idx + 1)..-1]
super(args[0..idx])
else
Expand All @@ -37,16 +37,16 @@ def run(args)
end
end)

# T::Sig::WithoutRuntime.sig { returns(Kuby::Tasks) }
T::Sig::WithoutRuntime.sig { returns(Kuby::Tasks) }
def self.tasks
Kuby::Tasks.new(Kuby.environment)
end

# T::Sig::WithoutRuntime.sig {
# params(
# global_options: T::Hash[T.any(String, Symbol), T.any(String, Integer)]
# ).void
# }
T::Sig::WithoutRuntime.sig {
params(
global_options: T::Hash[T.any(String, Symbol), T.any(String, Integer)]
).void
}
def self.load_kuby_config!(global_options)
return if @kuby_config_loaded

Expand Down Expand Up @@ -289,7 +289,7 @@ def self.load_kuby_config!(global_options)
rc.desc 'Runs an arbitrary command inside a running Rails pod.'
rc.command :exec do |c|
c.action do |global_options, options, args|
tasks.remote_exec([*args, *@rails_options])
tasks.remote_exec([*args, *T.unsafe(@rails_options)])
end
end

Expand Down
Loading

0 comments on commit 73c2493

Please sign in to comment.