Re: [External] re: Adding a directory to LOAD_PATH

"Tran, Minh" <[email protected]> Thu, 7 Nov 2019 17:41:40 +0000
Newsgroups gmane.comp.lang.ruby.general
Message-ID <SN6PR05MB53919815A2307B3916918892EE780@SN6PR05MB5391.namprd05.prod.outlook.com>
--===============1047638486==
Content-Language: en-US
Content-Type: multipart/alternative;
	boundary="_000_SN6PR05MB53919815A2307B3916918892EE780SN6PR05MB5391namp_"

--_000_SN6PR05MB53919815A2307B3916918892EE780SN6PR05MB5391namp_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Thank you so much Leam.
I would like to load the kinetic-sdk.rb program in /vendor/kinetic-sdk-rb/ =
 to my current working directory /my_project ;
so would the following command work ?

$LOAD_PATH << File.expand_path("/vendor/kinectic-sdk-rb", __FILE__)
________________________________
From: ruby-talk <[email protected]> on behalf of Leam Hall <l=
[email protected]>
Sent: Thursday, November 7, 2019 12:16 PM
To: Ruby users <[email protected]>
Subject: Re: [External] re: Adding a directory to LOAD_PATH

Have you tried something like:

     $LOAD_PATH << File.expand_path("../my_project/", __FILE__)

That's what I usually do, with "../lib".

Leam


On 11/7/19 11:55 AM, Tran, Minh wrote:
>
> Thank you so much Raj for all of the helps.
> Since I am new to Ruby, could I ask on how could I add my project vendor
> directory to the load path ?
>
> I did a ruby -e 'puts $LOADPATH' command , and it gave me my current
> LOAD_PATH
>
> /usr/local/lib/site_ruby/2.3.0
> /usr/local/lib/x86_64-linux-gnu/site_ruby
> /usr/local/lib/site_ruby
> /usr/lib/ruby/vendor_ruby/2.3.0
> /usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.3.0
> /usr/lib/ruby/vendor_ruby
> /usr/lib/ruby/2.3.0
> /usr/lib/x86_64-linux-gnu/ruby/2.3.0
>
> I am still googling for a Ruby command that I could use to add my vendor
> folder to the LOAD_PATH.
>
> Thanks for all of the helps,
> Minh
>
>
> ------------------------------------------------------------------------
> *From:* ruby-talk <[email protected]> on behalf of Raj
> Sahae <[email protected]>
> *Sent:* Wednesday, November 6, 2019 5:54 PM
> *To:* Ruby users <[email protected]>
> *Subject:* [External] Re: Could not load a Ruby program
> This is sort of a strange thing to do. You are using require while
> dynamically generating the path based on the location of test.rb, which
> could change with respect to your vendor directory.
> Your error message would seem to indicate that the relative path of
> kinetic-sdk.rb from test.rb is not what you are specifying.
>
> If you want to use kinetic-sdk.rb as a library file, then the folder you
> want to load it from should be in your load path.
> There are a couple ways to do this but in my opinion the easiest to test
> with is using "ruby -I"
>
> So if I were you, I would keep kinetic-sdk.rb where it is, and add your
> projects vendor directory to the load path, and then call require in
> test.rb with that relative path.
>
> test.rb would be something like
>
> *#!/usr/bin/ruby
> *
> *puts "Hello World!"
> *
> *require 'kinectic-sdk-rb/kinectic-sdk.rb'*
> *
> *
> And you would run it with a command like
>
> ruby -I my_project/vendor test.rb
>
> You can persist that sort of thing by setting your RUBYLIB env variable,
> or changing load_path inside your test.rb, etc. There are many ways.
>
>
> -Raj
>
>
> On Wed, Nov 6, 2019 at 1:39 PM Tran, Minh <[email protected]
> <mailto:[email protected]>> wrote:
>
>     Hello,
>
>          I have a scenario that I need to execute a program from the
>     other directory than my current directory.
>     I got an error when I ran it, and I would like to seek helps
>     and expertises.
>
>
>     My current directory is at my_project, and the program that
>     I would like to execute is
>     at my_project/vendor/kinectic-sdk-rb/kinectic-sdk.rb
>
>     In my current directory my_project, I have  a test.rb which contains
>     a very simple line of code such as
>
>     #!/usr/bin/ruby
>     puts "Hello World!"
>     require File.join (File.expand_path (File.dirname(__FILE__)),
>     'vendor/kinectic-sdk-rb/kinectic-sdk.rb')
>
>
>     I tried to run the test.rb at my current directory which
>     is my_project , and I got the following error message:
>
>     Could not load file kinectic-sdk.rb  from
>     my  /my_project/vendor/kinectic-sdk-rb/kinectic-sdk.rb folder.
>
>
>     Thanks for all of your helps,
>     Minh
>
>


Unsubscribe: <mailto:[email protected]?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

________________________________

This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).

--_000_SN6PR05MB53919815A2307B3916918892EE780SN6PR05MB5391namp_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
Thank you so much Leam. </div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
I would like to&nbsp;load the kinetic-sdk.rb program in /vendor/kinetic-sdk=
-rb/&nbsp;&nbsp;to my current working directory /my_project ;
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
so would the following command work ?</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<br>
</div>
<div style=3D"color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,san=
s-serif; font-size: 12pt;">
<font size=3D"3">$LOAD_PATH &lt;&lt; File.expand_path(&quot;/vendor/kinecti=
c-sdk-rb&quot;, __FILE__)</font>&nbsp;&nbsp;&nbsp;<br>
</div>
<div id=3D"appendonsend"></div>
<hr style=3D"display:inline-block;width:98%" tabindex=3D"-1">
<div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st=
yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> ruby-talk &lt;ruby-ta=
[email protected]&gt; on behalf of Leam Hall &lt;[email protected]&=
gt;<br>
<b>Sent:</b> Thursday, November 7, 2019 12:16 PM<br>
<b>To:</b> Ruby users &lt;[email protected]&gt;<br>
<b>Subject:</b> Re: [External] re: Adding a directory to LOAD_PATH</font>
<div>&nbsp;</div>
</div>
<div class=3D"BodyFragment"><font size=3D"2"><span style=3D"font-size:11pt;=
">
<div class=3D"PlainText">Have you tried something like:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; $LOAD_PATH &lt;&lt; File.expand_path(&quot;../my_p=
roject/&quot;, __FILE__)<br>
<br>
That's what I usually do, with &quot;../lib&quot;.<br>
<br>
Leam<br>
<br>
<br>
On 11/7/19 11:55 AM, Tran, Minh wrote:<br>
&gt; <br>
&gt; Thank you so much Raj for all of the helps.<br>
&gt; Since I am new to Ruby, could I ask on how could I add my project vend=
or <br>
&gt; directory to the load path ?<br>
&gt; <br>
&gt; I did a ruby -e 'puts $LOADPATH' command , and it gave me my current <=
br>
&gt; LOAD_PATH<br>
&gt; <br>
&gt; /usr/local/lib/site_ruby/2.3.0<br>
&gt; /usr/local/lib/x86_64-linux-gnu/site_ruby<br>
&gt; /usr/local/lib/site_ruby<br>
&gt; /usr/lib/ruby/vendor_ruby/2.3.0<br>
&gt; /usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.3.0<br>
&gt; /usr/lib/ruby/vendor_ruby<br>
&gt; /usr/lib/ruby/2.3.0<br>
&gt; /usr/lib/x86_64-linux-gnu/ruby/2.3.0<br>
&gt; <br>
&gt; I am still&nbsp;googling for a Ruby command that I could use to add my=
 vendor <br>
&gt; folder to the LOAD_PATH.<br>
&gt; <br>
&gt; Thanks for all of the helps,<br>
&gt; Minh<br>
&gt; <br>
&gt; <br>
&gt; ----------------------------------------------------------------------=
--<br>
&gt; *From:* ruby-talk &lt;[email protected]&gt; on behalf of=
 Raj <br>
&gt; Sahae &lt;[email protected]&gt;<br>
&gt; *Sent:* Wednesday, November 6, 2019 5:54 PM<br>
&gt; *To:* Ruby users &lt;[email protected]&gt;<br>
&gt; *Subject:* [External] Re: Could not load a Ruby program<br>
&gt; This is sort of a strange thing to do. You are using require while <br=
>
&gt; dynamically generating the path based on the location of test.rb, whic=
h <br>
&gt; could change with respect to your vendor directory.<br>
&gt; Your error message would seem to indicate that the relative path of <b=
r>
&gt; kinetic-sdk.rb from test.rb is not what you are specifying.<br>
&gt; <br>
&gt; If you want to use kinetic-sdk.rb as a library file, then the folder y=
ou <br>
&gt; want to load it from should be in your load path.<br>
&gt; There are a couple ways to do this but in my opinion the easiest to te=
st <br>
&gt; with is using &quot;ruby -I&quot;<br>
&gt; <br>
&gt; So if I were you, I would keep kinetic-sdk.rb where it is, and add you=
r <br>
&gt; projects vendor directory to the load path, and then call require in <=
br>
&gt; test.rb with that relative path.<br>
&gt; <br>
&gt; test.rb would be something like<br>
&gt; <br>
&gt; *#!/usr/bin/ruby<br>
&gt; *<br>
&gt; *puts &quot;Hello World!&quot;<br>
&gt; *<br>
&gt; *require 'kinectic-sdk-rb/kinectic-sdk.rb'*<br>
&gt; *<br>
&gt; *<br>
&gt; And you would run it with a command like<br>
&gt; <br>
&gt; ruby -I my_project/vendor test.rb<br>
&gt; <br>
&gt; You can persist that sort of thing by setting your RUBYLIB env variabl=
e, <br>
&gt; or changing load_path inside your test.rb, etc. There are many ways.<b=
r>
&gt; <br>
&gt; <br>
&gt; -Raj<br>
&gt; <br>
&gt; <br>
&gt; On Wed, Nov 6, 2019 at 1:39 PM Tran, Minh &lt;minh.tran@emoryhealthcar=
e.org <br>
&gt; &lt;<a href=3D"mailto:[email protected]">mailto:minh.tran@=
emoryhealthcare.org</a>&gt;&gt; wrote:<br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Hello,<br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; I have a scenario tha=
t I&nbsp;need to execute a program from the<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; other directory than my current directory.<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; I got an error when I ran it, and I would like=
 to seek helps<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; and&nbsp;expertises.<br>
&gt; <br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; My current directory is at my_project, and&nbs=
p;the&nbsp;program that<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; I&nbsp;would&nbsp;like&nbsp;to execute is<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; at&nbsp;my_project/vendor/kinectic-sdk-rb/kine=
ctic-sdk.rb<br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; In my current directory my_project, I have&nbs=
p; a test.rb which contains<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; a very simple line of code such as<br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; #!/usr/bin/ruby<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; puts &quot;Hello World!&quot;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; require File.join (File.expand_path (File.dirn=
ame(__FILE__)),<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; 'vendor/kinectic-sdk-rb/kinectic-sdk.rb')<br>
&gt; <br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; I tried to run the test.rb at my current direc=
tory&nbsp;which<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; is&nbsp;my_project , and I got the following e=
rror message:<br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Could not load&nbsp;file kinectic-sdk.rb&nbsp;=
 from<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; my&nbsp;&nbsp;/my_project/vendor/kinectic-sdk-=
rb/kinectic-sdk.rb folder.<br>
&gt; <br>
&gt; <br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Thanks for all of your helps,<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Minh<br>
&gt; <br>
&gt; <br>
<br>
<br>
Unsubscribe: &lt;<a href=3D"mailto:[email protected]?subject=
=3Dunsubscribe">mailto:[email protected]?subject=3Dunsubscrib=
e</a>&gt;<br>
&lt;<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk=
">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk</a>&gt;<br>
</div>
</span></font></div>
<br>
<hr>
<font face=3D"Arial" color=3D"Gray" size=3D"1"><br>
This e-mail message (including any attachments) is for the sole use of<br>
the intended recipient(s) and may contain confidential and privileged<br>
information. If the reader of this message is not the intended<br>
recipient, you are hereby notified that any dissemination, distribution<br>
or copying of this message (including any attachments) is strictly<br>
prohibited.<br>
<br>
If you have received this message in error, please contact<br>
the sender by reply e-mail message and destroy all copies of the<br>
original message (including attachments).<br>
</font>
</body>
</html>

--_000_SN6PR05MB53919815A2307B3916918892EE780SN6PR05MB5391namp_--

--===============1047638486==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--===============1047638486==--