Skip to content

Commit 3d51f78

Browse files
fix(internal): ensure formatting always uses c.utf-8 locale
1 parent 9a2827b commit 3d51f78

File tree

1,128 files changed

+33173
-21914
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,128 files changed

+33173
-21914
lines changed

.rubocop.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Layout/MultilineMethodParameterLineBreaks:
6363
# Prefer compact hash literals.
6464
Layout/SpaceInsideHashLiteralBraces:
6565
EnforcedStyle: no_space
66+
Exclude:
67+
- "**/*.rbi"
6668

6769
Lint/BooleanSymbol:
6870
Enabled: false
@@ -90,6 +92,10 @@ Lint/MissingSuper:
9092
Exclude:
9193
- "**/*.rbi"
9294

95+
Lint/SymbolConversion:
96+
Exclude:
97+
- "**/*.rbi"
98+
9399
# Disabled for safety reasons, this option changes code semantics.
94100
Lint/UnusedMethodArgument:
95101
AutoCorrect: false
@@ -244,6 +250,10 @@ Style/RedundantInitialize:
244250
Exclude:
245251
- "**/*.rbi"
246252

253+
Style/RedundantParentheses:
254+
Exclude:
255+
- "**/*.rbi"
256+
247257
# Prefer slashes for regex literals.
248258
Style/RegexpLiteral:
249259
EnforcedStyle: slashes

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ When using sorbet, it is recommended to use model classes as below. This provide
4848

4949
```ruby
5050
openai.chat.completions.create(
51-
messages: [OpenAI::Models::Chat::ChatCompletionUserMessageParam.new(role: "user", content: "Say this is a test")],
51+
messages: [OpenAI::Chat::ChatCompletionUserMessageParam.new(role: "user", content: "Say this is a test")],
5252
model: :"gpt-4.1"
5353
)
5454
```
@@ -189,7 +189,7 @@ In all places where a `BaseModel` type is specified, vanilla Ruby `Hash` can als
189189
```ruby
190190
# This has tooling readability, for auto-completion, static analysis, and goto definition with supported language services
191191
params = OpenAI::Models::Chat::CompletionCreateParams.new(
192-
messages: [OpenAI::Models::Chat::ChatCompletionUserMessageParam.new(role: "user", content: "Say this is a test")],
192+
messages: [OpenAI::Chat::ChatCompletionUserMessageParam.new(role: "user", content: "Say this is a test")],
193193
model: :"gpt-4.1"
194194
)
195195

@@ -245,9 +245,9 @@ Sorbet's typed enums require sub-classing of the [`T::Enum` class](https://sorbe
245245
Since this library does not depend on `sorbet-runtime`, it uses a [`T.all` intersection type](https://sorbet.org/docs/intersection-types) with a ruby primitive type to construct a "tagged alias" instead.
246246

247247
```ruby
248-
module OpenAI::Models::ChatModel
248+
module OpenAI::ChatModel
249249
# This alias aids language service driven navigation.
250-
TaggedSymbol = T.type_alias { T.all(Symbol, OpenAI::Models::ChatModel) }
250+
TaggedSymbol = T.type_alias { T.all(Symbol, OpenAI::ChatModel) }
251251
end
252252
```
253253

@@ -257,7 +257,7 @@ It is possible to pass a compatible model / parameter class to a method that exp
257257

258258
```ruby
259259
params = OpenAI::Models::Chat::CompletionCreateParams.new(
260-
messages: [OpenAI::Models::Chat::ChatCompletionUserMessageParam.new(role: "user", content: "Say this is a test")],
260+
messages: [OpenAI::Chat::ChatCompletionUserMessageParam.new(role: "user", content: "Say this is a test")],
261261
model: :"gpt-4.1"
262262
)
263263
openai.chat.completions.create(**params)

Rakefile

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,40 @@ multitask(:test) do
3434
ruby(*%w[-w -e], rb, verbose: false) { fail unless _1 }
3535
end
3636

37-
rubo_find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]
3837
xargs = %w[xargs --no-run-if-empty --null --max-procs=0 --max-args=300 --]
38+
locale = {"LC_ALL" => "C.UTF-8"}
3939

4040
desc("Lint `*.rb(i)`")
4141
multitask(:"lint:rubocop") do
42+
find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]
43+
4244
rubocop = %w[rubocop --fail-level E]
4345
rubocop += %w[--format github] if ENV.key?("CI")
4446

4547
# some lines cannot be shortened
4648
rubocop += %w[--except Lint/RedundantCopDisableDirective,Layout/LineLength]
4749

4850
lint = xargs + rubocop
49-
sh("#{rubo_find.shelljoin} | #{lint.shelljoin}")
51+
sh("#{find.shelljoin} | #{lint.shelljoin}")
5052
end
5153

52-
desc("Format `*.rb(i)`")
53-
multitask(:"format:rubocop") do
54+
desc("Format `*.rb`")
55+
multitask(:"format:rb") do
56+
# while `syntax_tree` is much faster than `rubocop`, `rubocop` is the only formatter with full syntax support
57+
find = %w[find ./lib ./test -type f -and -name *.rb -print0]
5458
fmt = xargs + %w[rubocop --fail-level F --autocorrect --format simple --]
55-
sh("#{rubo_find.shelljoin} | #{fmt.shelljoin}")
59+
sh("#{find.shelljoin} | #{fmt.shelljoin}")
60+
end
61+
62+
desc("Format `*.rbi`")
63+
multitask(:"format:rbi") do
64+
find = %w[find ./rbi -type f -and -name *.rbi -print0]
65+
fmt = xargs + %w[stree write --]
66+
sh(locale, "#{find.shelljoin} | #{fmt.shelljoin}")
5667
end
5768

5869
desc("Format `*.rbs`")
59-
multitask(:"format:syntax_tree") do
70+
multitask(:"format:rbs") do
6071
find = %w[find ./sig -type f -name *.rbs -print0]
6172
inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? ["-i", ""] : %w[-i]
6273
uuid = SecureRandom.uuid
@@ -88,7 +99,7 @@ multitask(:"format:syntax_tree") do
8899
# transform class aliases to type aliases, which syntax tree has no trouble with
89100
sh("#{find.shelljoin} | #{pre.shelljoin}")
90101
# run syntax tree to format `*.rbs` files
91-
sh("#{find.shelljoin} | #{fmt.shelljoin}") do
102+
sh(locale, "#{find.shelljoin} | #{fmt.shelljoin}") do
92103
success = _1
93104
end
94105
# transform type aliases back to class aliases
@@ -99,7 +110,7 @@ multitask(:"format:syntax_tree") do
99110
end
100111

101112
desc("Format everything")
102-
multitask(format: [:"format:rubocop", :"format:syntax_tree"])
113+
multitask(format: [:"format:rb", :"format:rbi", :"format:rbs"])
103114

104115
desc("Typecheck `*.rbs`")
105116
multitask(:"typecheck:steep") do

lib/openai.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@
428428
require_relative "openai/models/vector_store_search_params"
429429
require_relative "openai/models/vector_store_search_response"
430430
require_relative "openai/models/vector_store_update_params"
431+
require_relative "openai/models"
431432
require_relative "openai/resources/audio"
432433
require_relative "openai/resources/audio/speech"
433434
require_relative "openai/resources/audio/transcriptions"

lib/openai/file_part.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def initialize(content, filename: nil, content_type: nil)
4545
@filename =
4646
case content
4747
in Pathname
48-
filename.nil? ? content.basename.to_path : File.basename(filename)
48+
filename.nil? ? content.basename.to_path : ::File.basename(filename)
4949
else
50-
filename.nil? ? nil : File.basename(filename)
50+
filename.nil? ? nil : ::File.basename(filename)
5151
end
5252
@content_type = content_type
5353
end

lib/openai/internal/type/enum.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ module Type
1717
# values safely.
1818
#
1919
# @example
20-
# # `chat_model` is a `OpenAI::Models::ChatModel`
20+
# # `chat_model` is a `OpenAI::ChatModel`
2121
# case chat_model
22-
# when OpenAI::Models::ChatModel::GPT_4_1
22+
# when OpenAI::ChatModel::GPT_4_1
2323
# # ...
24-
# when OpenAI::Models::ChatModel::GPT_4_1_MINI
24+
# when OpenAI::ChatModel::GPT_4_1_MINI
2525
# # ...
26-
# when OpenAI::Models::ChatModel::GPT_4_1_NANO
26+
# when OpenAI::ChatModel::GPT_4_1_NANO
2727
# # ...
2828
# else
2929
# puts(chat_model)

lib/openai/internal/type/request_parameters.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ module Internal
55
module Type
66
# @api private
77
module RequestParameters
8-
# @!parse
9-
# # Options to specify HTTP behaviour for this request.
10-
# # @return [OpenAI::RequestOptions, Hash{Symbol=>Object}]
11-
# attr_accessor :request_options
8+
# @!attribute request_options
9+
# Options to specify HTTP behaviour for this request.
10+
#
11+
# @return [OpenAI::RequestOptions, Hash{Symbol=>Object}]
1212

1313
# @param mod [Module]
1414
def self.included(mod)

lib/openai/internal/type/union.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ module Type
66
# @api private
77
#
88
# @example
9-
# # `chat_completion_content_part` is a `OpenAI::Models::Chat::ChatCompletionContentPart`
9+
# # `chat_completion_content_part` is a `OpenAI::Chat::ChatCompletionContentPart`
1010
# case chat_completion_content_part
11-
# when OpenAI::Models::Chat::ChatCompletionContentPartText
11+
# when OpenAI::Chat::ChatCompletionContentPartText
1212
# puts(chat_completion_content_part.text)
13-
# when OpenAI::Models::Chat::ChatCompletionContentPartImage
13+
# when OpenAI::Chat::ChatCompletionContentPartImage
1414
# puts(chat_completion_content_part.image_url)
15-
# when OpenAI::Models::Chat::ChatCompletionContentPartInputAudio
15+
# when OpenAI::Chat::ChatCompletionContentPartInputAudio
1616
# puts(chat_completion_content_part.input_audio)
1717
# else
1818
# puts(chat_completion_content_part)

lib/openai/internal/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class << self
535535
filename = ERB::Util.url_encode(val.filename)
536536
y << "; filename=\"#{filename}\""
537537
in Pathname | IO
538-
filename = ERB::Util.url_encode(File.basename(val.to_path))
538+
filename = ERB::Util.url_encode(::File.basename(val.to_path))
539539
y << "; filename=\"#{filename}\""
540540
else
541541
end

lib/openai/models/all_models.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ module AllModels
77

88
variant String
99

10-
variant enum: -> { OpenAI::Models::ChatModel }
10+
variant enum: -> { OpenAI::ChatModel }
1111

12-
variant enum: -> { OpenAI::Models::AllModels::ResponsesOnlyModel }
12+
variant enum: -> { OpenAI::AllModels::ResponsesOnlyModel }
1313

1414
module ResponsesOnlyModel
1515
extend OpenAI::Internal::Type::Enum
@@ -24,7 +24,7 @@ module ResponsesOnlyModel
2424
end
2525

2626
# @!method self.variants
27-
# @return [Array(String, Symbol, OpenAI::Models::ChatModel, Symbol, OpenAI::Models::AllModels::ResponsesOnlyModel)]
27+
# @return [Array(String, Symbol, OpenAI::ChatModel, Symbol, OpenAI::AllModels::ResponsesOnlyModel)]
2828
end
2929
end
3030
end

0 commit comments

Comments
 (0)