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 #<path:/Applications/Racket 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 <[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.

