Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream1 #5

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright © 2013 by Steven G. Johnson, Fernando Perez, Jeff Bezanson, Stefan Karpinski, Keno Fischer, and other contributors.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2 changes: 1 addition & 1 deletion julia/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .core import Julia, JuliaModule, JuliaError
from .core import Julia
9 changes: 7 additions & 2 deletions julia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ def __init__(self, init_julia=True, jl_init_path=None):
api.jl_init.arg_types = [char_p]

if jl_init_path:
api.jl_init(jl_init_path)
if python_version.major == 3: # we need to translate in non-unicode
sys_ji_path_relative = os.path.join("..", "lib", "julia", "sys.ji")
api.jl_init_with_image(jl_init_path.encode('utf8'), sys_ji_path_relative.encode('utf8'))
else:
api.jl_init(jl_init_path)
else:
api.jl_init(0)
else:
Expand Down Expand Up @@ -367,7 +371,8 @@ def __init__(self, init_julia=True, jl_init_path=None):
try:
self.call('pyinitialize(C_NULL)')
except:
raise JuliaError("Failed to initialize PyCall package")
#raise JuliaError("Failed to initialize PyCall package")
print(" Julia error ? Failed to initialize PyCall package")

# Whether we initialized Julia or not, we MUST create at least one
# instance of PyObject. Since this will be needed on every call, we
Expand Down
74 changes: 74 additions & 0 deletions julia/magic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
==========================
Julia magics for IPython
==========================

{JULIAMAGICS_DOC}

Usage
=====

``%%julia``

{JULIA_DOC}
"""

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------

from __future__ import print_function

import sys

from IPython.core.magic import Magics, magics_class, line_cell_magic

from julia import Julia

#-----------------------------------------------------------------------------
# Main classes
#-----------------------------------------------------------------------------

@magics_class
class JuliaMagics(Magics):
"""A set of magics useful for interactive work with Julia.
"""
def __init__(self, shell):
"""
Parameters
----------
shell : IPython shell

"""

super(JuliaMagics, self).__init__(shell)
print("Initializing Julia interpreter. This may take some time...",
end='')
# Flush, otherwise the Julia startup will keep stdout buffered
sys.stdout.flush()
self.julia = Julia(init_julia=True)
print()

@line_cell_magic
def julia(self, line, cell=None):
"""
Execute code in Julia, and pull some of the results back into the
Python namespace.
"""
src = str(line if cell is None else cell)
return self.julia.eval(src)

# Add to the global docstring the class information.
__doc__ = __doc__.format(
JULIAMAGICS_DOC = ' '*8 + JuliaMagics.__doc__,
JULIA_DOC = ' '*8 + JuliaMagics.julia.__doc__,
)


#-----------------------------------------------------------------------------
# IPython registration entry point.
#-----------------------------------------------------------------------------

def load_ipython_extension(ip):
"""Load the extension in IPython."""
ip.register_magics(JuliaMagics)
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
"""Julia/Python bridge with IPython support.
"""

from distutils.core import setup

setup(name='julia',
version='0.1.1',
description=__doc__,
author='The Julia and IPython development teams.',
author_email='julia@julialang.org',
url='http://julialang.org',
packages=['julia'],
)