Forum: Ruby A dream: gem require with auto-installer

B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2011-10-06 12:37
Hello,

When I develop some administration scripts and distribute them to
my colleague, we often encounter issues: I must write a readme or
an email for explain what to do for use them:
mkdir, gem install …

Why 'require X' instruction do not make a  'gem install X' when
the gem is not installed ?

With (red) Shoes, we got  "Shoes.setup { gem 'json_pure' } ", this is
really useful for non-native gem !

Sincerely,

Regis d'Aubarede
http://regisaubarede.posterous.com/
3e19fbf581d8a7fd51f2b8067a911f35?d=identicon&s=25 "Étienne Vallette d'Osia" <etienne.vallettedosia@g (Guest)
on 2011-10-06 14:44
(Received via mailing list)
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 06/10/2011 12:37, Regis d'Aubarede wrote:
    <blockquote
      cite="mid:ac8a7625ff00e0193e795c91e29f48ea@ruby-forum.com"
      type="cite">
      <pre wrap="">Hello,

When I develop some administration scripts and distribute them to
my colleague, we often encounter issues: I must write a readme or
an email for explain what to do for use them:
mkdir, gem install …

Why 'require X' instruction do not make a  'gem install X' when
the gem is not installed ?

With (red) Shoes, we got  "Shoes.setup { gem 'json_pure' } ", this is
really useful for non-native gem !

Sincerely,

Regis d'Aubarede
http://regisaubarede.posterous.com/

</pre>
    </blockquote>
    Hello,<br>
    <br>
    IMHO a such tool would be really dangerous, and not so useful:<br>
    the best option is to allow users to install everything in 1
    command.<br>
    <br>
    You should try Bundler : even if you don't want to use it in
your<br>
    application, you can provide a Gemfile (and, even better, a<br>
    Gemfile.lock) then user will be able to use it with "bundle
    install."<br>
    <br>
    An other way is to create a rake task which does to job.<br>
    <br>
    Regards,<br>
    <br>
    -- <br>
    Étienne Vallette d'Osia<br>
  </body>
</html>
A70c94da27a322b077742779f62ef81d?d=identicon&s=25 Phillip Gawlowski (Guest)
on 2011-10-06 14:49
(Received via mailing list)
On Thu, Oct 6, 2011 at 12:37 PM, Regis d'Aubarede
<regis.aubarede@gmail.com> wrote:
>
> Why 'require X' instruction do not make a 'gem install X' when
> the gem is not installed ?

Because not every require statement requires a gem.

--
Phillip Gawlowski

gplus.to/phgaw | twitter.com/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
       -- Leibniz
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2011-10-06 15:18
> You should try Bundler ...
> An other way is to create a rake task which does to job....

yes, so a readme file  is necessary


or I can do   that at the beginning of my script :

        def my_require(gem,pack=nil)  require gem
        rescue Exception => e
            puts "loading #{pack||gem} from internet ..."
            system("gem install  #{pack||gem} --no-ri --no-rdoc")  ;
            require gem
        end


and then :


        my_require 'json','json_pure'
        my_require 'green_shoes' ,   'gtk2,green_shoes'
        my_require 'toto' , 'zzz'
A70c94da27a322b077742779f62ef81d?d=identicon&s=25 Phillip Gawlowski (Guest)
on 2011-10-06 15:35
(Received via mailing list)
On Thu, Oct 6, 2011 at 3:19 PM, Regis d'Aubarede
<regis.aubarede@gmail.com> wrote:
> or I can do  that at the beginning of my script :
>
>    def my_require(gem,pack=nil) require gem
>    rescue Exception => e
>      puts "loading #{pack||gem} from internet ..."
>      system("gem install #{pack||gem} --no-ri --no-rdoc") ;
>      require gem
>    end

Breaks if the user account doesn't have write permissions to the gem
installation directory.

Also: Who the hell do you think you are that you think you are allowed
to futz around with my OS during your script's runtime? What you are
doing *screams* malware behaviour (connecting to the internet and
downloading code; nobody can guarantee that you haven't done a
system("gem sources -a http://malicious.url") somewhere in there).

If you are unable or unwilling to bundle your dependencies into one
package, that's very much _your_ problem: You can build a custom
RubyInstaller for Windows and include your dependencies, and for *NIX
you can create a tarball for distribution that includes your
dependencies. Heck, the latter works for Windows, too, if you don't
include native extensions.

--
Phillip Gawlowski

gplus.to/phgaw | twitter.com/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
       -- Leibniz
39093dd2b68b68960fecd0fe2b9a5045?d=identicon&s=25 Bartosz Dziewoński (matmarex)
on 2011-10-06 18:58
(Received via mailing list)
If you sent that kind of script to me, I'd print it out and slap you
with the paper.

For Windows, use Ocra for packaging; for Linux, everyone using it
should already be clever enough to do something as simple as a gem
install themselves.

Also, why a readme file? Just add a note to the top of the file in
question.

-- Matma Rex
Ab6938ed8ccd188beb1bb1ded5641931?d=identicon&s=25 Hilco Wijbenga (Guest)
on 2011-10-06 19:12
(Received via mailing list)
On 6 October 2011 06:34, Phillip Gawlowski <cmdjackryan@gmail.com>
wrote:
>
> package, that's very much _your_ problem: You can build a custom
> RubyInstaller for Windows and include your dependencies, and for *NIX
> you can create a tarball for distribution that includes your
> dependencies. Heck, the latter works for Windows, too, if you don't
> include native extensions.

If you're worried about malware then I don't see how running someone's
custom installer is any safer than running some script. Arguably, with
the script you at least have a chance to look at what it's doing.
A70c94da27a322b077742779f62ef81d?d=identicon&s=25 Phillip Gawlowski (Guest)
on 2011-10-06 19:16
(Received via mailing list)
On Thu, Oct 6, 2011 at 7:12 PM, Hilco Wijbenga
<hilco.wijbenga@gmail.com> wrote:
>
> If you're worried about malware then I don't see how running someone's
> custom installer is any safer than running some script. Arguably, with
> the script you at least have a chance to look at what it's doing.

It's much easier to audit a whole installer (and block it!), than read
a dozen scripts, chasing through whatever rabbit holes the code goes
through.

--
Phillip Gawlowski

gplus.to/phgaw | twitter.com/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
       -- Leibniz
233c279c012ebac792aaa805f966cbc7?d=identicon&s=25 Steve Klabnik (Guest)
on 2011-10-06 21:46
(Received via mailing list)
> With (red) Shoes, we got "Shoes.setup { gem 'json_pure' } ", this is
> really useful for non-native gem !

And as the Shoes maintainer, the reason that this is in here is
specifically to help new people. This feature is really useful, but it
does semi-violate what most programmers would expect out of a system.
Since Shoes is a custom Ruby distribution, we can play by slightly
different rules. :)
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2011-10-06 23:46
Perhaps this one will be less blamed :

  def my_require(gem,pack=nil)
    require gem
  rescue LoadError => e
    print "'#{gem}' package is missing. Can I load #{pack||'it'} \
    from internet without slap or go to hell ? (y/n) : "
    exit! if STDIN.gets.chomp !~ /^y|o$/i
    system("gem install  #{pack||gem} --no-ri --no-rdoc")  ;
    Gem.clear_paths() && require(gem) && puts("loading '#{gem}' ok!")
  end

  my_require 'xxx'
  my_require 'json','json_pure'
  my_require 'green_shoes' ,   'gtk2,green_shoes'
  my_require 'foo' , 'zzz'


Thank you very much for your help,
realy...
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.