forked from pinterface/burgled-batteries
-
Notifications
You must be signed in to change notification settings - Fork 1
/
grovel-include-dir.lisp
28 lines (24 loc) · 1.18 KB
/
grovel-include-dir.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(in-package #:cpython)
(defun read-path ()
(format *query-io* "Enter directory containing Python's C header files: ")
(cl:list (read-line *query-io*)))
(defun query-error (format-string &rest args)
(restart-case (apply #'error format-string args)
(use-value (v)
:report "Specify directory containing CPython's header files"
:interactive read-path
v)))
(defun query-user-for-include-dir ()
(loop :for path := (query-error "Unable to determine Python include directory.")
:then (query-error "Path ~s does not appear to exist." path)
:when (cl-fad:directory-exists-p path) :return it))
(defparameter *cpython-include-dir*
(or (loop :for minor :from 7 :downto 4
:when (or (cl-fad:directory-exists-p (format nil "/usr/include/python2.~d" minor))
(cl-fad:directory-exists-p (format nil "/usr/local/include/python2.~d" minor)))
:return it)
;; This allows us to avoid querying the user during a recompile, while
;; still allowing for a change in Python version
(when (boundp '*cpython-include-dir*)
(cl-fad:directory-exists-p *cpython-include-dir*))
(query-user-for-include-dir)))