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

Centralize Ruby Version to .ruby-version #221

Merged
merged 6 commits into from
Apr 10, 2024
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
2 changes: 0 additions & 2 deletions .github/workflows/liquid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jobs:
strategy:
matrix:
include:
- { ruby: '2.7', allowed-failure: false }
- { ruby: '3.0', allowed-failure: false }
- { ruby: '3.1', allowed-failure: false }
- { ruby: '3.2', allowed-failure: false }
Expand Down Expand Up @@ -44,7 +43,6 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
bundler-cache: true
- run: sudo apt-get install -y valgrind
- run: bundle exec rake test:valgrind
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.gem
*.rbc
Gemfile.lock
pkg
tmp
*.o
Expand Down
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ inherit_gem:
require: rubocop-performance

AllCops:
TargetRubyVersion: 2.5
Exclude:
- 'vendor/bundle/**/*'
- 'tmp/**/*'
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.0
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ gem "liquid", github: "Shopify/liquid", ref: "master"

group :test do
gem "base64", require: false # for older rubocop on Ruby 3.4
gem "rubocop", "~> 1.24.1", require: false
gem "rubocop", "~> 1.61.0", require: false
gem "rubocop-performance", "~> 1.13.2", require: false
gem "rubocop-shopify", "~> 2.4.0", require: false
gem "rubocop-shopify", "~> 2.15.1", require: false
gem "spy", "0.4.1"
gem "benchmark-ips"
gem "ruby_memcheck"
Expand Down
85 changes: 85 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
GIT
remote: https://github.com/Shopify/liquid.git
revision: 0b9318222bcc09681e52fd5b8e70262274e673bf
ref: master
specs:
liquid (5.4.0)

PATH
remote: .
specs:
liquid-c (4.2.0)
liquid (>= 5.0.1)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
base64 (0.2.0)
benchmark-ips (2.13.0)
byebug (11.1.3)
json (2.7.2)
language_server-protocol (3.17.0.3)
mini_portile2 (2.8.5)
minitest (5.22.3)
nokogiri (1.16.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.2.1)
rake-compiler (1.2.7)
rake
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-performance (1.13.3)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-shopify (2.15.1)
rubocop (~> 1.51)
ruby-progressbar (1.13.0)
ruby_memcheck (2.3.0)
nokogiri
spy (0.4.1)
stackprof (0.2.26)
unicode-display_width (2.5.0)

PLATFORMS
ruby

DEPENDENCIES
base64
benchmark-ips
bundler (>= 1.5)
byebug
liquid!
liquid-c!
minitest
rake
rake-compiler
rubocop (~> 1.61.0)
rubocop-performance (~> 1.13.2)
rubocop-shopify (~> 2.15.1)
ruby_memcheck
spy (= 0.4.1)
stackprof

BUNDLED WITH
2.4.22
2 changes: 1 addition & 1 deletion ext/liquid_c/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@

have_func "rb_hash_bulk_insert"

$warnflags&.gsub!(/-Wdeclaration-after-statement/, "")
$warnflags&.gsub!("-Wdeclaration-after-statement", "")
create_makefile("liquid_c")
41 changes: 23 additions & 18 deletions lib/liquid/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ def render(context)

module Liquid
BlockBody.class_eval do
def self.c_rescue_render_node(context, output, line_number, exc, blank_tag)
# There seems to be a MRI ruby bug with how the rb_rescue C function,
# where $! gets set for its rescue callback, but it doesn't stay set
# after a nested exception is raised and handled as is the case in
# Liquid::Context#internal_error. This isn't a problem for plain ruby code,
# so use a ruby rescue block to have setup $! properly.
raise(exc)
rescue => exc
rescue_render_node(context, output, line_number, exc, blank_tag)
class << self
def c_rescue_render_node(context, output, line_number, exc, blank_tag)
# There seems to be a MRI ruby bug with how the rb_rescue C function,
# where $! gets set for its rescue callback, but it doesn't stay set
# after a nested exception is raised and handled as is the case in
# Liquid::Context#internal_error. This isn't a problem for plain ruby code,
# so use a ruby rescue block to have setup $! properly.
raise(exc)
rescue => exc
rescue_render_node(context, output, line_number, exc, blank_tag)
end
end
end
end
Expand Down Expand Up @@ -100,6 +102,7 @@ def liquid_c_nodes_disabled?
# provide the `disable_liquid_c_nodes` option to enable the Ruby AST to be produced
# so the profiler can use it on future runs.
return @liquid_c_nodes_disabled if defined?(@liquid_c_nodes_disabled)

@liquid_c_nodes_disabled = !Liquid::C.enabled || @template_options[:profile] ||
@template_options[:disable_liquid_c_nodes] || self.class.liquid_c_nodes_disabled
end
Expand Down Expand Up @@ -234,15 +237,17 @@ def c_parse_evaluate(expression)
end

Liquid::ResourceLimits.class_eval do
def self.new(limits)
if Liquid::C.enabled
Liquid::C::ResourceLimits.new(
limits[:render_length_limit],
limits[:render_score_limit],
limits[:assign_score_limit]
)
else
super
class << self
def new(limits)
if Liquid::C.enabled
Liquid::C::ResourceLimits.new(
limits[:render_length_limit],
limits[:render_score_limit],
limits[:assign_score_limit],
)
else
super
end
end
end
end
Expand Down
7 changes: 2 additions & 5 deletions liquid-c.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# coding: utf-8
# frozen_string_literal: true

# rubocop:disable Gemspec/RubyVersionGlobalsUsage

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "liquid/c/version"
Expand All @@ -19,10 +17,9 @@ Gem::Specification.new do |spec|
spec.extensions = ["ext/liquid_c/extconf.rb"]
spec.files = %x(git ls-files -z).split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.5.0"
spec.required_ruby_version = ">= 3.0.0"

spec.metadata["allowed_push_host"] = "https://rubygems.org"

Expand All @@ -32,5 +29,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency("minitest")
spec.add_development_dependency("rake")
spec.add_development_dependency("rake-compiler")
spec.add_development_dependency("stackprof") if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0")
spec.add_development_dependency("stackprof") if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0") # rubocop:disable Gemspec/RubyVersionGlobalsUsage
end
1 change: 1 addition & 0 deletions performance/c_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
unless TASK_NAMES.include?(task_name)
raise "Unsupported task '#{task_name}' (must be one of #{TASK_NAMES})"
end

task = ThemeRunner.new.method(task_name)

runner_id = fork do
Expand Down
5 changes: 3 additions & 2 deletions test/unit/block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def test_disassemble
0x0000: write_raw("raw")
0x0005: render_variable_rescue(line_number: 2)
0x0009: find_static_var("var")
0x000c: push_const(\"none\")
0x000f: push_const(\"allow_false\")
0x000c: push_const("none")
0x000f: push_const("allow_false")
0x0012: push_true
0x0013: hash_new(1)
0x0015: builtin_filter(name: :default, num_args: 3)
Expand All @@ -97,6 +97,7 @@ def test_exception_renderer_exception
if exc == original_error
raise(handler_error)
end

exc
end
template = Liquid::Template.parse("{% assign x = raise_error %}")
Expand Down
6 changes: 3 additions & 3 deletions test/unit/raw_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_derived_class
assert_equal(
"<body>",
output,
"Template: #{template}"
"Template: #{template}",
)
end
end
Expand Down Expand Up @@ -76,10 +76,10 @@ def test_does_not_allow_nbsp_in_tag_delimiter
].each do |bad_delimiter|
exception = assert_raises(
Liquid::SyntaxError,
"#{bad_delimiter.inspect} did not raise Liquid::SyntaxError"
"#{bad_delimiter.inspect} did not raise Liquid::SyntaxError",
) do
Liquid::Template.parse(
"{% raw %}body#{bad_delimiter}"
"{% raw %}body#{bad_delimiter}",
)
end

Expand Down
8 changes: 4 additions & 4 deletions test/unit/variable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_write_object_with_broken_to_s
end
assert_equal(
"VariableTest::StringConvertible#to_s returned a non-String convertible value of type Integer",
exc.message
exc.message,
)
end

Expand Down Expand Up @@ -264,7 +264,7 @@ def test_encoding_error_message_with_multi_byte_characters
end
assert_equal(
"Liquid syntax error: Unexpected character \u00A0 in \"{{\u00a0}}\"",
exc.message
exc.message,
)

# 3 byte character
Expand All @@ -273,7 +273,7 @@ def test_encoding_error_message_with_multi_byte_characters
end
assert_equal(
"Liquid syntax error: Unexpected character \u3042 in \"{{\u3042}}\"",
exc.message
exc.message,
)

# 4 byte character
Expand All @@ -282,7 +282,7 @@ def test_encoding_error_message_with_multi_byte_characters
end
assert_equal(
"Liquid syntax error: Unexpected character \u{1F600} in \"{{\u{1F600}}}\"",
exc.message
exc.message,
)
end

Expand Down
Loading