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

Circular require #173

Open
rwstauner opened this issue Jan 24, 2025 · 0 comments · May be fixed by #183
Open

Circular require #173

rwstauner opened this issue Jan 24, 2025 · 0 comments · May be fixed by #183
Assignees

Comments

@rwstauner
Copy link
Contributor

I noticed an issue if that occurs under certain circumstances.
If you require "protoboeuf" it defines an autoload for CodeGen.
If you then require codegen directly it requires codegen_type_helper before establishing the CodeGen module
and the autoload is triggered for a file that is currently being loaded:

💥 ruby -Ilib -ve 'require "protoboeuf"; require "protoboeuf/codegen"'
ruby 3.3.4 (2024-07-09 revision be1089c8ec) [arm64-darwin24]
<internal:/Users/rwstauner/.rubies/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136: warning: <internal:/Users/rwstauner/.rubies/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136: warning: loading in progress, circular require considered harmful - /Users/rwstauner/src/github.com/Shopify/protoboeuf/lib/protoboeuf/codegen.rb
        from -e:1:in  `<main>'
        from <internal:/Users/rwstauner/.rubies/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in  `require'
        from <internal:/Users/rwstauner/.rubies/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in  `require'
        from /Users/rwstauner/src/github.com/Shopify/protoboeuf/lib/protoboeuf/codegen.rb:5:in  `<top (required)>'
        from /Users/rwstauner/src/github.com/Shopify/protoboeuf/lib/protoboeuf/codegen.rb:5:in  `require_relative'
        from /Users/rwstauner/src/github.com/Shopify/protoboeuf/lib/protoboeuf/codegen_type_helper.rb:3:in  `<top (required)>'
        from /Users/rwstauner/src/github.com/Shopify/protoboeuf/lib/protoboeuf/codegen_type_helper.rb:4:in  `<module:ProtoBoeuf>'
        from <internal:/Users/rwstauner/.rubies/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in  `require'
        from <internal:/Users/rwstauner/.rubies/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in  `require'

/Users/rwstauner/src/github.com/Shopify/protoboeuf/lib/protoboeuf/codegen_type_helper.rb:4: warning: Expected protoboeuf/codegen to define ProtoBoeuf::CodeGen but it didn't

One option is to move the require:

diff --git a/lib/protoboeuf/codegen.rb b/lib/protoboeuf/codegen.rb
index 9f6492e..7bb353e 100644
--- a/lib/protoboeuf/codegen.rb
+++ b/lib/protoboeuf/codegen.rb
@@ -2,13 +2,14 @@
 
 require "erb"
 require "syntax_tree"
-require_relative "codegen_type_helper"
 
 module ProtoBoeuf
   class CodeGen
     class EnumCompiler
       attr_reader :generate_types
 
+      require_relative "codegen_type_helper"
+
       include TypeHelper
 
       class << self

we could also change the namespace, etc.

@davebenvenuti davebenvenuti linked a pull request Jan 30, 2025 that will close this issue
@davebenvenuti davebenvenuti self-assigned this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants