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

Better inflector support for ui rake tasks and asset plugins #3986

Merged

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented May 24, 2018

This better supports the ActiveSupport::Inflectors that are set by both the main app and any asset engines that are pulled in by the webpack tasks.

The PR creates two new tasks in the :ui namespace:

  • rake ui:load_app_inflectors
  • rake ui:load_asset_engine_inflectors

The first loads the inflectors from the main application, and the second pulls in any inflectors from the asset_engines that are present. The asset_engine inflector task does assume the file lives in the config/initializers/inflections.rb, so that is sort of being set as the standard as part of this PR.

Also, minor addition: The asset_engines method is now memoized. Your welcome. #smugNickIsSmug

Links

Steps for Testing/QA

When the aforementioned rename of miq_v2v_ui_plugin has completed, we should test rake update:ui from both this repo and the main repo to confirm everything is working as expected

Spoiler! I have already done this from the main repo with these, and seems to work as expected. That said, others should do the same.

@NickLaMuro
Copy link
Member Author

@miq-bot assign @Fryguy

This should fix the issues you were having with the miq_v2v_ui_plugin rename. Let me know if this does the trick and the conventions that I am setting are all "gravy" with you.

cc @himdel (because I am sure you have some sort of opinion with this)

@himdel himdel mentioned this pull request May 24, 2018
27 tasks
@himdel
Copy link
Contributor

himdel commented May 24, 2018

Thanks @NickLaMuro, once (if?) merged, I'll add this to the "backport the necessary webpack/engine switching bits to gaprindashvili" PR :).

all_engines = Rails::Engine.subclasses.each_with_object({}) do |engine, acc|
acc[engine] = engine.root.realpath.to_s
end
@asset_engines ||= begin do
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like begin do is not a thing ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

@himdel heh, looks like #smugNickisSmug got cocky a little to early. Didn't test with that change... go figure it is the one that breaks (facepalm).

Will push a chance in a second.

@NickLaMuro NickLaMuro force-pushed the better_inflector_support_for_ui_tasks branch from 8b3d1ae to 897ccdb Compare May 24, 2018 14:49
Loads the lib/vmdb/inflections.rb file from the main app to inject the
inflectors into tasks that aren't loading the entire Rails environment.
Allows the inflectors to be evaluated without loading the entire Rails
environment, which causes issues when compiling assets in the appliance
build.

This gets ride of the gross hardcoding business of the ManageIQ
inflector that was done previously as a stopgap.
Adds a task to load inflectors from asset engines that define them.

This assumes the convention of `config/initializers/inflectors.rb` being
the path where the we set the inflectors in our plugins.
This is now getting called a few times when doing something `update:ui`,
so memoize it so we limit the number of filesystem checks we do.
@miq-bot
Copy link
Member

miq-bot commented May 25, 2018

Checked commits NickLaMuro/manageiq-ui-classic@40b76be~...ba77c31 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. ⭐

@Fryguy
Copy link
Member

Fryguy commented May 29, 2018

I am good with this for now, but I think it would be preferable if this lived in the core repo in some way. Perhaps Vmdb::Inflections and/or Vmdb::Plugins could own the knowledge? I know you are trying to avoid loading the environment, but from a pluggability standpoint, this is likely not the only repo that will bring their own assets and inflectors.

@Fryguy Fryguy merged commit f6128de into ManageIQ:master May 29, 2018
@Fryguy Fryguy added this to the Sprint 87 Ending Jun 4, 2018 milestone May 29, 2018
@himdel
Copy link
Contributor

himdel commented May 30, 2018

this is likely not the only repo that will bring their own assets and inflectors.

v2v is also bringing assets - they're using the asset pipeline for css
the same goes for manageiq-graphql I think.

(but Webpack 5 should have sane support for non-javascript packs, so maybe that will go away)

@himdel
Copy link
Contributor

himdel commented Jun 6, 2018

Not backported as part of #4071, but after that one gets in gaprindashvili, this one will backport cleanly.

So.. adding gaprindashvili/yes.

This will only be useful after ManageIQ/manageiq-v2v#344, right? Meaning not needed for today's build so not needing the transformation label quite yet?

@NickLaMuro
Copy link
Member Author

@himdel yeah, that sounds right to me.

@himdel
Copy link
Contributor

himdel commented Jun 25, 2018

@NickLaMuro not sure if anything changed but ... the rake task doesn't inflect as intended:

$ be rake webpack:paths
$ cat config/webpack/paths.json
..
    "manageiq-v2_v": "/home/himdel/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/bundler/gems/miq_v2v_ui_plugin-6ee8b26a6a40",
..

@NickLaMuro
Copy link
Member Author

😭

WHYYYYYYYYYYYYY!!!1!

Okay... I will try and take a look in a bit...

@himdel
Copy link
Contributor

himdel commented Jun 25, 2018

Thanks! :)

Just verified that

--- a/lib/tasks/manageiq/ui_tasks.rake
+++ b/lib/tasks/manageiq/ui_tasks.rake
@@ -162,6 +162,9 @@ def asset_engines
 end
 
 def asset_engines_plugins_hash
+  ActiveSupport::Inflector.inflections do |inflect|
+    inflect.acronym("V2V")
+  end
   asset_engines.each_with_object({}) do |(engine, path), plugin_hash|
     # remove '::Engine' from the constant name, underscore it, and replace
     # backslashes with dashes

works just fine, so it must be something in how we load the inflectors.

@himdel
Copy link
Contributor

himdel commented Jun 25, 2018

@NickLaMuro Ok, never mind...

This is not ":load_asset_engine_inflectors doesn't work".
This is .. running webpack:paths manually, it doesn't get loaded.

Sorry for the confusion :)

@NickLaMuro
Copy link
Member Author

Oh, interesting. I wonder if that should be added as a dependency to that task.

@himdel
Copy link
Contributor

himdel commented Jun 25, 2018

Or that :) I tried to fix this in #4205

But if this is needed for other stuff too..

@NickLaMuro
Copy link
Member Author

I see, that is why I got pinged so much. Just saw that now. Will comment there.

@Fryguy
Copy link
Member

Fryguy commented Jun 25, 2018

I waited on merging the rename thinking this fixed it, so this is a problem now that the rename has been merged.

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.

4 participants