Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-20 Thread David Storrs
On Fri, Jan 20, 2017 at 10:02 AM, Robby Findler
 wrote:
> On Thu, Jan 19, 2017 at 7:29 PM, David Storrs  wrote:
>> On Thu, Jan 19, 2017 at 6:45 PM, Robby Findler
>>  wrote:
>>> In DrRacet, current-directory in initialized to the directory
>>> containing the file where you hit "Run" and in the shell it is
>>> initialized to the current directory as understood by the shell.
>>>
>>> Is that what you're asking?
>>>
>>> Robby
>>
>> I think so, yes.  What is current-directory set to for the DrRacket repl?
>
> It is initialized to the directory containing the file where you hit "Run".
>
>> On a related topic, Dr Racket does not seem to properly inherit the
>> environment from the shell.  (getenv "PATH") from the repl does not
>> return the same value as "echo $PATH" from the shell.  Does Dr Racket
>> have anything equivalent to a .bashrc file?
>
> If you were to open DrRacket by running `bin/drracket` (a shell
> script) or `racket -l drracket`, it will get the environment of that
> shell. If you run it by double clicking or using "open -a DrRacket" or
> "open file.rkt" (or other similar ways) it will start the process in
> an empty (emptier) environment.
>
> Robby

Perfect, that's just what I needed.  Thanks, Robby.

>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-20 Thread Robby Findler
On Thu, Jan 19, 2017 at 7:29 PM, David Storrs  wrote:
> On Thu, Jan 19, 2017 at 6:45 PM, Robby Findler
>  wrote:
>> In DrRacet, current-directory in initialized to the directory
>> containing the file where you hit "Run" and in the shell it is
>> initialized to the current directory as understood by the shell.
>>
>> Is that what you're asking?
>>
>> Robby
>
> I think so, yes.  What is current-directory set to for the DrRacket repl?

It is initialized to the directory containing the file where you hit "Run".

> On a related topic, Dr Racket does not seem to properly inherit the
> environment from the shell.  (getenv "PATH") from the repl does not
> return the same value as "echo $PATH" from the shell.  Does Dr Racket
> have anything equivalent to a .bashrc file?

If you were to open DrRacket by running `bin/drracket` (a shell
script) or `racket -l drracket`, it will get the environment of that
shell. If you run it by double clicking or using "open -a DrRacket" or
"open file.rkt" (or other similar ways) it will start the process in
an empty (emptier) environment.

Robby

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread David Storrs
On Thu, Jan 19, 2017 at 6:45 PM, Robby Findler
 wrote:
> In DrRacet, current-directory in initialized to the directory
> containing the file where you hit "Run" and in the shell it is
> initialized to the current directory as understood by the shell.
>
> Is that what you're asking?
>
> Robby

I think so, yes.  What is current-directory set to for the DrRacket repl?

On a related topic, Dr Racket does not seem to properly inherit the
environment from the shell.  (getenv "PATH") from the repl does not
return the same value as "echo $PATH" from the shell.  Does Dr Racket
have anything equivalent to a .bashrc file?

>
>
> On Thu, Jan 19, 2017 at 4:36 PM, David Storrs  wrote:
>> For the record, I know I can pass an absolute path (defined with
>> define-runtime-path) to load-initial-data.  My question is more about
>> "why is this different between the shell and Dr Racket?"
>>
>> On Thu, Jan 19, 2017 at 5:23 PM, David Storrs  wrote:
>>> define-runtime-path is based on the enclosing file, not the running file.
>>>
>>>
>>>
>>> ;; file:  app/lib/db/initial_test_data.sql
>>> ...various SQL commands...
>>>
>>>
>>> ;; file:  app/lib/t/testing_utils.rkt
>>> (define-runtime-path thisdir ".")
>>> (define cmd (string-append "psql -d biomantica < "
>>>  (path->string (build-path thisdir where
>>>   (say "shelling out in order to load initial data into DB. Command
>>> is: \n\t" cmd)
>>>   (system cmd)
>>> )
>>>
>>>
>>> ;;  file:  app/test_1.rkt
>>> (require "lib/t/testing_utils.rkt")
>>> (load-initial-data "lib/db/initial_test_data.sql")
>>>
>>>
>>> ;;  file:  app/lib/db/test_2.rkt
>>> (require "../t/testing_utils.rkt")
>>> (load-initial-data "./initial_test_data.sql")
>>>
>>>
>>> $ ./test_1.rkt
>>> shelling out in order to load initial data into DB. Command is:
>>> psql -d biomantica < ./lib/db/initial_test_data.sql
>>> INSERT 0 0
>>> ...lots of other SQL results...
>>>
>>> $  ./lib/db/test_2.rkt
>>> shelling out in order to load initial data into DB. Command is:
>>> psql -d biomantica < ././initial_test_data.sql
>>> /bin/sh: ././initial_test_data.sql: No such file or directory
>>> #f
>>>
>>>
>>> Note that both test_N.rkt files worked when I used the prior version.
>>>
>>> On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
>>>  wrote:
 define-runtime-path is designed for this problem, IIUC. Let me know if
 the docs don't help.

 Robby

 On Thu, Jan 19, 2017 at 11:47 AM, David Storrs  
 wrote:
> Short form:  When using Dr Racket, how do I write something that says
> "Here is a path to a file that I care about.  The path is relative to
> you, the script that is running the code" ?
>
> Long form:
>
> I have a file, testing_utils.rkt, that includes the following snippet of 
> code:
>
> (define (load-initial-data where)
>   (define cmd (string-append "psql -d biomantica < "
>  (path->string
>   (path-only
>(path->complete-path
> (find-system-path 'run-file
>  where))
>   (say "shelling out in order to load initial data into DB. Command
> is: \n\t" cmd)
>
>   (void
>(with-output-to-string  ;; silence the output
>  (thunk
>   (system cmd)
>
>
> The way this gets used is that one of our test scripts (e.g.
> 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
> call the load-initial-data function as follows:
>
> (load-initial-data "../initial_test_data.sql")
>
> I operate in Emacs via the shell, while my cofounder James uses Dr
> Racket.  The above sequence works for me but not for him.  When I run
> endpoints.t it locates the endpoints.t file, generates the path from
> there to the initial_test_data.sql file, and shells out to run that
> SQL through psql in order to load the database for testing.  When
> James tries it it fails.
>
> The failure seems to be that for me "the running script" is the
> endpoints.t file, while for him it's the Dr Racket executable.  I'm
> not sure where to even begin sorting this out, so I was hoping for
> some help.
>
> Any thoughts?
>
> Dave
>
>
> PS:  James had to step out for something else or he would be sending
> this himself.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

 --
 You received this message because you are subscribed to the 

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
Assuming I understand it correctly, I think the problem in the original is
that, in Dr. Racket, (find-system-path 'run-file) returns the path of Dr.
Racket, whereas at the shell it returns the path of the file being run.

It's a hack, but I think you could make a quick and dirty solution to
finding the directory of the running module in either case by checking if
the program is running in Dr. Racket and, if it is, taking advantage of the
way Dr. Racket initializes current-directory. This seems to work, assuming
that your program isn't supposed to have "DrRacket" anywhere in its path
and that Dr. Racket does (it does on MacOS, at least):

(let ([run-file (path->complete-path (find-system-path 'run-file))])
  (cond
[(regexp-match? #rx"DrRacket" run-file)
 (path->complete-path
  (current-directory))]
[else
 (path-only run-file)]))


-Philip

On Thu, Jan 19, 2017 at 5:45 PM, Robby Findler 
wrote:

> In DrRacet, current-directory in initialized to the directory
> containing the file where you hit "Run" and in the shell it is
> initialized to the current directory as understood by the shell.
>
> Is that what you're asking?
>
> Robby
>
>
> On Thu, Jan 19, 2017 at 4:36 PM, David Storrs 
> wrote:
> > For the record, I know I can pass an absolute path (defined with
> > define-runtime-path) to load-initial-data.  My question is more about
> > "why is this different between the shell and Dr Racket?"
> >
> > On Thu, Jan 19, 2017 at 5:23 PM, David Storrs 
> wrote:
> >> define-runtime-path is based on the enclosing file, not the running
> file.
> >>
> >>
> >>
> >> ;; file:  app/lib/db/initial_test_data.sql
> >> ...various SQL commands...
> >>
> >>
> >> ;; file:  app/lib/t/testing_utils.rkt
> >> (define-runtime-path thisdir ".")
> >> (define cmd (string-append "psql -d biomantica < "
> >>  (path->string (build-path thisdir where
> >>   (say "shelling out in order to load initial data into DB. Command
> >> is: \n\t" cmd)
> >>   (system cmd)
> >> )
> >>
> >>
> >> ;;  file:  app/test_1.rkt
> >> (require "lib/t/testing_utils.rkt")
> >> (load-initial-data "lib/db/initial_test_data.sql")
> >>
> >>
> >> ;;  file:  app/lib/db/test_2.rkt
> >> (require "../t/testing_utils.rkt")
> >> (load-initial-data "./initial_test_data.sql")
> >>
> >>
> >> $ ./test_1.rkt
> >> shelling out in order to load initial data into DB. Command is:
> >> psql -d biomantica < ./lib/db/initial_test_data.sql
> >> INSERT 0 0
> >> ...lots of other SQL results...
> >>
> >> $  ./lib/db/test_2.rkt
> >> shelling out in order to load initial data into DB. Command is:
> >> psql -d biomantica < ././initial_test_data.sql
> >> /bin/sh: ././initial_test_data.sql: No such file or directory
> >> #f
> >>
> >>
> >> Note that both test_N.rkt files worked when I used the prior version.
> >>
> >> On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
> >>  wrote:
> >>> define-runtime-path is designed for this problem, IIUC. Let me know if
> >>> the docs don't help.
> >>>
> >>> Robby
> >>>
> >>> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs 
> wrote:
>  Short form:  When using Dr Racket, how do I write something that says
>  "Here is a path to a file that I care about.  The path is relative to
>  you, the script that is running the code" ?
> 
>  Long form:
> 
>  I have a file, testing_utils.rkt, that includes the following snippet
> of code:
> 
>  (define (load-initial-data where)
>    (define cmd (string-append "psql -d biomantica < "
>   (path->string
>    (path-only
> (path->complete-path
>  (find-system-path 'run-file
>   where))
>    (say "shelling out in order to load initial data into DB. Command
>  is: \n\t" cmd)
> 
>    (void
> (with-output-to-string  ;; silence the output
>   (thunk
>    (system cmd)
> 
> 
>  The way this gets used is that one of our test scripts (e.g.
>  'endpoints.t') will (require "path/to/testing_utils.rkt") and then
>  call the load-initial-data function as follows:
> 
>  (load-initial-data "../initial_test_data.sql")
> 
>  I operate in Emacs via the shell, while my cofounder James uses Dr
>  Racket.  The above sequence works for me but not for him.  When I run
>  endpoints.t it locates the endpoints.t file, generates the path from
>  there to the initial_test_data.sql file, and shells out to run that
>  SQL through psql in order to load the database for testing.  When
>  James tries it it fails.
> 
>  The failure seems to be that for me "the running script" is the
>  endpoints.t file, while for him it's the Dr Racket executable.  I'm
>  not 

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Robby Findler
In DrRacet, current-directory in initialized to the directory
containing the file where you hit "Run" and in the shell it is
initialized to the current directory as understood by the shell.

Is that what you're asking?

Robby


On Thu, Jan 19, 2017 at 4:36 PM, David Storrs  wrote:
> For the record, I know I can pass an absolute path (defined with
> define-runtime-path) to load-initial-data.  My question is more about
> "why is this different between the shell and Dr Racket?"
>
> On Thu, Jan 19, 2017 at 5:23 PM, David Storrs  wrote:
>> define-runtime-path is based on the enclosing file, not the running file.
>>
>>
>>
>> ;; file:  app/lib/db/initial_test_data.sql
>> ...various SQL commands...
>>
>>
>> ;; file:  app/lib/t/testing_utils.rkt
>> (define-runtime-path thisdir ".")
>> (define cmd (string-append "psql -d biomantica < "
>>  (path->string (build-path thisdir where
>>   (say "shelling out in order to load initial data into DB. Command
>> is: \n\t" cmd)
>>   (system cmd)
>> )
>>
>>
>> ;;  file:  app/test_1.rkt
>> (require "lib/t/testing_utils.rkt")
>> (load-initial-data "lib/db/initial_test_data.sql")
>>
>>
>> ;;  file:  app/lib/db/test_2.rkt
>> (require "../t/testing_utils.rkt")
>> (load-initial-data "./initial_test_data.sql")
>>
>>
>> $ ./test_1.rkt
>> shelling out in order to load initial data into DB. Command is:
>> psql -d biomantica < ./lib/db/initial_test_data.sql
>> INSERT 0 0
>> ...lots of other SQL results...
>>
>> $  ./lib/db/test_2.rkt
>> shelling out in order to load initial data into DB. Command is:
>> psql -d biomantica < ././initial_test_data.sql
>> /bin/sh: ././initial_test_data.sql: No such file or directory
>> #f
>>
>>
>> Note that both test_N.rkt files worked when I used the prior version.
>>
>> On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
>>  wrote:
>>> define-runtime-path is designed for this problem, IIUC. Let me know if
>>> the docs don't help.
>>>
>>> Robby
>>>
>>> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs  
>>> wrote:
 Short form:  When using Dr Racket, how do I write something that says
 "Here is a path to a file that I care about.  The path is relative to
 you, the script that is running the code" ?

 Long form:

 I have a file, testing_utils.rkt, that includes the following snippet of 
 code:

 (define (load-initial-data where)
   (define cmd (string-append "psql -d biomantica < "
  (path->string
   (path-only
(path->complete-path
 (find-system-path 'run-file
  where))
   (say "shelling out in order to load initial data into DB. Command
 is: \n\t" cmd)

   (void
(with-output-to-string  ;; silence the output
  (thunk
   (system cmd)


 The way this gets used is that one of our test scripts (e.g.
 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
 call the load-initial-data function as follows:

 (load-initial-data "../initial_test_data.sql")

 I operate in Emacs via the shell, while my cofounder James uses Dr
 Racket.  The above sequence works for me but not for him.  When I run
 endpoints.t it locates the endpoints.t file, generates the path from
 there to the initial_test_data.sql file, and shells out to run that
 SQL through psql in order to load the database for testing.  When
 James tries it it fails.

 The failure seems to be that for me "the running script" is the
 endpoints.t file, while for him it's the Dr Racket executable.  I'm
 not sure where to even begin sorting this out, so I was hoping for
 some help.

 Any thoughts?

 Dave


 PS:  James had to step out for something else or he would be sending
 this himself.

 --
 You received this message because you are subscribed to the Google Groups 
 "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to racket-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
Not the question you asked, but instead of with-output-to-string, if you're
discarding the output, you might prefer:

(parameterize ([current-output-port (open-output-nowhere)])
  ...)


-Philip

On Thu, Jan 19, 2017 at 4:51 PM, Philip McGrath 
wrote:

> I haven't looked in detail, but two quick thoughts:
>
>- When I evaluate (find-system-path 'run-file) in Dr. Racket, either
>inside a module or in the REPL, I get #v6.7/DrRacket.app/Contents/MacOS/DrRacket>
>- Have you looked at (current-directory)? In Dr. Racket, if the file
>has been saved, that returns the path to the directory of the file being
>run, which might give you what you need. (Of course, if you manipulate
>current-directory, or run the program from the shell when your working
>directory is not the directory of the file being run, you will get
>different results.)
>- Greg Hendershott's "__FILE__ and __LINE__ in Racket" might be
>relevant, though I don't think it does exactly what you want (
>http://www.greghendershott.com/2014/06/-file-and-line-in-racket.html
>)
>
>
> -Philip
>
> On Thu, Jan 19, 2017 at 4:36 PM, David Storrs 
> wrote:
>
>> For the record, I know I can pass an absolute path (defined with
>> define-runtime-path) to load-initial-data.  My question is more about
>> "why is this different between the shell and Dr Racket?"
>>
>> On Thu, Jan 19, 2017 at 5:23 PM, David Storrs 
>> wrote:
>> > define-runtime-path is based on the enclosing file, not the running
>> file.
>> >
>> >
>> >
>> > ;; file:  app/lib/db/initial_test_data.sql
>> > ...various SQL commands...
>> >
>> >
>> > ;; file:  app/lib/t/testing_utils.rkt
>> > (define-runtime-path thisdir ".")
>> > (define cmd (string-append "psql -d biomantica < "
>> >  (path->string (build-path thisdir where
>> >   (say "shelling out in order to load initial data into DB. Command
>> > is: \n\t" cmd)
>> >   (system cmd)
>> > )
>> >
>> >
>> > ;;  file:  app/test_1.rkt
>> > (require "lib/t/testing_utils.rkt")
>> > (load-initial-data "lib/db/initial_test_data.sql")
>> >
>> >
>> > ;;  file:  app/lib/db/test_2.rkt
>> > (require "../t/testing_utils.rkt")
>> > (load-initial-data "./initial_test_data.sql")
>> >
>> >
>> > $ ./test_1.rkt
>> > shelling out in order to load initial data into DB. Command is:
>> > psql -d biomantica < ./lib/db/initial_test_data.sql
>> > INSERT 0 0
>> > ...lots of other SQL results...
>> >
>> > $  ./lib/db/test_2.rkt
>> > shelling out in order to load initial data into DB. Command is:
>> > psql -d biomantica < ././initial_test_data.sql
>> > /bin/sh: ././initial_test_data.sql: No such file or directory
>> > #f
>> >
>> >
>> > Note that both test_N.rkt files worked when I used the prior version.
>> >
>> > On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
>> >  wrote:
>> >> define-runtime-path is designed for this problem, IIUC. Let me know if
>> >> the docs don't help.
>> >>
>> >> Robby
>> >>
>> >> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs 
>> wrote:
>> >>> Short form:  When using Dr Racket, how do I write something that says
>> >>> "Here is a path to a file that I care about.  The path is relative to
>> >>> you, the script that is running the code" ?
>> >>>
>> >>> Long form:
>> >>>
>> >>> I have a file, testing_utils.rkt, that includes the following snippet
>> of code:
>> >>>
>> >>> (define (load-initial-data where)
>> >>>   (define cmd (string-append "psql -d biomantica < "
>> >>>  (path->string
>> >>>   (path-only
>> >>>(path->complete-path
>> >>> (find-system-path 'run-file
>> >>>  where))
>> >>>   (say "shelling out in order to load initial data into DB. Command
>> >>> is: \n\t" cmd)
>> >>>
>> >>>   (void
>> >>>(with-output-to-string  ;; silence the output
>> >>>  (thunk
>> >>>   (system cmd)
>> >>>
>> >>>
>> >>> The way this gets used is that one of our test scripts (e.g.
>> >>> 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
>> >>> call the load-initial-data function as follows:
>> >>>
>> >>> (load-initial-data "../initial_test_data.sql")
>> >>>
>> >>> I operate in Emacs via the shell, while my cofounder James uses Dr
>> >>> Racket.  The above sequence works for me but not for him.  When I run
>> >>> endpoints.t it locates the endpoints.t file, generates the path from
>> >>> there to the initial_test_data.sql file, and shells out to run that
>> >>> SQL through psql in order to load the database for testing.  When
>> >>> James tries it it fails.
>> >>>
>> >>> The failure seems to be that for me "the running script" is the
>> >>> endpoints.t file, while for him it's the Dr Racket executable.  I'm
>> 

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
I haven't looked in detail, but two quick thoughts:

   - When I evaluate (find-system-path 'run-file) in Dr. Racket, either
   inside a module or in the REPL, I get #
   - Have you looked at (current-directory)? In Dr. Racket, if the file has
   been saved, that returns the path to the directory of the file being run,
   which might give you what you need. (Of course, if you manipulate
   current-directory, or run the program from the shell when your working
   directory is not the directory of the file being run, you will get
   different results.)
   - Greg Hendershott's "__FILE__ and __LINE__ in Racket" might be
   relevant, though I don't think it does exactly what you want (
   http://www.greghendershott.com/2014/06/-file-and-line-in-racket.html)


-Philip

On Thu, Jan 19, 2017 at 4:36 PM, David Storrs 
wrote:

> For the record, I know I can pass an absolute path (defined with
> define-runtime-path) to load-initial-data.  My question is more about
> "why is this different between the shell and Dr Racket?"
>
> On Thu, Jan 19, 2017 at 5:23 PM, David Storrs 
> wrote:
> > define-runtime-path is based on the enclosing file, not the running file.
> >
> >
> >
> > ;; file:  app/lib/db/initial_test_data.sql
> > ...various SQL commands...
> >
> >
> > ;; file:  app/lib/t/testing_utils.rkt
> > (define-runtime-path thisdir ".")
> > (define cmd (string-append "psql -d biomantica < "
> >  (path->string (build-path thisdir where
> >   (say "shelling out in order to load initial data into DB. Command
> > is: \n\t" cmd)
> >   (system cmd)
> > )
> >
> >
> > ;;  file:  app/test_1.rkt
> > (require "lib/t/testing_utils.rkt")
> > (load-initial-data "lib/db/initial_test_data.sql")
> >
> >
> > ;;  file:  app/lib/db/test_2.rkt
> > (require "../t/testing_utils.rkt")
> > (load-initial-data "./initial_test_data.sql")
> >
> >
> > $ ./test_1.rkt
> > shelling out in order to load initial data into DB. Command is:
> > psql -d biomantica < ./lib/db/initial_test_data.sql
> > INSERT 0 0
> > ...lots of other SQL results...
> >
> > $  ./lib/db/test_2.rkt
> > shelling out in order to load initial data into DB. Command is:
> > psql -d biomantica < ././initial_test_data.sql
> > /bin/sh: ././initial_test_data.sql: No such file or directory
> > #f
> >
> >
> > Note that both test_N.rkt files worked when I used the prior version.
> >
> > On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
> >  wrote:
> >> define-runtime-path is designed for this problem, IIUC. Let me know if
> >> the docs don't help.
> >>
> >> Robby
> >>
> >> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs 
> wrote:
> >>> Short form:  When using Dr Racket, how do I write something that says
> >>> "Here is a path to a file that I care about.  The path is relative to
> >>> you, the script that is running the code" ?
> >>>
> >>> Long form:
> >>>
> >>> I have a file, testing_utils.rkt, that includes the following snippet
> of code:
> >>>
> >>> (define (load-initial-data where)
> >>>   (define cmd (string-append "psql -d biomantica < "
> >>>  (path->string
> >>>   (path-only
> >>>(path->complete-path
> >>> (find-system-path 'run-file
> >>>  where))
> >>>   (say "shelling out in order to load initial data into DB. Command
> >>> is: \n\t" cmd)
> >>>
> >>>   (void
> >>>(with-output-to-string  ;; silence the output
> >>>  (thunk
> >>>   (system cmd)
> >>>
> >>>
> >>> The way this gets used is that one of our test scripts (e.g.
> >>> 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
> >>> call the load-initial-data function as follows:
> >>>
> >>> (load-initial-data "../initial_test_data.sql")
> >>>
> >>> I operate in Emacs via the shell, while my cofounder James uses Dr
> >>> Racket.  The above sequence works for me but not for him.  When I run
> >>> endpoints.t it locates the endpoints.t file, generates the path from
> >>> there to the initial_test_data.sql file, and shells out to run that
> >>> SQL through psql in order to load the database for testing.  When
> >>> James tries it it fails.
> >>>
> >>> The failure seems to be that for me "the running script" is the
> >>> endpoints.t file, while for him it's the Dr Racket executable.  I'm
> >>> not sure where to even begin sorting this out, so I was hoping for
> >>> some help.
> >>>
> >>> Any thoughts?
> >>>
> >>> Dave
> >>>
> >>>
> >>> PS:  James had to step out for something else or he would be sending
> >>> this himself.
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> >>> To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> >>> For more options, visit 

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread David Storrs
For the record, I know I can pass an absolute path (defined with
define-runtime-path) to load-initial-data.  My question is more about
"why is this different between the shell and Dr Racket?"

On Thu, Jan 19, 2017 at 5:23 PM, David Storrs  wrote:
> define-runtime-path is based on the enclosing file, not the running file.
>
>
>
> ;; file:  app/lib/db/initial_test_data.sql
> ...various SQL commands...
>
>
> ;; file:  app/lib/t/testing_utils.rkt
> (define-runtime-path thisdir ".")
> (define cmd (string-append "psql -d biomantica < "
>  (path->string (build-path thisdir where
>   (say "shelling out in order to load initial data into DB. Command
> is: \n\t" cmd)
>   (system cmd)
> )
>
>
> ;;  file:  app/test_1.rkt
> (require "lib/t/testing_utils.rkt")
> (load-initial-data "lib/db/initial_test_data.sql")
>
>
> ;;  file:  app/lib/db/test_2.rkt
> (require "../t/testing_utils.rkt")
> (load-initial-data "./initial_test_data.sql")
>
>
> $ ./test_1.rkt
> shelling out in order to load initial data into DB. Command is:
> psql -d biomantica < ./lib/db/initial_test_data.sql
> INSERT 0 0
> ...lots of other SQL results...
>
> $  ./lib/db/test_2.rkt
> shelling out in order to load initial data into DB. Command is:
> psql -d biomantica < ././initial_test_data.sql
> /bin/sh: ././initial_test_data.sql: No such file or directory
> #f
>
>
> Note that both test_N.rkt files worked when I used the prior version.
>
> On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
>  wrote:
>> define-runtime-path is designed for this problem, IIUC. Let me know if
>> the docs don't help.
>>
>> Robby
>>
>> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs  
>> wrote:
>>> Short form:  When using Dr Racket, how do I write something that says
>>> "Here is a path to a file that I care about.  The path is relative to
>>> you, the script that is running the code" ?
>>>
>>> Long form:
>>>
>>> I have a file, testing_utils.rkt, that includes the following snippet of 
>>> code:
>>>
>>> (define (load-initial-data where)
>>>   (define cmd (string-append "psql -d biomantica < "
>>>  (path->string
>>>   (path-only
>>>(path->complete-path
>>> (find-system-path 'run-file
>>>  where))
>>>   (say "shelling out in order to load initial data into DB. Command
>>> is: \n\t" cmd)
>>>
>>>   (void
>>>(with-output-to-string  ;; silence the output
>>>  (thunk
>>>   (system cmd)
>>>
>>>
>>> The way this gets used is that one of our test scripts (e.g.
>>> 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
>>> call the load-initial-data function as follows:
>>>
>>> (load-initial-data "../initial_test_data.sql")
>>>
>>> I operate in Emacs via the shell, while my cofounder James uses Dr
>>> Racket.  The above sequence works for me but not for him.  When I run
>>> endpoints.t it locates the endpoints.t file, generates the path from
>>> there to the initial_test_data.sql file, and shells out to run that
>>> SQL through psql in order to load the database for testing.  When
>>> James tries it it fails.
>>>
>>> The failure seems to be that for me "the running script" is the
>>> endpoints.t file, while for him it's the Dr Racket executable.  I'm
>>> not sure where to even begin sorting this out, so I was hoping for
>>> some help.
>>>
>>> Any thoughts?
>>>
>>> Dave
>>>
>>>
>>> PS:  James had to step out for something else or he would be sending
>>> this himself.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread David Storrs
define-runtime-path is based on the enclosing file, not the running file.



;; file:  app/lib/db/initial_test_data.sql
...various SQL commands...


;; file:  app/lib/t/testing_utils.rkt
(define-runtime-path thisdir ".")
(define cmd (string-append "psql -d biomantica < "
 (path->string (build-path thisdir where
  (say "shelling out in order to load initial data into DB. Command
is: \n\t" cmd)
  (system cmd)
)


;;  file:  app/test_1.rkt
(require "lib/t/testing_utils.rkt")
(load-initial-data "lib/db/initial_test_data.sql")


;;  file:  app/lib/db/test_2.rkt
(require "../t/testing_utils.rkt")
(load-initial-data "./initial_test_data.sql")


$ ./test_1.rkt
shelling out in order to load initial data into DB. Command is:
psql -d biomantica < ./lib/db/initial_test_data.sql
INSERT 0 0
...lots of other SQL results...

$  ./lib/db/test_2.rkt
shelling out in order to load initial data into DB. Command is:
psql -d biomantica < ././initial_test_data.sql
/bin/sh: ././initial_test_data.sql: No such file or directory
#f


Note that both test_N.rkt files worked when I used the prior version.

On Thu, Jan 19, 2017 at 12:52 PM, Robby Findler
 wrote:
> define-runtime-path is designed for this problem, IIUC. Let me know if
> the docs don't help.
>
> Robby
>
> On Thu, Jan 19, 2017 at 11:47 AM, David Storrs  wrote:
>> Short form:  When using Dr Racket, how do I write something that says
>> "Here is a path to a file that I care about.  The path is relative to
>> you, the script that is running the code" ?
>>
>> Long form:
>>
>> I have a file, testing_utils.rkt, that includes the following snippet of 
>> code:
>>
>> (define (load-initial-data where)
>>   (define cmd (string-append "psql -d biomantica < "
>>  (path->string
>>   (path-only
>>(path->complete-path
>> (find-system-path 'run-file
>>  where))
>>   (say "shelling out in order to load initial data into DB. Command
>> is: \n\t" cmd)
>>
>>   (void
>>(with-output-to-string  ;; silence the output
>>  (thunk
>>   (system cmd)
>>
>>
>> The way this gets used is that one of our test scripts (e.g.
>> 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
>> call the load-initial-data function as follows:
>>
>> (load-initial-data "../initial_test_data.sql")
>>
>> I operate in Emacs via the shell, while my cofounder James uses Dr
>> Racket.  The above sequence works for me but not for him.  When I run
>> endpoints.t it locates the endpoints.t file, generates the path from
>> there to the initial_test_data.sql file, and shells out to run that
>> SQL through psql in order to load the database for testing.  When
>> James tries it it fails.
>>
>> The failure seems to be that for me "the running script" is the
>> endpoints.t file, while for him it's the Dr Racket executable.  I'm
>> not sure where to even begin sorting this out, so I was hoping for
>> some help.
>>
>> Any thoughts?
>>
>> Dave
>>
>>
>> PS:  James had to step out for something else or he would be sending
>> this himself.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Robby Findler
define-runtime-path is designed for this problem, IIUC. Let me know if
the docs don't help.

Robby

On Thu, Jan 19, 2017 at 11:47 AM, David Storrs  wrote:
> Short form:  When using Dr Racket, how do I write something that says
> "Here is a path to a file that I care about.  The path is relative to
> you, the script that is running the code" ?
>
> Long form:
>
> I have a file, testing_utils.rkt, that includes the following snippet of code:
>
> (define (load-initial-data where)
>   (define cmd (string-append "psql -d biomantica < "
>  (path->string
>   (path-only
>(path->complete-path
> (find-system-path 'run-file
>  where))
>   (say "shelling out in order to load initial data into DB. Command
> is: \n\t" cmd)
>
>   (void
>(with-output-to-string  ;; silence the output
>  (thunk
>   (system cmd)
>
>
> The way this gets used is that one of our test scripts (e.g.
> 'endpoints.t') will (require "path/to/testing_utils.rkt") and then
> call the load-initial-data function as follows:
>
> (load-initial-data "../initial_test_data.sql")
>
> I operate in Emacs via the shell, while my cofounder James uses Dr
> Racket.  The above sequence works for me but not for him.  When I run
> endpoints.t it locates the endpoints.t file, generates the path from
> there to the initial_test_data.sql file, and shells out to run that
> SQL through psql in order to load the database for testing.  When
> James tries it it fails.
>
> The failure seems to be that for me "the running script" is the
> endpoints.t file, while for him it's the Dr Racket executable.  I'm
> not sure where to even begin sorting this out, so I was hoping for
> some help.
>
> Any thoughts?
>
> Dave
>
>
> PS:  James had to step out for something else or he would be sending
> this himself.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.