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

metrical/metric_fu gives the error: uninitialized constant MetricFu::Configuration - how do I require this properly? #36

Closed
NullVoxPopuli opened this issue Jan 7, 2013 · 13 comments
Assignees

Comments

@NullVoxPopuli
Copy link

Originally, I was following this guide: http://metric-fu.rubyforge.org/ But that didn't work (got the same error as I'm getting now). and I read that using metrical is supposedly easier, as it is supposed to do a lot of the set up for you. But the following happens:

From the Terminal,

$ bundle exec rake spec rake aborted! uninitialized constant MetricFu::Configuration
in my Gemfile I have:

gem "metrical", :require => false
and then in my rakefile I have:

require "metrical"

rails 2.3.14
ruby 1.8.7
metrical 0.1.0
I'm using metric_fu (2.1.3.6)
how can I require metrical / metric fu correctly?

If I just use metric_fu instead of metrical

I have
require "metric_fu", :require => false # in gemfile
and
require "metric_fu" # in my Rakefile

this metric_fu is 2.1.3.6 (same as above)

and when I run bundle exec metric_fu

I still get the same error. :-\

EDIT by bf4: original question

@ghost ghost assigned bf4 Jan 8, 2013
@bf4
Copy link
Member

bf4 commented Jan 8, 2013

I've been unable to reproduce this error. I've written up a wiki page with some pointers on additional information that would be helpful in debugging this error. Please add some more information.

My guess, is that since I've changed the load order of some of the classes, you might be calling MetricFu::Configuration before you've loaded lib/metric_fu.rb e.g. the included rake task https://github.com/metricfu/metric_fu/blob/master/lib/tasks/metric_fu.rake assumes lib/metric_fu.rb has already been required, as that requires all the files in lib/*.rb before loading lib/tasks/metric_fu.rake

@NullVoxPopuli
Copy link
Author

Ok, cool. Here are updates:

Ubuntu 12.10
Rails 2.3.14
Ruby 1.8.7
From Gemfile.lock:
metric_fu (2.1.3.6)
Saikuro (= 1.1.0)
activesupport (>= 2.0.0)
arrayfields (= 4.7.4)
bluff
churn (= 0.0.25)
coderay
fattr (= 2.2.1)
flay (= 1.2.1)
flog (= 2.3.0)
googlecharts
map (= 6.2.0)
metric_fu-roodi (>= 2.2.0)
rails_best_practices (> 0.10.1)
rcov (
> 0.8)
reek (= 1.2.12)
ripper (= 1.0.5)
sexp_processor (~> 3.0.3)
metric_fu-roodi (2.2.0)
ruby_parser

Configuration:

When I run bundle exec rake metrics:all (same result as bundle exec rake)as the readme instructs to do, I get the following error:
rake aborted!
uninitialized constant MetricFu::Configuration
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:466:in load_missing_constant' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:inconst_missing'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/run.rb:1
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in require' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:inrequire'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in new_constants_in' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:inrequire'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/load_files.rb:10
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/load_files.rb:9:in each' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/load_files.rb:9 /home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:inrequire'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in require' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:innew_constants_in'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in require' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/metric_fu.rb:13:inlib_require'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/metric_fu.rb:11:in each' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/metric_fu.rb:11:inlib_require'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.6/lib/metric_fu.rb:58
/home/me/my_project/Rakefile:19:in `require'
/home/me/my_project/Rakefile:19
/home/me/.rvm/gems/ruby-1.8.7-p371/bin/ruby_noexec_wrapper:14
(See full trace by running task with --trace)

What I've tried: requiring metric_fu in the gemfile instead of the Rakefile. This cause bundle exec rake metrics:all to throw an error: Don't know how to build task 'metrics:all'

I've also tried metrical, which has a very similar setup (I just changed metric_fu to metrical in both my gemfile and rakefile, and it generated the same error)

@bf4
Copy link
Member

bf4 commented Jan 8, 2013

Thanks for the additional info. That helps.

Try again with metric_fu gem version 2.1.3.7.18 which includes a bug fix (requiring the Configuration file before it's called in run.rb ) and is packaged for ruby 1.8. I'm not sure if version 2.1.3.7.19 will work for you. It's the same code, but packaged with the ruby 1.9 dependencies in mind.

@NullVoxPopuli
Copy link
Author

That version isn't available?

gem "metric_fu", "2.1.3.7.18", :require => false

$ bundle install (bundle update does the same thing)
Could not find gem 'metric_fu (= 2.1.3.7.18) ruby' in the gems available on this machine.

Do I need to specify a source or :git?

@bf4
Copy link
Member

bf4 commented Jan 8, 2013

My mistake. I somehow failed to push the gem. I've pushed it now.

@NullVoxPopuli
Copy link
Author

Got this:

$ bundle exec rake metrics:all --trace
rake aborted!
no such file to load -- metric_fu
/home/me/my_project/Rakefile:18:in require' # require "metric_fu" /home/me/my_project/Rakefile:18 /home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/rake_module.rb:25:inload'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in load_rakefile' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/application.rb:583:inraw_load_rakefile'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/application.rb:89:in load_rakefile' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/application.rb:160:instandard_exception_handling'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/application.rb:88:in load_rakefile' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/application.rb:72:inrun'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/application.rb:160:in standard_exception_handling' /home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/lib/rake/application.rb:70:inrun'
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/rake-10.0.3/bin/rake:33
/home/me/.rvm/gems/ruby-1.8.7-p371/bin/rake:19:in `load'
/home/me/.rvm/gems/ruby-1.8.7-p371/bin/rake:19
/home/me/.rvm/gems/ruby-1.8.7-p371/bin/ruby_noexec_wrapper:14

@bf4
Copy link
Member

bf4 commented Jan 8, 2013

What happens if you just run metric_fu or bundle exec metric_fu from the commandline?

What happens if you go into irb and require rubygems and metric_fu? Does it return true? Does it do the same thing in the rails console?

Thanks

@NullVoxPopuli
Copy link
Author

$ bundle exec metric_fu
/home/me/.rvm/gems/ruby-1.8.7-p371@global/gems/bundler-1.2.1/lib/bundler/rubygems_integration.rb:223:in `bin_path': can't find executable metric_fu (Gem::Exception)
from /home/me/.rvm/gems/ruby-1.8.7-p371/bin/metric_fu:19
from /home/me/.rvm/gems/ruby-1.8.7-p371/bin/ruby_noexec_wrapper:14

require "metric_fu"
MissingSourceFile: no such file to load -- metric_fu

:-(

@bf4
Copy link
Member

bf4 commented Jan 9, 2013

I apologize for the back and forth. Somehow when I made the ruby18 branch I deleted the require lines in the gemspec for everything.. 1a902d5 I've now re-released the gem as 2.1.3.7.18.1 (I'll up the minor version once I know this is working). I was able to run this with the following lines in my gemfile on ruby 1.8.7-p72

gem 'metric_fu-metrical', :require => false
gem 'metric_fu', '2.1.3.7.18.1', :require => false

as both bundle exec metric_fu-metrical and bundle exec metric_fu. If you continue to have problems, please also try the 2.1.3.7.19 version before reporting back.

I appreciate you continuing to follow up here. I think this should work, but then I've thought that before.

For bonus points, let me know if you can run gem install metric_fu -v 2.1.3.18.1 && gem install metric_fu-metrical and then run metric_fu-metrical or metric_fu from the root of the project

@NullVoxPopuli
Copy link
Author

It's cool. Just glad I can help. The company I'm working for doesn't really have the resources at the moment to upgrade to Rails 3, so I really appreciate helping get 1.8.7 compatibility working again. :-)

After adding those to my gemfile, I have this in my gem list
metric_fu (2.1.3.7.18.1)
metric_fu-metrical (0.1.1)
metric_fu-roodi (2.2.0)

in my Rakefile, I still just have require "metric_fu"

I did find the output directory.... and at a glance the data looks ok. Not sure about the graphs though. Just a couple points an most of them.

bundle exec metric_fu-metrical and bundle exec metric_fu all do the same thing. bundle exec rake metrics:all also gives the same output, except takes a bit longer, I think

they give some errors. Here they are:
parse error on value ";" (tSEMI)
parse error on value ")" (tRPAREN)
parse error on value "-" (tMINUS)

Unexpected sexp_type :defn

#<RubyToken::TkCOMMENT:0x7f3d64ea5e18 @char_no=19, @seek=32561, @line_no=960>
undefined method `name' for #<RubyToken::TkCOMMENT:0x7f3d64ea5e18>
Error while parsing file : app/controllers/view_controller.rb
SystemExit
exit

`Lexer received an error for line 8 char 84`
`Lexer received an error for line 8 char 88`

I also get :
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.7.18.1/lib/metric_fu.rb:2: warning: already initialized constant APP_ROOT
/home/me/.rvm/gems/ruby-1.8.7-p371/gems/metric_fu-2.1.3.7.18.1/lib/metric_fu.rb:3: warning: already initialized constant LIB_ROOT

For the bonus points: :-)

$ gem install metric_fu -v 2.1.3.18.1 && gem install metric_fu-metrical
ERROR: Could not find a valid gem 'metric_fu' (= 2.1.3.18.1) in any repository
ERROR: Possible alternatives: metric_fu

$ bundle exec gem install metric_fu -v 2.1.3.18.1 && bundle exec gem install metric_fu-metrical
ERROR: Could not find a valid gem 'metric_fu' (= 2.1.3.18.1) in any repository
ERROR: Possible alternatives: metric_fu

so.. that's weird. :-\

@bf4
Copy link
Member

bf4 commented Jan 9, 2013

Those warnings are expected. Did the metrics otherwise display properly? Can we consider this bug fixed?

The reason it would be faster to run without rake is because I removed the rake dependency for running the metrics, and when you explicitly include it, it slows down.

Also, the gem install line had a typo.. should have been 2.1.3.7.18.1 not 2.1.3.18.1

@NullVoxPopuli
Copy link
Author

Excellent. Yeah, I'd say we can consider the bug fixed. My problem of getting the thing to run at all is solved. :-)
Reports and graphs are generated.

Ah, yeah, that makes sense. Thanks!

@bf4
Copy link
Member

bf4 commented Jan 9, 2013

great!

@bf4 bf4 closed this as completed Jan 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants