16
16
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
18
18
module CPython
19
- ( initialize
20
- , isInitialized
21
- , finalize
22
- , newInterpreter
23
- , endInterpreter
24
- , getProgramName
25
- , setProgramName
26
- , getPrefix
27
- , getExecPrefix
28
- , getProgramFullPath
29
- , getPath
30
- , getVersion
31
- , getPlatform
32
- , getCopyright
33
- , getCompiler
34
- , getBuildInfo
35
- , setArgv
36
- , getPythonHome
37
- , setPythonHome
38
- ) where
19
+ ( initialize
20
+ , isInitialized
21
+ , finalize
22
+ , newInterpreter
23
+ , endInterpreter
24
+ , getProgramName
25
+ , setProgramName
26
+ , getPrefix
27
+ , getExecPrefix
28
+ , getProgramFullPath
29
+ , getPath
30
+ , getVersion
31
+ , getPlatform
32
+ , getCopyright
33
+ , getCompiler
34
+ , getBuildInfo
35
+ , setArgv
36
+ , getPythonHome
37
+ , setPythonHome
38
+ ) where
39
39
40
40
#include <hscpython-shim.h>
41
41
@@ -54,13 +54,13 @@ import CPython.Internal
54
54
-- first). There is no return value; it is a fatal error if the initialization
55
55
-- fails.
56
56
{# fun Py_Initialize as initialize
57
- {} -> `() ' id # }
57
+ {} -> `() ' id # }
58
58
59
59
-- | Return 'True' when the Python interpreter has been initialized, 'False'
60
60
-- if not. After 'finalize' is called, this returns 'False' until
61
61
-- 'initialize' is called again.
62
62
{# fun Py_IsInitialized as isInitialized
63
- {} -> `Bool' # }
63
+ {} -> `Bool' # }
64
64
65
65
-- | Undo all initializations made by 'initialize' and subsequent use of
66
66
-- Python/C API computations, and destroy all sub-interpreters (see
@@ -89,7 +89,7 @@ import CPython.Internal
89
89
-- initialization routine is called more than once; this can happen if an
90
90
-- application calls 'initialize' and 'finalize' more than once.
91
91
{# fun Py_Finalize as finalize
92
- {} -> `() ' id # }
92
+ {} -> `() ' id # }
93
93
94
94
newtype ThreadState = ThreadState (Ptr ThreadState )
95
95
@@ -147,10 +147,10 @@ newtype ThreadState = ThreadState (Ptr ThreadState)
147
147
-- work). Simple things may work, but confusing behavior will always be near.
148
148
newInterpreter :: IO (Maybe ThreadState )
149
149
newInterpreter = do
150
- ptr <- {# call Py_NewInterpreter as ^ # }
151
- return $ if ptr == nullPtr
152
- then Nothing
153
- else Just $ ThreadState $ castPtr ptr
150
+ ptr <- {# call Py_NewInterpreter as ^ # }
151
+ return $ if ptr == nullPtr
152
+ then Nothing
153
+ else Just $ ThreadState $ castPtr ptr
154
154
155
155
-- | Destroy the (sub-)interpreter represented by the given thread state.
156
156
-- The given thread state must be the current thread state. See the
@@ -162,14 +162,14 @@ newInterpreter = do
162
162
-- explicitly destroyed at that point.
163
163
endInterpreter :: ThreadState -> IO ()
164
164
endInterpreter (ThreadState ptr) =
165
- {# call Py_EndInterpreter as ^ # } $ castPtr ptr
165
+ {# call Py_EndInterpreter as ^ # } $ castPtr ptr
166
166
167
167
-- | Return the program name set with 'setProgramName', or the default.
168
168
getProgramName :: IO Text
169
169
getProgramName = pyGetProgramName >>= peekTextW
170
170
171
171
foreign import ccall safe " hscpython-shim.h Py_GetProgramName"
172
- pyGetProgramName :: IO CWString
172
+ pyGetProgramName :: IO CWString
173
173
174
174
-- | This computation should be called before 'initialize' is called for the
175
175
-- first time, if it is called at all. It tells the interpreter the value of
@@ -182,7 +182,7 @@ setProgramName :: Text -> IO ()
182
182
setProgramName name = withTextW name cSetProgramName
183
183
184
184
foreign import ccall safe " hscpython-shim.h hscpython_SetProgramName"
185
- cSetProgramName :: CWString -> IO ()
185
+ cSetProgramName :: CWString -> IO ()
186
186
187
187
-- | Return the prefix for installed platform-independent files. This is
188
188
-- derived through a number of complicated rules from the program name set
@@ -196,7 +196,7 @@ getPrefix :: IO Text
196
196
getPrefix = pyGetPrefix >>= peekTextW
197
197
198
198
foreign import ccall safe " hscpython-shim.h Py_GetPrefix"
199
- pyGetPrefix :: IO CWString
199
+ pyGetPrefix :: IO CWString
200
200
201
201
-- | Return the /exec-prefix/ for installed platform-/dependent/ files. This
202
202
-- is derived through a number of complicated rules from the program name
@@ -232,7 +232,7 @@ getExecPrefix :: IO Text
232
232
getExecPrefix = pyGetExecPrefix >>= peekTextW
233
233
234
234
foreign import ccall safe " hscpython-shim.h Py_GetExecPrefix"
235
- pyGetExecPrefix :: IO CWString
235
+ pyGetExecPrefix :: IO CWString
236
236
237
237
-- | Return the full program name of the Python executable; this is computed
238
238
-- as a side-effect of deriving the default module search path from the
@@ -242,7 +242,7 @@ getProgramFullPath :: IO Text
242
242
getProgramFullPath = pyGetProgramFullPath >>= peekTextW
243
243
244
244
foreign import ccall safe " hscpython-shim.h Py_GetProgramFullPath"
245
- pyGetProgramFullPath :: IO CWString
245
+ pyGetProgramFullPath :: IO CWString
246
246
247
247
-- | Return the default module search path; this is computed from the
248
248
-- program name (set by 'setProgramName' above) and some environment
@@ -255,7 +255,7 @@ getPath :: IO Text
255
255
getPath = pyGetPath >>= peekTextW
256
256
257
257
foreign import ccall safe " hscpython-shim.h Py_GetPath"
258
- pyGetPath :: IO CWString
258
+ pyGetPath :: IO CWString
259
259
260
260
-- | Return the version of this Python interpreter. This is a string that
261
261
-- looks something like
@@ -269,7 +269,7 @@ foreign import ccall safe "hscpython-shim.h Py_GetPath"
269
269
-- separated by a period. The value is available to Python code as
270
270
-- @sys.version@.
271
271
{# fun Py_GetVersion as getVersion
272
- {} -> `Text' peekText* # }
272
+ {} -> `Text' peekText* # }
273
273
274
274
-- | Return the platform identifier for the current platform. On Unix, this
275
275
-- is formed from the “official” name of the operating system,
@@ -278,7 +278,7 @@ foreign import ccall safe "hscpython-shim.h Py_GetPath"
278
278
-- On Mac OS X, it is @\"darwin\"@. On Windows, it is @\"win\"@. The value
279
279
-- is available to Python code as @sys.platform@.
280
280
{# fun Py_GetPlatform as getPlatform
281
- {} -> `Text' peekText* # }
281
+ {} -> `Text' peekText* # }
282
282
283
283
-- | Return the official copyright string for the current Python version,
284
284
-- for example
@@ -289,7 +289,7 @@ foreign import ccall safe "hscpython-shim.h Py_GetPath"
289
289
--
290
290
-- The value is available to Python code as @sys.copyright@.
291
291
{# fun Py_GetCopyright as getCopyright
292
- {} -> `Text' peekText* # }
292
+ {} -> `Text' peekText* # }
293
293
294
294
-- | Return an indication of the compiler used to build the current Python
295
295
-- version, in square brackets, for example:
@@ -301,7 +301,7 @@ foreign import ccall safe "hscpython-shim.h Py_GetPath"
301
301
-- The value is available to Python code as part of the variable
302
302
-- @sys.version@.
303
303
{# fun Py_GetCompiler as getCompiler
304
- {} -> `Text' peekText* # }
304
+ {} -> `Text' peekText* # }
305
305
306
306
-- | Return information about the sequence number and build date and time of
307
307
-- the current Python interpreter instance, for example
@@ -313,7 +313,7 @@ foreign import ccall safe "hscpython-shim.h Py_GetPath"
313
313
-- The value is available to Python code as part of the variable
314
314
-- @sys.version@.
315
315
{# fun Py_GetBuildInfo as getBuildInfo
316
- {} -> `Text' peekText* # }
316
+ {} -> `Text' peekText* # }
317
317
318
318
-- | Set @sys.argv@. The first parameter is similar to the result of
319
319
-- 'getProgName', with the difference that it should refer to the script
@@ -327,12 +327,12 @@ foreign import ccall safe "hscpython-shim.h Py_GetPath"
327
327
-- or just the interactive interpreter), the empty string is used instead.
328
328
setArgv :: Text -> [Text ] -> IO ()
329
329
setArgv argv0 argv =
330
- mapWith withTextW (argv0 : argv) $ \ textPtrs ->
331
- let argc = fromIntegral $ length textPtrs in
332
- withArray textPtrs $ pySetArgv argc
330
+ mapWith withTextW (argv0 : argv) $ \ textPtrs ->
331
+ let argc = fromIntegral $ length textPtrs in
332
+ withArray textPtrs $ pySetArgv argc
333
333
334
334
foreign import ccall safe " hscpython-shim.h PySys_SetArgv"
335
- pySetArgv :: CInt -> Ptr CWString -> IO ()
335
+ pySetArgv :: CInt -> Ptr CWString -> IO ()
336
336
337
337
-- | Return the default “home”, that is, the value set by a
338
338
-- previous call to 'setPythonHome', or the value of the @PYTHONHOME@
@@ -341,7 +341,7 @@ getPythonHome :: IO (Maybe Text)
341
341
getPythonHome = pyGetPythonHome >>= peekMaybeTextW
342
342
343
343
foreign import ccall safe " hscpython-shim.h Py_GetPythonHome"
344
- pyGetPythonHome :: IO CWString
344
+ pyGetPythonHome :: IO CWString
345
345
346
346
-- | Set the default “home” directory, that is, the location
347
347
-- of the standard Python libraries. The libraries are searched in
@@ -351,4 +351,4 @@ setPythonHome :: Maybe Text -> IO ()
351
351
setPythonHome name = withMaybeTextW name cSetPythonHome
352
352
353
353
foreign import ccall safe " hscpython-shim.h hscpython_SetPythonHome"
354
- cSetPythonHome :: CWString -> IO ()
354
+ cSetPythonHome :: CWString -> IO ()
0 commit comments