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

Add zeitwerk loader and teach it about this gem #551

Merged
merged 5 commits into from
Aug 23, 2023

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Dec 10, 2022

Depends on:

  • specify load path directories
  • inform of organizational directories that aren't namespaces
  • specific files that must be required and not autoloaded
  • custom inflectors where we deviate from convention
  • remove requires for autoload-able files (caution must be taken when we need to monkey patch as we need to require or we may never get our monkey patch loaded)
  • use require_relative for ones that must be manually required

TODO:

loader.setup

# TODO: consider turning on eager_load and only disable really slow/fat requires
# loader.eager_load
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I enabled locally to get everything to fail so I could then fix or ignore.

@miq-bot miq-bot added the wip label Dec 10, 2022
s.add_runtime_dependency "winrm", "~> 2.1"
s.add_runtime_dependency "winrm-elevated", "~> 1.0.1"
s.add_runtime_dependency "zeitwerk"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to lock this down to a minor version

jrafanie added a commit to jrafanie/manageiq-smartstate that referenced this pull request Mar 16, 2023
See: ManageIQ/manageiq#22279

I noticed this while looking to add zeitwerk in gems pending, see:
ManageIQ/manageiq-gems-pending#551

I used the following to find these:
git grep -iE "win_rm|winrm|scvmm|hyperv"
jrafanie added a commit to jrafanie/manageiq-gems-pending that referenced this pull request Mar 16, 2023
@jrafanie jrafanie force-pushed the zeitwerk branch 2 times, most recently from c06c761 to 0aebbc0 Compare March 22, 2023 20:26
@@ -41,7 +41,7 @@ def self.xml_document(xmlClass)
when :xmlhash
Copy link
Member

@kbrock kbrock Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tangent: do we have enough coverage to know if we can drop :xmlhash or :rexml?

aah, default is :rexml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed we only used this in a few rare places, but besides smart state (and specs), looks like we use it in kubernetes, vmware, ui classic (only in 1-2 files each) along with a dozen core models.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question... I haven't looked recently but in the past we had no coverage of this area so it's hard to know if you can just drop it.

@kbrock
Copy link
Member

kbrock commented Mar 23, 2023

We used to require util/ for all of these. Happy that you are getting rid of these.

lib = File.expand_path("#{__dir__}../../../../")
loader.push_dir("#{lib}/gems/pending/util")

# This tells the loader to not expect Mount or ObjectStorage namspaces...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦅 👁️

Suggested change
# This tells the loader to not expect Mount or ObjectStorage namspaces...
# This tells the loader to not expect Mount or ObjectStorage namespaces...

# These files skip zeitwerk and must be required manually
##### TODO: check for requires outside of this gem to these files and util/ in requires
loader.ignore("#{lib}/gems/pending/util/miq-extensions.rb") # loader file, no class
loader.ignore("#{lib}/gems/pending/util/require_with_logging.rb") # file has no class ;-)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this out into a diagnostics thing or maybe move it into core.

* specify load path directories
* organizational directories that aren't namespaces
* specific files that must be required and not autoloaded
* custom inflectors where we deviate from convention
Unfortunately, miq_rexml is different because we need to monkey patch it early.
…them

Once we eager load, we can remove these.
Use for_gem_extension provided in zeitwerk 2.6.8
@miq-bot
Copy link
Member

miq-bot commented Aug 21, 2023

Checked commits jrafanie/manageiq-gems-pending@d23ca2f~...d560e92 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
45 files checked, 4 offenses detected

lib/gems/pending/util/miq_file_storage.rb

  • ⚠️ - Line 51, Col 7 - Lint/Void - Variable MiqGlusterfsSession used in void context.
  • ⚠️ - Line 52, Col 7 - Lint/Void - Variable MiqLocalMountSession used in void context.
  • ⚠️ - Line 53, Col 7 - Lint/Void - Variable MiqNfsSession used in void context.
  • ⚠️ - Line 54, Col 7 - Lint/Void - Variable MiqSmbSession used in void context.

@jrafanie jrafanie changed the title [WIP] Add zeitwerk loader and teach it about this gem Add zeitwerk loader and teach it about this gem Aug 21, 2023
@jrafanie
Copy link
Member Author

ok, this is green other than the already existing constants:
image

The cross repo is green other than ui service

@jrafanie
Copy link
Member Author

I think this is ready to go. Once in and backported to quinteros, we can decide about about the core PR. They can be independent upgrades.

@agrare agrare merged commit 943bd66 into ManageIQ:master Aug 23, 2023
3 checks passed
@jrafanie jrafanie deleted the zeitwerk branch August 23, 2023 18:09
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Aug 24, 2023
Fixes an issue hit with bin/update but not bundle update.

The hypenated manageiq-gems-pending gem name file was removed as bundler/rubygems
wants you to use manageiq/gems/pending file layout.

Due to ManageIQ/manageiq-gems-pending#551
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Aug 24, 2023
Fixes an issue hit with bin/update but not bundle update.

The hyphenated manageiq-gems-pending gem name file was removed as bundler/rubygems
wants you to use manageiq/gems/pending file layout.

Due to ManageIQ/manageiq-gems-pending#551
@Fryguy
Copy link
Member

Fryguy commented Oct 27, 2023

Skipping backport to quinteros, because it is already in the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants