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

Remove hard dep on Redis and update bin #96

Merged
merged 5 commits into from
Jan 8, 2017

Conversation

Ch4s3
Copy link
Member

@Ch4s3 Ch4s3 commented Jan 6, 2017

No description provided.

@Ch4s3
Copy link
Member Author

Ch4s3 commented Jan 6, 2017

@ibnesayeed What are your thoughts on making Redis a soft dependency? This gem gets rolled into Jekyll and I imagine people don't want to run redis to build their blogs.

@ibnesayeed
Copy link
Contributor

@Ch4s3 I like this soft dependency approach better. I was actually thinking about it in the beginning that if there is a way to get the tests passing, but don't force users to install a dependency that they might not use. However, I didn't know the trick to provision that.

begin
require 'redis'
rescue LoadError
puts 'The redis gem is required to use the redis backend.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use $stderr instead? Unless, this repository as a whole only uses STDOUT for all sorts of outputs.

$stderr.puts "The redis gem is required to use the Redis backend. To install redis gem run:\n\ngem install redis\n"

Copy link
Member Author

Choose a reason for hiding this comment

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

Either this, or we should raise if it fails... hum

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think raising exception with helpful message would be a better way. It will automatically use the STDERR channel and will allow the application terminate they way it should be.

Copy link
Member

Choose a reason for hiding this comment

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

With more complex systems, I would recommend indicating where this comes from. This message should contain classifier-reborn somewhere in there.

Additionally, the user experience of wanting redis and not fulfilling the requirements should be considered. I think a hard raise would be the most direct way to ensure if the user wants to use redis, they get redis.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll update this to raise with a message including the gem name and maybe some relevant info. I'll play around with error messages and see if I can come up with something intuitive and helpful.

@@ -1,4 +1,2 @@
source 'https://rubygems.org'
gemspec

gem 'redis'
Copy link
Member

Choose a reason for hiding this comment

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

FWIW this is how you'd do a soft dependency for this repo. It'd be a hard dependency if it were added to the .gemspec file instead as a runtime_dependency.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I thought it made sense to keep it in the gemspec

Copy link
Contributor

Choose a reason for hiding this comment

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

Another way to convey the message is to use conditional inclusion in the Gemfile like:

gem 'redis' if ENV['REDIS']

This approach will still need the NoRedisError message, but the text can be updated to reflect the procedure or passing environment variable while running bundle install. This will have an added advantage of tracking the desired version number of the gem in the Gemfile. Additionally, anyone looking at the Gemfile will notice the need of the gem.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather avoid using ENV vars for installation. That can make things more complicated for users, and libs upstream that use Classifier.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather avoid using ENV vars for installation. That can make things more complicated for users, and libs upstream that use Classifier.

I agree! However, I have seen this trick being used in SciRuby/rb-gsl/Gemfile.

@@ -34,4 +34,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('minitest-reporters')
s.add_development_dependency('rubocop')
s.add_development_dependency('pry')
s.add_development_dependency('redis')
Copy link
Member

Choose a reason for hiding this comment

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

This works too. 😄

@@ -6,31 +6,3 @@
rescue
require 'classifier'
end
Copy link
Member

Choose a reason for hiding this comment

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

Why not remove the whole file?

Copy link
Member Author

Choose a reason for hiding this comment

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

wanted to double check and make sure it wasn't being used.

@Ch4s3
Copy link
Member Author

Ch4s3 commented Jan 7, 2017

I added a custom error class, but the use feels clunky. What do you @parkr and @ibnesayeed?

 begin
    require 'redis'
  rescue LoadError
    raise NoRedisError
  end

Which emits this error:

NoRedisError: The Redis Backend can only be used if Redis is installed.
        This error is raised from 'lib/classifier-reborn/backends/bayes_redis_backend.rb'.
        If you have encountered this error and would like to use the Redis Backend,
        please run 'gem install redis' or include 'gem "redis", "~>3.2"' in
        your gemfile. For more info see https://github.com/jekyll/classifier-reborn#usage.

@ibnesayeed
Copy link
Contributor

There are actually two requirements to use the Redis backend:

  • The redis gem is installed
  • A Redis server is running (locally or remotely) to connect to

If the gem is installed but the Redis server is not available to connect then the error should be raised from the redis gem itself. You might want to update the message to educate users about the two requirements.

@Ch4s3
Copy link
Member Author

Ch4s3 commented Jan 7, 2017

I could probably just wrap the redis error and return separate info

@ibnesayeed
Copy link
Contributor

I was thinking of catching that error in the redis backend if the connection can't be established with the redis server (which might not be running or the correct connection config is not passed). But then I realized that the underlying redis gem will issue sensible message, enough for the user to know what's wrong. Here is the exception that is raised from redis gem.

Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)

If this is not enough (which I think it actually is) then we can update the initialize method of BayesRedisBackend with custom message.

@Ch4s3
Copy link
Member Author

Ch4s3 commented Jan 7, 2017

That probably works.

@ibnesayeed
Copy link
Contributor

or include 'gem "redis", "~>3.2"'

I would avoid specifying the version number here (assuming that we dont have any specific need of a specific version of redis gem and the user is familiar enough with the Gemfile to specify a version if desired). Having a version number here means it will be an ongoing maintenance overhead, one which would be very easy to forget about (who will regularly check the upstream?). This might cause users to believe that we strictly need that version even if the upstream deprecates that version.

@Ch4s3
Copy link
Member Author

Ch4s3 commented Jan 8, 2017

Good point

@Ch4s3
Copy link
Member Author

Ch4s3 commented Jan 8, 2017

I was going to have minitest fire off 'redis-server' in a process before tests and kill it at the end, but with #101 that seems pointless, so I'm calling this done!

@Ch4s3 Ch4s3 merged commit e218359 into master Jan 8, 2017
@Ch4s3 Ch4s3 deleted the remove_hard_dep_and_update_bin branch January 8, 2017 00:35
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 this pull request may close these issues.

None yet

3 participants