-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporate Python files formerly in separate repo
- Loading branch information
1 parent
20ebc22
commit 273eed2
Showing
89 changed files
with
2,888 additions
and
1,569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ ptghci-engine.cabal | |
tags | ||
log.txt | ||
ptghci_log.txt | ||
BUGS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Changelog for ptghci-engine | ||
# Changelog for ptghci | ||
|
||
## Unreleased changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,51 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Main where | ||
|
||
import Language.Haskell.PtGhci.Prelude | ||
import Language.Haskell.PtGhci.App | ||
import Language.Haskell.PtGhci.Engine | ||
import Language.Haskell.PtGhci.StartPy | ||
import Foreign.C.Types | ||
import System.IO (hFlush) | ||
import System.Environment | ||
import System.FilePath | ||
import System.Process | ||
-- import Paths_ptghci_engine | ||
|
||
-- foreign import ccall "run_python_interpreter" runPythonIntepreter :: IO CInt | ||
|
||
main = runApp | ||
-- do | ||
-- dataDir <- getDataDir | ||
-- putStrLn dataDir | ||
-- pythonPath <- lookupEnv "PYTHONPATH" | ||
-- let pythonBase = dataDir </> "pybits" | ||
-- pyMain = pythonBase </> "main.py" | ||
-- case pythonPath of | ||
-- Nothing -> setEnv "PYTHONPATH" pythonBase | ||
-- Just path -> setEnv "PYTHONPATH" (path ++ ":" ++ pythonBase) | ||
-- -- runPythonIntepreter | ||
-- createProcess (proc "python3" [pyMain]) { | ||
-- cwd = Nothing, | ||
-- env = Nothing, | ||
-- std_in = Inherit, | ||
-- std_out = Inherit, | ||
-- close_fds = False, | ||
-- create_group = False, | ||
-- delegate_ctlc = True } | ||
-- forever (return ()) | ||
|
||
main :: IO () | ||
main = do | ||
sockets <- setupSockets | ||
|
||
-- Check if we are running in "engine mode" -- if so we should not start the | ||
-- Python interpreter, but should print the ZeroMQ sockets we are using to | ||
-- stdout | ||
lookupEnv "PTGHCI_ENGINE_MODE" >>= \case | ||
Just _ -> runEngineMode sockets | ||
Nothing -> runPythonInProc sockets | ||
|
||
|
||
-- | The normal way we run -- Python interpreter runs prompt-toolkit loop | ||
-- in-process. | ||
runPythonInProc :: Sockets -> IO () | ||
runPythonInProc sockets = do | ||
sockAddrs <- socketEndpoints sockets | ||
|
||
(appThread, quitApp) <- runApp sockets | ||
withAsync (startPythonApp sockAddrs) $ \pyThread -> do | ||
res <- waitEither pyThread appThread | ||
case res of | ||
Left () -> quitApp | ||
Right () -> return () | ||
|
||
-- | Don't run the Python intepreter; just start the engine and listen for a | ||
-- connection from an external Python process. Used for testing. In the | ||
-- future may be used for Jupyter notebook connections. | ||
runEngineMode :: Sockets -> IO () | ||
runEngineMode sockets = do | ||
sockAddrs <- socketEndpoints sockets | ||
|
||
-- Print the socket addresses so Python knows how to connect | ||
print sockAddrs >> hFlush stdout | ||
|
||
(appThread, quitApp) <- runApp sockets | ||
wait appThread `finally` quitApp | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.