On Thu, Jan 19, 2017 at 7:10 PM, Philip McGrath
<[email protected]> wrote:
> 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.

That's exactly it, yes.  I hadn't formatted it that way, but you're right.

>
> 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)]))
>
>

Cool, thank you.


> -Philip
>
> On Thu, Jan 19, 2017 at 5:45 PM, Robby Findler <[email protected]>
> 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 <[email protected]>
>> 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 <[email protected]>
>> > 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
>> >> <[email protected]> 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
>> >>> <[email protected]> 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 [email protected].
>> >>>> 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 [email protected].
>> >>> 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 [email protected].
>> > 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 [email protected].
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to