Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
10002807
Commit
10002807
authored
Oct 28, 2013
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using `ipython locate` to find ipython profile directory.
parent
722c46f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
36 deletions
+25
-36
IPython.hs
IHaskell/IPython.hs
+25
-36
No files found.
IHaskell/IPython.hs
View file @
10002807
...
@@ -6,11 +6,11 @@ module IHaskell.IPython (
...
@@ -6,11 +6,11 @@ module IHaskell.IPython (
import
ClassyPrelude
import
ClassyPrelude
import
Shelly
hiding
(
find
,
trace
)
import
Shelly
hiding
(
find
,
trace
)
import
Text.Printf
import
System.Argv0
import
System.Argv0
import
System.Directory
import
System.Directory
import
qualified
Filesystem.Path.CurrentOS
as
FS
import
qualified
Filesystem.Path.CurrentOS
as
FS
import
Data.List.Utils
(
split
)
import
Data.List.Utils
(
split
)
import
Data.String.Utils
(
rstrip
)
import
Prelude
(
read
)
import
Prelude
(
read
)
import
qualified
System.IO.Strict
as
StrictIO
import
qualified
System.IO.Strict
as
StrictIO
...
@@ -18,61 +18,47 @@ import qualified System.IO.Strict as StrictIO
...
@@ -18,61 +18,47 @@ import qualified System.IO.Strict as StrictIO
import
qualified
IHaskell.Config
as
Config
import
qualified
IHaskell.Config
as
Config
-- | Run IPython with any arguments.
-- | Run IPython with any arguments.
ipython
::
[
Text
]
->
Sh
()
ipython
::
Bool
-- ^ Whether to suppress output.
ipython
args
=
do
->
[
Text
]
-- ^ IPython command line arguments.
->
Sh
String
-- ^ IPython output.
ipython
suppress
args
=
do
path
<-
which
"ipython"
path
<-
which
"ipython"
case
path
of
case
path
of
Nothing
->
putStrLn
"Could not find `ipython` executable."
Nothing
->
do
Just
ipythonPath
->
runHandles
ipythonPath
args
inheritHandles
doNothing
putStrLn
"Could not find `ipython` executable."
where
inheritHandles
=
[
InHandle
Inherit
,
OutHandle
Inherit
,
ErrorHandle
Inherit
]
fail
"`ipython` not on $PATH."
doNothing
_
_
_
=
return
()
Just
ipythonPath
->
runHandles
ipythonPath
args
handles
doNothing
where
handles
=
[
InHandle
Inherit
,
outHandle
suppress
,
ErrorHandle
Inherit
]
outHandle
True
=
OutHandle
CreatePipe
outHandle
False
=
OutHandle
Inherit
doNothing
_
stdout
_
=
if
suppress
then
liftIO
$
StrictIO
.
hGetContents
stdout
else
return
""
-- | Use the `ipython --version` command to figure out the version.
-- | Use the `ipython --version` command to figure out the version.
-- Return a tuple with (major, minor, patch).
-- Return a tuple with (major, minor, patch).
ipythonVersion
::
IO
(
Int
,
Int
,
Int
)
ipythonVersion
::
IO
(
Int
,
Int
,
Int
)
ipythonVersion
=
shelly
$
do
ipythonVersion
=
shelly
$
do
path
<-
which
"ipython"
[
major
,
minor
,
patch
]
<-
map
read
<$>
split
"."
<$>
ipython
True
[
"--version"
]
case
path
of
return
(
major
,
minor
,
patch
)
Nothing
->
error
"Could not find `ipython` executable."
Just
path
->
do
[
major
,
minor
,
patch
]
<-
map
read
<$>
split
"."
<$>
runHandle
path
[
"--version"
]
(
liftIO
.
StrictIO
.
hGetContents
)
::
Sh
[
Int
]
return
(
major
,
minor
,
patch
)
-- | Run an IHaskell application using the given profile.
-- | Run an IHaskell application using the given profile.
runIHaskell
::
String
-- ^ IHaskell profile name.
runIHaskell
::
String
-- ^ IHaskell profile name.
->
String
-- ^ IPython app name.
->
String
-- ^ IPython app name.
->
[
String
]
-- ^ Arguments to IPython.
->
[
String
]
-- ^ Arguments to IPython.
->
IO
()
->
IO
()
runIHaskell
profile
app
args
=
shelly
.
ipython
$
[
pack
app
,
"--profile"
,
pack
profile
]
++
map
pack
args
runIHaskell
profile
app
args
=
void
.
shelly
.
ipython
False
$
[
pack
app
,
"--profile"
,
pack
profile
]
++
map
pack
args
-- | Create the IPython profile.
-- | Create the IPython profile.
setupIPythonProfile
::
String
-- ^ IHaskell profile name.
setupIPythonProfile
::
String
-- ^ IHaskell profile name.
->
IO
()
->
IO
()
setupIPythonProfile
profile
=
shelly
$
do
setupIPythonProfile
profile
=
shelly
$
do
-- Create the IPython profile.
-- Create the IPython profile.
ipython
[
"profile"
,
"create"
,
pack
profile
]
void
$
ipython
False
[
"profile"
,
"create"
,
pack
profile
]
-- Find the IPython profile directory.
ipythonDirs
<-
catMaybes
<$>
sequence
[
get_env
"IPYTHON_DIR"
,
get_env
"IPYTHONDIR"
]
ipythonDir
<-
case
ipythonDirs
of
dir
:
_
->
return
dir
[]
->
do
home
<-
get_env
"HOME"
case
home
of
Nothing
->
error
"Could not locate $HOME."
Just
home
->
do
dotIpython
<-
test_d
.
fromText
$
home
++
"/.ipython"
dotConfigIpython
<-
test_d
.
fromText
$
home
++
"/.config/ipython"
when
(
not
dotIpython
&&
not
dotConfigIpython
)
$
do
putStrLn
"Could not find ~/.ipython or ~/.config/ipython."
error
"Could not find IPython directory."
return
$
home
++
(
if
dotIpython
then
"/.ipython"
else
"/.config/ipython"
)
-- Find the IPython profile directory. Make sure to get rid of trailing
-- newlines from the output of the `ipython locate` call.
ipythonDir
<-
pack
<$>
rstrip
<$>
ipython
True
[
"locate"
]
let
profileDir
=
ipythonDir
++
"/profile_"
++
pack
profile
++
"/"
let
profileDir
=
ipythonDir
++
"/profile_"
++
pack
profile
++
"/"
path
<-
getIHaskellPath
path
<-
getIHaskellPath
...
@@ -87,6 +73,9 @@ writeConfigFilesTo profileDir ihaskellPath = do
...
@@ -87,6 +73,9 @@ writeConfigFilesTo profileDir ihaskellPath = do
writeFile
(
conf
"ipython_notebook_config.py"
)
Config
.
notebook
writeFile
(
conf
"ipython_notebook_config.py"
)
Config
.
notebook
writeFile
(
conf
"ipython_console_config.py"
)
Config
.
console
writeFile
(
conf
"ipython_console_config.py"
)
Config
.
console
writeFile
(
conf
"ipython_qtconsole_config.py"
)
Config
.
qtconsole
writeFile
(
conf
"ipython_qtconsole_config.py"
)
Config
.
qtconsole
-- The custom directory many not exist, in which case we'll create it.
mkdir_p
(
conf
"static/custom/"
)
writeFile
(
conf
"static/custom/custom.js"
)
Config
.
customjs
writeFile
(
conf
"static/custom/custom.js"
)
Config
.
customjs
where
where
conf
filename
=
fromText
$
profileDir
++
filename
conf
filename
=
fromText
$
profileDir
++
filename
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment