CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-julia

Julia/Python bridge with IPython support enabling seamless interoperability between Python and Julia programming languages.

Pending
Overview
Eval results
Files

development-tools.mddocs/

Development Tools and Utilities

Utilities for PyCall.jl installation, system image building, testing infrastructure, and development workflow support including PyCall rebuild and Julia executable management for PyJulia development and deployment.

Capabilities

PyCall.jl Installation and Management

Install, configure, and rebuild PyCall.jl package for PyJulia operation.

def install(julia="julia", color="auto", python=None, quiet=False):
    """
    Install/configure Julia packages required by PyJulia.
    
    Parameters:
    - julia: Path to Julia executable (default: "julia")
    - color: Color output setting ("auto"/"yes"/"no")  
    - python: Python executable path (default: current Python)
    - quiet: Suppress output if True
    
    Raises:
    - PyCallInstallError: If PyCall.jl installation fails
    """

def build_pycall(julia="julia", python=sys.executable, **kwargs):
    """
    Force rebuild PyCall.jl package.
    
    Parameters:
    - julia: Path to Julia executable
    - python: Python executable to configure PyCall for
    - **kwargs: Additional build options
    """

class PyCallInstallError(Exception):
    """Raised when PyCall.jl installation or configuration fails."""

System Image Building

Build custom Julia system images for faster PyJulia startup and deployment.

def build_sysimage(output, julia="julia", script=None, debug=False, 
                   compiler_env="", base_sysimage=None):
    """
    Build Julia system image for faster startup.
    
    Parameters:
    - output: Output path for system image file
    - julia: Path to Julia executable
    - script: Julia script to precompile into sysimage
    - debug: Enable debug output
    - compiler_env: Environment for PackageCompiler.jl
    - base_sysimage: Base system image to build upon
    
    Raises:
    - KnownError: Expected errors during system image building
    """

class KnownError(Exception):
    """Expected errors that can occur during system image building."""

def script_path(name: str) -> str:
    """
    Get path to bundled Julia script.
    
    Parameters:
    - name: Script name
    
    Returns:
    - Absolute path to script file
    """

def install_packagecompiler_cmd(julia: str, compiler_env: str) -> list:
    """Get PackageCompiler.jl install command."""

def build_sysimage_cmd(julia_py: str, julia: str, compile_args: list) -> list:
    """Get system image build command."""

Testing Infrastructure

PyTest integration and testing utilities for PyJulia development.

def pytest_addoption(parser):
    """Add PyJulia-specific pytest command line options."""

def pytest_sessionstart(session):
    """pytest session startup hook."""

def pytest_configure(config):
    """pytest configuration hook."""

def pytest_runtest_setup(item):
    """pytest test setup hook."""

# Testing fixtures
def julia():
    """Julia runtime fixture for testing."""

def juliainfo():
    """JuliaInfo fixture for testing."""

Test Execution and Validation

Run PyJulia test suite and validate dependencies.

def check_test_dependencies():
    """
    Verify that required test dependencies are available.
    
    Raises:
    - ApplicationError: If required dependencies are missing
    """

def runtests(pytest_args: list, dry_run: bool = False):
    """
    Run PyJulia test suite with pytest.
    
    Parameters:
    - pytest_args: Arguments to pass to pytest
    - dry_run: Show what would be run without executing
    """

class ApplicationError(Exception):
    """Application-level errors during test execution."""

Development Workflow Utilities

Tools for managing development workflows including conditional rebuilds and signal handling.

def maybe_rebuild(rebuild: bool, julia: str = "julia"):
    """
    Context manager for conditional PyCall.jl rebuild.
    
    Parameters:
    - rebuild: Whether to rebuild PyCall.jl
    - julia: Path to Julia executable
    """

def with_rebuilt(rebuild: bool, julia: str, command: list):
    """
    Execute command with optional PyCall rebuild.
    
    Parameters:
    - rebuild: Whether to rebuild before execution
    - julia: Path to Julia executable  
    - command: Command to execute
    """

def ignoring(sig):
    """
    Context manager for ignoring system signals.
    
    Parameters:
    - sig: Signal to ignore during execution
    """

Output Stream Management

Redirect Julia output streams to Python for integrated logging and display.

def redirect_output_streams():
    """Redirect Julia stdout/stderr streams to Python."""

def make_receiver(io):
    """
    Create output stream receiver function for stream redirection.
    
    Parameters:
    - io: Python IO object to receive redirected output
    
    Returns:
    - Receiver function for Julia output
    """

Julia Executable Discovery

Find and validate Julia executable paths and configurations.

def julia_py_executable() -> str:
    """
    Get path to julia-py executable script.
    
    Returns:
    - Absolute path to julia-py script
    """

Temporary Directory Management

Utilities for creating and managing temporary directories during builds.

def temporarydirectory(**kwargs):
    """
    Context manager for temporary directory creation.
    
    Parameters:
    - **kwargs: Arguments passed to tempfile.TemporaryDirectory
    
    Returns:
    - Context manager yielding temporary directory path
    """

def check_call(cmd: list, **kwargs):
    """
    Execute command with detailed logging.
    
    Parameters:
    - cmd: Command and arguments as list
    - **kwargs: Additional subprocess arguments
    """

Usage Examples

PyCall.jl Installation

from julia import install
from julia.tools import PyCallInstallError

try:
    # Basic installation
    install()
    
    # Install with specific Julia executable
    install(julia="/usr/local/bin/julia")
    
    # Quiet installation
    install(quiet=True)
    
    # Install for specific Python version
    install(python="/usr/bin/python3.9")
    
except PyCallInstallError as e:
    print(f"PyCall installation failed: {e}")

System Image Building

from julia.sysimage import build_sysimage, KnownError

try:
    # Build basic system image
    build_sysimage("my_sysimage.so")
    
    # Build with custom precompilation script
    build_sysimage(
        output="optimized.so", 
        script="precompile_script.jl",
        debug=True
    )
    
    # Build with specific Julia version
    build_sysimage(
        output="custom.so",
        julia="/path/to/julia",
        compiler_env="JULIA_PKG_DEVDIR=/dev/packages"
    )
    
except KnownError as e:
    print(f"Expected error during build: {e}")

Testing Setup

from julia.runtests import runtests, check_test_dependencies
from julia.runtests import ApplicationError

try:
    # Check test dependencies
    check_test_dependencies()
    
    # Run all tests
    runtests([])
    
    # Run specific test with verbose output
    runtests(["-v", "test_core.py"])
    
    # Dry run to see what tests would run
    runtests(["--collect-only"], dry_run=True)
    
except ApplicationError as e:
    print(f"Test execution failed: {e}")

Development Workflow

from julia.with_rebuilt import maybe_rebuild, with_rebuilt

# Conditional rebuild context
with maybe_rebuild(rebuild=True):
    # Code that may need fresh PyCall build
    from julia import Julia
    jl = Julia()
    jl.eval("println(\"Hello after rebuild!\")")

# Execute command with rebuild
with_rebuilt(
    rebuild=True, 
    julia="/usr/local/bin/julia",
    command=["python", "my_script.py"]
)

Output Stream Redirection

from julia.tools import redirect_output_streams, make_receiver
import sys

# Redirect Julia output to Python
redirect_output_streams()

# Create custom receiver for Julia output
receiver = make_receiver(sys.stdout)

# Now Julia output appears in Python stdout
from julia import Julia
jl = Julia()
jl.eval('println("This will appear in Python output")')

Custom System Image Scripts

from julia.sysimage import script_path, build_sysimage

# Get path to bundled precompilation script
precompile_script = script_path("precompile_common.jl")

# Build system image with bundled script
build_sysimage(
    output="precompiled.so",
    script=precompile_script,
    debug=True
)

Testing with Fixtures

# In a pytest test file
import pytest
from julia.pytestplugin import julia, juliainfo

def test_julia_functionality(julia):
    """Test using Julia fixture."""
    result = julia.eval("2 + 3")
    assert result == 5

def test_julia_info(juliainfo):
    """Test using JuliaInfo fixture."""
    assert juliainfo.version is not None
    assert juliainfo.executable is not None

Signal Handling During Operations

from julia.with_rebuilt import ignoring
import signal

# Ignore SIGINT during critical operation
with ignoring(signal.SIGINT):
    # Long-running operation that shouldn't be interrupted
    from julia.sysimage import build_sysimage
    build_sysimage("critical.so")

Command Line Interface Integration

# Main function for command-line tools
from julia.sysimage import main as sysimage_main
from julia.runtests import main as test_main
from julia.with_rebuilt import main as rebuilt_main

# These can be called from command line or programmatically
if __name__ == "__main__":
    import sys
    
    # Build system image from command line
    sysimage_main(sys.argv[1:])
    
    # Run tests from command line  
    test_main(sys.argv[1:])
    
    # Execute with rebuild from command line
    rebuilt_main(sys.argv[1:])

Error Handling

Development tools provide specific exceptions for different failure modes:

from julia.tools import PyCallInstallError
from julia.sysimage import KnownError
from julia.runtests import ApplicationError

try:
    # Various development operations
    install()
    build_sysimage("test.so")
    runtests([])
    
except PyCallInstallError as e:
    print(f"PyCall installation issue: {e}")
except KnownError as e:
    print(f"Expected build error: {e}")
except ApplicationError as e:
    print(f"Application error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Install with Tessl CLI

npx tessl i tessl/pypi-julia

docs

console-scripts.md

core-runtime.md

development-tools.md

index.md

ipython-integration.md

low-level-api.md

tile.json