CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-jupyter-core

Core foundational package providing base application classes, path utilities, and configuration management for the Jupyter ecosystem.

Pending
Overview
Eval results
Files

command-line-tools.mddocs/

Command-Line Tools

Command-line utilities for Jupyter ecosystem management including the main jupyter command dispatcher, IPython-to-Jupyter migration tools, and system troubleshooting utilities. These tools provide essential functionality for system administration and user support.

Capabilities

Main Jupyter Command

The primary jupyter command that serves as a dispatcher to subcommands and provides system information.

def main() -> None:
    """The command entry point for the 'jupyter' command.
    
    Handles subcommand dispatching, path information display,
    version information, and help functionality.
    """

def jupyter_parser() -> JupyterParser:
    """Create a jupyter argument parser.
    
    Returns:
        JupyterParser: Configured argument parser for jupyter command
    """

def list_subcommands() -> list[str]:
    """List all jupyter subcommands.
    
    Searches PATH for `jupyter-name` executables and returns 
    subcommand names without the `jupyter-` prefix.
    
    Returns:
        list[str]: Available subcommand names
    """

Usage Example:

from jupyter_core.command import list_subcommands, main

# List available subcommands
subcommands = list_subcommands()
print("Available subcommands:", subcommands)

# The main() function is typically called from command line:
# $ jupyter --version
# $ jupyter --paths
# $ jupyter notebook

The jupyter command supports several built-in options:

  • --version: Show versions of core Jupyter packages
  • --paths: Show all Jupyter paths (config, data, runtime)
  • --config-dir: Show Jupyter config directory
  • --data-dir: Show Jupyter data directory
  • --runtime-dir: Show Jupyter runtime directory
  • --json: Output paths as JSON (with --paths)
  • --debug: Show debug information about path resolution (with --paths)

Jupyter Parser Class

Custom argument parser for the jupyter command with auto-completion support.

class JupyterParser(argparse.ArgumentParser):
    """A Jupyter argument parser with auto-completion support."""
    
    @property
    def epilog(self) -> str:
        """Add subcommands to epilog on request.
        
        Avoids searching PATH for subcommands unless help output is requested.
        """
    
    def argcomplete(self) -> None:
        """Trigger auto-completion, if enabled.
        
        Uses argcomplete library if available for bash/zsh completion.
        """

Migration Tools

Tools for migrating IPython < 4.0 configurations and data to Jupyter locations.

def migrate() -> bool:
    """Migrate IPython configuration to Jupyter.
    
    Copies (doesn't move) IPython configuration files, kernels,
    extensions, and other data to appropriate Jupyter locations.
    
    Returns:
        bool: True if any files were migrated
    """

def migrate_dir(src: str, dst: str) -> bool:
    """Migrate a directory from src to dst.
    
    Args:
        src: Source directory path
        dst: Destination directory path
        
    Returns:
        bool: True if directory was migrated
    """

def migrate_file(src: str | Path, dst: str | Path, substitutions=None) -> bool:
    """Migrate a single file from src to dst.
    
    Args:
        src: Source file path
        dst: Destination file path  
        substitutions: Optional dict of {regex: replacement} for text substitution
        
    Returns:
        bool: True if file was migrated
    """

def migrate_one(src: str, dst: str) -> bool:
    """Migrate one item from src to dst.
    
    Generic migration dispatcher that handles both files and directories.
    
    Args:
        src: Source path (file or directory)
        dst: Destination path
        
    Returns:
        bool: True if item was migrated
    """

def migrate_static_custom(src: str, dst: str) -> bool:
    """Migrate non-empty custom.js,css from src to dst.
    
    Handles migration of custom CSS and JavaScript files from
    IPython profile directories to Jupyter custom directories.
    
    Args:
        src: Source directory path
        dst: Destination directory path
        
    Returns:
        bool: True if custom files were migrated
    """

def migrate_config(name: str, env: Any) -> list[Any]:
    """Migrate a config file with text substitutions.
    
    Applies regex substitutions to update IPython class names
    and configuration patterns to Jupyter equivalents.
    
    Args:
        name: Configuration file name
        env: Configuration environment/context
        
    Returns:
        list[Any]: List of migrated configuration objects
    """

def get_ipython_dir() -> str:
    """Return the IPython directory location.
    
    Checks IPYTHONDIR environment variable, defaults to ~/.ipython.
    
    Returns:
        str: Path to IPython directory
    """

Usage Example:

from jupyter_core.migrate import migrate, get_ipython_dir

# Check if IPython directory exists
ipython_dir = get_ipython_dir()
print(f"IPython directory: {ipython_dir}")

# Perform migration
if migrate():
    print("Successfully migrated IPython configuration to Jupyter")
else:
    print("No migration needed")

The migration process handles:

  • Configuration files: ipython_notebook_config.pyjupyter_notebook_config.py
  • Kernels: ~/.ipython/kernels/{jupyter_data_dir}/kernels/
  • Extensions: ~/.ipython/extensions/{jupyter_data_dir}/nbextensions/
  • Custom files: ~/.ipython/profile_default/static/custom/~/.jupyter/custom/
  • Security files: Notebook secrets and signatures
  • Text substitutions: Updates class names (IPythonApp → JupyterApp, etc.)

Migration Application Class

Command-line application for running migrations.

class JupyterMigrate(JupyterApp):
    """A Jupyter Migration App.
    
    Command-line application that migrates IPython < 4.0 configuration
    and data to Jupyter locations.
    """
    
    name: str = "jupyter-migrate"
    description: str  # Multi-line description of migration process
    
    def start(self) -> None:
        """Start the migration process."""

Troubleshooting Tools

System information gathering tools for diagnosing Jupyter installation issues.

def get_data() -> dict[str, Any]:
    """Returns a dict of various user environment data.
    
    Gathers comprehensive system information including:
    - PATH and sys.path
    - Python executable and version
    - Platform information  
    - Jupyter command locations
    - Package lists (pip, conda)
    - Environment exports
    
    Returns:
        dict[str, Any]: Environment data dictionary
    """

def subs(cmd: list[str] | str) -> str | None:
    """Get data from commands that need to run outside of Python.
    
    Args:
        cmd: Command to execute (string or list)
        
    Returns:
        str | None: Command output or None if command failed
    """

def main() -> None:
    """Print out comprehensive system information for troubleshooting."""

Usage Example:

from jupyter_core.troubleshoot import get_data, main

# Get structured environment data
env_data = get_data()
print("Python executable:", env_data['sys_exe'])
print("Platform:", env_data['platform'])
print("Jupyter locations:", env_data.get('which'))

# Or run the full troubleshooting report
main()  # Prints comprehensive system information

The troubleshooting output includes:

  • $PATH: All directories in system PATH
  • sys.path: Python module search paths
  • sys.executable: Python interpreter location
  • sys.version: Python version information
  • platform.platform(): System platform details
  • which/where jupyter: Jupyter command locations
  • pip list: Installed Python packages
  • conda list: Conda package information (if available)
  • conda env export: Full conda environment (if available)

Command Execution Utilities

Internal utilities for cross-platform command execution and subcommand discovery.

def _jupyter_abspath(subcommand: str) -> str:
    """Get the absolute path of a specified jupyter subcommand.
    
    Args:
        subcommand: Name of subcommand (without 'jupyter-' prefix)
        
    Returns:
        str: Absolute path to subcommand executable
        
    Raises:
        Exception: If subcommand not found or not executable
    """

def _path_with_self() -> list[str]:
    """Put jupyter's directory at the front of PATH.
    
    Ensures that /path/to/jupyter subcommand will find 
    /path/to/jupyter-subcommand even if other versions 
    are ahead on PATH.
    
    Returns:
        list[str]: Modified PATH directories
    """

def _execvp(cmd: str, argv: list[str]) -> None:
    """Cross-platform execvp that handles Windows properly.
    
    Python's execvp has problematic behavior on Windows,
    so this uses Popen on Windows and execvp on Unix.
    
    Args:
        cmd: Command to execute
        argv: Command arguments
    """

Command-Line Entry Points

Based on the package configuration, these commands are available after installation:

jupyter

Main command dispatcher (jupyter_core.command:main)

# Show version information
jupyter --version

# Show all Jupyter paths
jupyter --paths

# Show specific directories  
jupyter --config-dir
jupyter --data-dir
jupyter --runtime-dir

# Show paths as JSON
jupyter --paths --json

# Debug path resolution
jupyter --paths --debug

# Run subcommands
jupyter notebook
jupyter lab
jupyter console

jupyter-migrate

IPython migration tool (jupyter_core.migrate:main)

# Migrate IPython configuration to Jupyter
jupyter-migrate

# The command is idempotent - safe to run multiple times
# Creates a marker file to avoid duplicate migrations

jupyter-troubleshoot

System troubleshooting tool (jupyter_core.troubleshoot:main)

# Display comprehensive system information
jupyter-troubleshoot

# Output includes PATH, Python info, package lists, etc.
# Useful for diagnosing installation and configuration issues

Subcommand Discovery

The jupyter command automatically discovers subcommands by searching PATH for executables matching the pattern jupyter-*. This allows any package to provide Jupyter subcommands by installing appropriately named executables.

Subcommand Resolution Order:

  1. Check if first argument matches a subcommand name
  2. Search PATH for jupyter-{subcommand} executable
  3. Verify executable permissions
  4. Execute with remaining arguments

Example Subcommands:

  • jupyter-notebookjupyter notebook
  • jupyter-labjupyter lab
  • jupyter-consolejupyter console
  • jupyter-kernelspecjupyter kernelspec

This design enables a distributed ecosystem where different packages can contribute functionality to the unified jupyter command interface.

Install with Tessl CLI

npx tessl i tessl/pypi-jupyter-core

docs

application-framework.md

command-line-tools.md

index.md

path-management.md

utility-functions.md

tile.json