Skip to content

Commit

Permalink
Incorporate Python files formerly in separate repo
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWarfield committed Apr 20, 2019
1 parent 20ebc22 commit 273eed2
Show file tree
Hide file tree
Showing 89 changed files with 2,888 additions and 1,569 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ptghci-engine.cabal
tags
log.txt
ptghci_log.txt
BUGS
56 changes: 0 additions & 56 deletions BUGS

This file was deleted.

2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Changelog for ptghci-engine
# Changelog for ptghci

## Unreleased changes
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright Author name here (c) 2019
Copyright Richard Warfield 2019
Ghcid portions (c) Neil Mitchell 2014-2018

All rights reserved.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ ptghci is an interactive command shell for Haskell designed for high-productivit
## Installation

```
stack install ptghci-engine
pip install ptghci
pip install -r requirements.txt
stack install
```

## Usage
Expand Down
68 changes: 43 additions & 25 deletions app/Main.hs
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

34 changes: 0 additions & 34 deletions cbits/ptghci-shim.c

This file was deleted.

9 changes: 0 additions & 9 deletions cbits/ptghci-shim.h

This file was deleted.

152 changes: 0 additions & 152 deletions ghcid-0.7.1/CHANGES.txt

This file was deleted.

30 changes: 0 additions & 30 deletions ghcid-0.7.1/LICENSE

This file was deleted.

Loading

0 comments on commit 273eed2

Please sign in to comment.