Skip to content

Commit

Permalink
Removed dependency on package being named "python".
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 21, 2014
1 parent b924b74 commit 038fa4d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion info.rkt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#lang info
(define collection "python")
(define compile-omit-paths (list "examples"))
(define compile-omit-paths (list "examples" "test"))
7 changes: 3 additions & 4 deletions libpython.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(require ffi/unsafe
ffi/unsafe/define
ffi/unsafe/alloc
"paths.rkt"
(for-syntax racket/syntax))

(provide (except-out (all-defined-out)
Expand All @@ -26,10 +27,8 @@
(define path-to-others-lib
(and path-to-cpython-lib
(let ([file-suffix (number->string (system-type 'word))]
[file-ext (case (system-type 'os)
[(windows) ".dll"]
[(unix macosx) ".so"])])
(collection-file-path (build-path "c" (string-append "others" file-suffix file-ext)) "python"))))
[file-ext (bytes->string/locale (system-type 'so-suffix))])
(simplify-path (build-path python-root "c" (string-append "others" file-suffix file-ext))))))

(define-ffi-definer define-function (ffi-lib path-to-cpython-lib)
#:default-make-fail void-if-not-available)
Expand Down
9 changes: 9 additions & 0 deletions paths.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#lang racket
(provide (except-out (all-defined-out) paths.rkt))

(require racket/runtime-path)
(define-runtime-path paths.rkt "paths.rkt")
(define python-root (simplify-path (build-path paths.rkt 'up)))

(define path-to-lib (simplify-path (build-path python-root "lib")))
(define path-to-PATH (simplify-path (build-path path-to-lib "PATH")))
12 changes: 6 additions & 6 deletions runtime.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,13 @@
(provide (all-from-out "name-mangling.rkt"))


(require "paths.rkt")
(require (for-syntax "paths.rkt"))

(define PATH
(let* ([path-to-PATH (collection-file-path (build-path "lib" "PATH") "python")]
[file (open-input-file path-to-PATH)])
(let* ([file (open-input-file path-to-PATH)])
(list->py-list
(append (list "." (path->string (collection-file-path (build-path "lib") "python")))
(append (list "." path-to-lib)
(map string-trim
(port->list read-line file))))))

Expand All @@ -628,9 +629,8 @@
(require (for-syntax racket/port
racket/string))
(define-for-syntax (module-name->module-path/compile-time name)
(let* ([path-to-PATH (collection-file-path (build-path "lib" "PATH") "python")]
[file (open-input-file path-to-PATH)])
(let loop ([dirs (append (list "." (path->string (collection-file-path (build-path "lib") "python")))
(let* ([file (open-input-file path-to-PATH)])
(let loop ([dirs (append (list "." path-to-lib)
(map string-trim (port->list read-line file)))])
(if (empty? dirs)
(raise-syntax-error 'ImportError (format "No module named ~a" name))
Expand Down

0 comments on commit 038fa4d

Please sign in to comment.