CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyccel

Python-to-Fortran/C transpiler for scientific high-performance computing that automatically converts Python code into optimized low-level code.

Pending
Overview
Eval results
Files

command-line.mddocs/

Command-Line Tools

Console commands for transpiling Python files and managing Pyccel projects from the command line, supporting batch processing and integration with build systems.

Capabilities

Main Transpilation Command

The primary command-line interface for transpiling Python files to optimized compiled code.

pyccel filename.py [options]

Positional Arguments

filename.py         # Path to Python file to transpile

Basic Options

-h, --help          # Show help message and exit
-V, --version       # Show version and exit
-v, --verbose       # Increase verbosity (use -v, -vv, -vvv)
--time-execution    # Print time spent in each execution section
--developer-mode    # Enable developer error mode

Compilation Stages

-x, --syntax-only    # Stop after syntactic parsing
-e, --semantic-only  # Stop after semantic analysis  
-t, --convert-only   # Stop after translation, before build

Backend Selection

--language {fortran,c,python}    # Target language (default: fortran)

Compiler Configuration

--compiler-family {GNU,intel,PGI,nvidia,LLVM}  # Compiler family (default: GNU)
--compiler-config CONFIG.json                  # Load compiler config from JSON file

Additional Compiler Options

--flags FLAGS                    # Additional compiler flags
--wrapper-flags FLAGS            # Additional wrapper compiler flags
--debug / --no-debug            # Compile with debug flags
--include DIR [DIR ...]         # Additional include directories
--libdir DIR [DIR ...]          # Additional library directories  
--libs LIB [LIB ...]           # Additional libraries to link
--output DIR                    # Output folder (default: input file's folder)

Accelerator Options

--mpi              # Enable MPI support
--openmp           # Enable OpenMP support

Other Options

--conda-warnings {off,basic,verbose}  # Conda warning level (default: basic)

Usage examples:

# Basic transpilation to Fortran
pyccel my_script.py

# Transpile to C with debug mode
pyccel my_script.py --language c --debug

# Transpile with OpenMP support
pyccel compute.py --openmp --verbose

# Transpile with custom compiler and flags
pyccel simulation.py --compiler-family intel --flags "-O3 -march=native"

# Stop after semantic analysis for debugging
pyccel test.py --semantic-only --developer-mode

# Transpile with MPI and custom output directory
pyccel parallel_code.py --mpi --output ./build --verbose

Project Cleanup Command

Removes generated Pyccel files and build artifacts from the current directory or specified paths.

pyccel-clean [options]

Usage examples:

# Clean current directory
pyccel-clean

# Clean with verbose output
pyccel-clean --verbose

Testing Command

Runs Pyccel's test suite or tests specific Python files for transpilation compatibility.

pyccel-test [options] [files...]

Test Options

--language {fortran,c,python}     # Test with specific target language
--mpi                             # Test with MPI support
--openmp                          # Test with OpenMP support
--verbose                         # Verbose test output

Usage examples:

# Run all tests
pyccel-test

# Test specific files
pyccel-test my_module.py another_file.py

# Test with Fortran backend and MPI
pyccel-test --language fortran --mpi test_parallel.py

# Run tests with verbose output
pyccel-test --verbose

Command Implementation Functions

Console Command Function

from pyccel.commands.console import pyccel

def pyccel():
    """
    Main Pyccel console command function.
    
    Parses command-line arguments and executes the transpilation pipeline
    with the specified options. Handles all stages from syntax parsing
    through compilation and executable generation.
    """

Cleanup Command Function

from pyccel.commands.pyccel_clean import pyccel_clean_command

def pyccel_clean_command():
    """
    Clean generated Pyccel files command function.
    
    Removes __epyccel__ directories, compiled extensions, and other
    build artifacts created during transpilation process.
    """

Test Command Function

from pyccel.commands.pyccel_test import pyccel_test_command

def pyccel_test_command():
    """
    Pyccel test execution command function.
    
    Runs transpilation tests on specified files or the full test suite,
    validating correct behavior across different backends and options.
    """

Custom Argument Parser

import argparse
from pyccel.commands.console import MyParser

class MyParser(argparse.ArgumentParser):
    """
    Custom argument parser that displays help on error.
    
    Extends ArgumentParser to automatically show help message
    when invalid arguments are provided.
    """
    
    def error(self, message):
        """Display error message and help, then exit."""

Environment Variables

PYCCEL_DEBUG_MODE        # Default debug mode (True/False)
PYCCEL_ERROR_MODE        # Error reporting mode (user/developer)
PYTEST_XDIST_WORKER      # Parallel test worker ID (used internally)

Configuration Files

Compiler Configuration JSON

{
  "family": "GNU",
  "fortran": {
    "compiler": "gfortran", 
    "flags": ["-O3", "-fPIC"],
    "libs": ["gfortran"]
  },
  "c": {
    "compiler": "gcc",
    "flags": ["-O3", "-fPIC"], 
    "libs": ["m"]
  }
}

Output Files

Generated Files Structure

original_file.py                    # Original Python file
__epyccel__/                       # Build directory
├── mod_<random>.py               # Generated Python module
├── mod_<random>.f90              # Generated Fortran code  
├── mod_<random>.so               # Compiled shared library
└── mod_<random>.lock            # File lock for parallel builds

Executable Generation

When the input file contains if __name__ == '__main__':, Pyccel generates:

filename                          # Executable binary (Unix)
filename.exe                      # Executable binary (Windows)

Install with Tessl CLI

npx tessl i tessl/pypi-pyccel

docs

command-line.md

decorators.md

embedded-acceleration.md

index.md

type-system.md

tile.json