Documentation

Core classes

class pyswig.pyswig.PySwig(verbose: bool = True, *, parse_cli: bool = True)

Bases: object

The class used to configure the Swig preprocessor

VERSION = '0.1.4'
add_define(name: str, value: str | None = '') None

Adds a define to be included in the generated files

add_file_config(file_config: FileConfig) None

Add a FileConfig object

add_import(import_lib: str) None
add_include(include: str, local: bool = True) None

Add a C/C++ include file to be added

add_include_dir(include_dir: str) None

Add a Swig include search directory (-I).

add_include_lib(include_lib: str) None
add_replace_string(orig: str, new: str) None

Add string to be replace in the wrapper source code gerenated by Swig

add_typemap(type_map: str) None

Add a typemap which should be included in the generated files

do_file_config(file_config: FileConfig) None

Generate the output files related to one given FileConfig

generate() None

Generate all output files

generate_include_file() None

Write the include file included in the wrapper if generated

generate_main_interface_file() None

Write the Swig interface file, the main input file for Swig

get_all_warnings() bool

Get if all warnings are turned on or off

get_copy_shadow_dir() str | None

Get the folder where the shadow class is copied to if any

get_defines() list[list[str | None]]

Get the list of all defines to be included in the generated files

get_file_configs() list[FileConfig]

Return the list of all FileConfig objects

get_imports() list[str] | None
get_inc_output_dir() str | None

Get the output directory for include files

get_include_libs() list[str] | None
get_includes(local: bool = True) list[str]

Get the list of include files to be addded to the generated files

get_language() str | None

Get the language that the wrapper Swig should create

get_module_name() str | None

Get the Swig module name

get_output_cxx_file_path() str
get_output_cxx_filename() str
get_output_file() str | None

Get the outfile for Swig

get_output_file_ext() str | None

get the extension that the generated files input to Swig should have

get_process_cpp() bool

Get if Swig will be processing of C++ is turned on or off

get_replace_strings() list[list[str]]
get_shadow_file() str | None

Get the shadow file name if any is build

get_src_output_dir() str | None

Get the output directory for source file

get_swig() Swig

Get the Swig instance

get_threads_enabled() bool

Get if swig will generate theaded wrapper ot not

get_typemaps() list[str]

Get the list of all typemaps to use

get_use_director() bool

Get if the director feature of Swig should be used or not

get_verbose() bool

Get the verbosity level

get_version() str

Get PySwig version

handle_input_file() None

Resolve CLI input paths without changing the process working directory.

process_param() None

Process the command line parameters.

replace_all_strings() None

Replace all strings in Swig generated wrapper file

replace_strings_in_line(line: str) str
run_swig() int

Run swig on the newly generated files

set_all_warnings(all_warnings: bool = True) None

Turn on or off all warnings

set_copy_shadow_dir(copy_shadow_dir: str) None

Set the folder where the shadow class is copied to if any

set_imports(imports: list[str]) None
set_inc_output_dir(inc_output_dir: str) None

Set the output directory for include files

set_include_libs(include_libs: list[str] | None) None
set_language(language: str) None

Set the language that the wrapper Swig should create

set_module_name(module_name: str) None

Set the Swig module name

set_output_file(output_file: str) None

Set the outfile for Swig

set_output_file_ext(ext: str) None

Set the extension that the generated files input to Swig should have

set_process_cpp(process_cpp: bool = True) None

Turn on of off the processing of C++

set_src_output_dir(src_output_dir: str) None

Set the output directory for source file

set_threads_enabled(are_threads_enabled: bool = True) None

Turn on or off thread support

set_use_director(use_director: bool) None

Set if the director feature of Swig should be used or not

set_verbose(verbose: bool) None

Set the verbosity level

class pyswig.fileconfig.FileConfig

Bases: object

Class holding the information about a set of files with same source and output directory

add_tags(the_file: str | None, tags: list[str] | None) None

Record tags metadata parsed from a source header.

do_swig(enable: bool = True) None

Enable or disable Swig output generation for this file set.

do_tags(enable: bool = True) None

Enable or disable tag extraction for this file set.

get_base_abs_path() str | None
get_base_inc_dir() str | None

Get the folder to be used as the base of all indlude files generated by <swig_inc/>

Returns:

This is set the beginning of the path for header added by <swig_inc/> annotation.

get_output_file_ext(local: bool = True) str | None

get the extension that the generated files input to Swig will have

Parameters:

local – If True, return the local extension; otherwise use the Swig instance value.

Returns:

the extension that the generated files input to Swig will have

get_pyswig() PySwig | None

Get the pySwig instance

get_script_path() str | None

Get the path to the Python script setting up the whole work

Returns:

the path to the Python script setting up the whole work.

get_source_files() list[str | list[Any]] | None

Get the list of source file to process

Returns:

the list of source files to process

get_src_output_dir(local: bool = True) str | None

Get the ouput directory where all generated files will be stored

Parameters:

local – If True, return the local output path; otherwise use the Swig instance path.

Returns:

the ouput directory where all generated files will be stored

save_tags(name: str) None

Write collected tags to a Python list literal file.

set_base_abs_path(base_abs_path: str) None
set_base_inc_dir(base_inc_dir: str) None

Set the folder to be used as the base of all indlude files generated by <swig_inc/>

Parameters:

base_inc_dir – Base path prefix for headers added by the <swig_inc/> annotation.

set_input_dir(input_dir: str) None

Set the base of the input directory, so that source files are relative to it

Parameters:

input_dir – the base of the input directory

set_output_file_ext(ext: str) None

Set the extension that the generated files input to Swig will have

Parameters:

ext – the extension that the generated files input to Swig will have

set_pyswig(pyswig: PySwig) None

Set the pySwig instance

set_script_path(script_path: str) None

Set the path to the Python script setting up the whole work

Parameters:

script_path – the path to the Python script setting up the whole work.

set_source_files(source: list[str | list[Any]]) None

Set the list of source files to process

Parameters:

source – the list of source files to process

set_src_output_dir(src_output_dir: str) None

Set the ouput directory where all generated files will be stored

Parameters:

src_output_dir – the ouput directory where all generated files will be stored

class pyswig.processsrcfile.ProcessSrcFile(name: str, verbose: bool = False, file_config: FileConfig | None = None, wrap_filename: bool = False)

Bases: object

Process one FileConfig

add_include() None

Add a C/C++ include file at the place of <swig_inc/> annotation

do_command(cmd: str) bool

Process one given command

do_swig_close(cmd: str) bool

Process a </swig>

do_swig_closed(cmd: str) bool

Process a <swig/>

do_swig_out_close(cmd: str) bool

Process a </swig_out>

do_swig_out_closed() None

Process a <swig_out/>

do_swig_out_start(cmd: str) None

Process a <swig_out>

do_swig_start(cmd: str) bool

Process a <swig>

do_tags_close(cmd: str) None

Process a </tags>

do_tags_start(cmd: str) None

Process a <tags>

get_pyswig_version() str | None
get_wrap_filename() bool
handle_comment() None

Handle one comment

parse() int

Parse this input file and generate the corresponding output file.

print_error(msg: str) None

Raise a parse error with file and line context.

set_pyswig_version(pyswig_version: str) None
start_of_multi_lines_comment() None

Handle the start of a multi lines comment

start_of_single_line_comment() None

Handle the start of a single line comment

write(text: str) None

Write some text to the ouput file

Parameters:

text – the text to write

class pyswig.maininterfacefile.MainInterfaceFile(pyswig: PySwig | None = None)

Bases: object

Class generating the main interface file, input to Swig

close() None

Close the file

generate() None

Generate the Swig interface file, the main input file for Swig

main_file_write_interface_files() None

Write the insterface in the main file

open() None

Open the Swig interface file, the main input file for Swig

write_cpp_includes() None

Write the C/C++ includes to the main file

write_defines() None

Write the defines in the main file

write_header() None

Write header of the the main interface file

class pyswig.swig.Swig

Bases: object

Swig helper class

LANGUAGES = ['python', 'csharp', 'xml']
SWIG_EXE_NAME = ['swig.exe', 'swig', 'swigwin.exe']
SWIG_SEARCV_ENV = ['SWIG', 'ESYS_SWIG']
add_include_lib(include_lib: str) None

Add one path where to search for Swig include libraries

detect() bool

Detect Swig

detect_in_env() bool

Try to find the swig executable using environment variable

detect_in_exe_path() bool

Try to find the swig executable hoping it’s found in the path

detect_version() int

Detect swig version

found_dir(path: str) bool

Called when swig was found on some path

get_all_warnings() bool
get_exe_path() str | None

Get the path to Swig executable

get_include_libs() list[str] | None

Get the pathes where to search for Swig include libraries

get_input_file() str | None
get_language() str | None
get_process_cpp() bool
get_threads_enabled() bool
get_verbose() bool
get_version() str | None

Get Swig version

log(msg: str) None
run(cwd: str | None = None) int

Run swig with the configured parameters

set_all_warnings(all_warnings: bool = True) None

Turn on or off all warnings

set_exe_path(exe_path: str) None

Set the path to Swig executable

set_include_libs(include_libs: list[str] | None) None

Set the pathes where to search for Swig include libraries

set_input_file(input_file: str) None
set_language(language: str) None
set_process_cpp(process_cpp: bool = True) None

Turn on of off the processing of C++

set_threads_enabled(are_threads_enabled: bool = True) None

Turn on or off thread support

set_verbose(verbose: bool) None
set_version(version: str) None

Set Swig version

Package

PySwig — generate SWIG input files from annotated C/C++ headers.

class pyswig.FileConfig

Class holding the information about a set of files with same source and output directory

add_tags(the_file: str | None, tags: list[str] | None) None

Record tags metadata parsed from a source header.

do_swig(enable: bool = True) None

Enable or disable Swig output generation for this file set.

do_tags(enable: bool = True) None

Enable or disable tag extraction for this file set.

get_base_abs_path() str | None
get_base_inc_dir() str | None

Get the folder to be used as the base of all indlude files generated by <swig_inc/>

Returns:

This is set the beginning of the path for header added by <swig_inc/> annotation.

get_output_file_ext(local: bool = True) str | None

get the extension that the generated files input to Swig will have

Parameters:

local – If True, return the local extension; otherwise use the Swig instance value.

Returns:

the extension that the generated files input to Swig will have

get_pyswig() PySwig | None

Get the pySwig instance

get_script_path() str | None

Get the path to the Python script setting up the whole work

Returns:

the path to the Python script setting up the whole work.

get_source_files() list[str | list[Any]] | None

Get the list of source file to process

Returns:

the list of source files to process

get_src_output_dir(local: bool = True) str | None

Get the ouput directory where all generated files will be stored

Parameters:

local – If True, return the local output path; otherwise use the Swig instance path.

Returns:

the ouput directory where all generated files will be stored

save_tags(name: str) None

Write collected tags to a Python list literal file.

set_base_abs_path(base_abs_path: str) None
set_base_inc_dir(base_inc_dir: str) None

Set the folder to be used as the base of all indlude files generated by <swig_inc/>

Parameters:

base_inc_dir – Base path prefix for headers added by the <swig_inc/> annotation.

set_input_dir(input_dir: str) None

Set the base of the input directory, so that source files are relative to it

Parameters:

input_dir – the base of the input directory

set_output_file_ext(ext: str) None

Set the extension that the generated files input to Swig will have

Parameters:

ext – the extension that the generated files input to Swig will have

set_pyswig(pyswig: PySwig) None

Set the pySwig instance

set_script_path(script_path: str) None

Set the path to the Python script setting up the whole work

Parameters:

script_path – the path to the Python script setting up the whole work.

set_source_files(source: list[str | list[Any]]) None

Set the list of source files to process

Parameters:

source – the list of source files to process

set_src_output_dir(src_output_dir: str) None

Set the ouput directory where all generated files will be stored

Parameters:

src_output_dir – the ouput directory where all generated files will be stored

class pyswig.MainInterfaceFile(pyswig: PySwig | None = None)

Class generating the main interface file, input to Swig

close() None

Close the file

generate() None

Generate the Swig interface file, the main input file for Swig

main_file_write_interface_files() None

Write the insterface in the main file

open() None

Open the Swig interface file, the main input file for Swig

write_cpp_includes() None

Write the C/C++ includes to the main file

write_defines() None

Write the defines in the main file

write_header() None

Write header of the the main interface file

class pyswig.ProcessSrcFile(name: str, verbose: bool = False, file_config: FileConfig | None = None, wrap_filename: bool = False)

Process one FileConfig

add_include() None

Add a C/C++ include file at the place of <swig_inc/> annotation

do_command(cmd: str) bool

Process one given command

do_swig_close(cmd: str) bool

Process a </swig>

do_swig_closed(cmd: str) bool

Process a <swig/>

do_swig_out_close(cmd: str) bool

Process a </swig_out>

do_swig_out_closed() None

Process a <swig_out/>

do_swig_out_start(cmd: str) None

Process a <swig_out>

do_swig_start(cmd: str) bool

Process a <swig>

do_tags_close(cmd: str) None

Process a </tags>

do_tags_start(cmd: str) None

Process a <tags>

get_pyswig_version() str | None
get_wrap_filename() bool
handle_comment() None

Handle one comment

parse() int

Parse this input file and generate the corresponding output file.

print_error(msg: str) None

Raise a parse error with file and line context.

set_pyswig_version(pyswig_version: str) None
start_of_multi_lines_comment() None

Handle the start of a multi lines comment

start_of_single_line_comment() None

Handle the start of a single line comment

write(text: str) None

Write some text to the ouput file

Parameters:

text – the text to write

class pyswig.PySwig(verbose: bool = True, *, parse_cli: bool = True)

The class used to configure the Swig preprocessor

VERSION = '0.1.4'
add_define(name: str, value: str | None = '') None

Adds a define to be included in the generated files

add_file_config(file_config: FileConfig) None

Add a FileConfig object

add_import(import_lib: str) None
add_include(include: str, local: bool = True) None

Add a C/C++ include file to be added

add_include_dir(include_dir: str) None

Add a Swig include search directory (-I).

add_include_lib(include_lib: str) None
add_replace_string(orig: str, new: str) None

Add string to be replace in the wrapper source code gerenated by Swig

add_typemap(type_map: str) None

Add a typemap which should be included in the generated files

do_file_config(file_config: FileConfig) None

Generate the output files related to one given FileConfig

generate() None

Generate all output files

generate_include_file() None

Write the include file included in the wrapper if generated

generate_main_interface_file() None

Write the Swig interface file, the main input file for Swig

get_all_warnings() bool

Get if all warnings are turned on or off

get_copy_shadow_dir() str | None

Get the folder where the shadow class is copied to if any

get_defines() list[list[str | None]]

Get the list of all defines to be included in the generated files

get_file_configs() list[FileConfig]

Return the list of all FileConfig objects

get_imports() list[str] | None
get_inc_output_dir() str | None

Get the output directory for include files

get_include_libs() list[str] | None
get_includes(local: bool = True) list[str]

Get the list of include files to be addded to the generated files

get_language() str | None

Get the language that the wrapper Swig should create

get_module_name() str | None

Get the Swig module name

get_output_cxx_file_path() str
get_output_cxx_filename() str
get_output_file() str | None

Get the outfile for Swig

get_output_file_ext() str | None

get the extension that the generated files input to Swig should have

get_process_cpp() bool

Get if Swig will be processing of C++ is turned on or off

get_replace_strings() list[list[str]]
get_shadow_file() str | None

Get the shadow file name if any is build

get_src_output_dir() str | None

Get the output directory for source file

get_swig() Swig

Get the Swig instance

get_threads_enabled() bool

Get if swig will generate theaded wrapper ot not

get_typemaps() list[str]

Get the list of all typemaps to use

get_use_director() bool

Get if the director feature of Swig should be used or not

get_verbose() bool

Get the verbosity level

get_version() str

Get PySwig version

handle_input_file() None

Resolve CLI input paths without changing the process working directory.

m_args: Namespace | None
m_copy_shadow_dir: str | None
m_defines: list[list[str | None]]
m_file_configs: list[FileConfig]
m_global_include_files: list[str]
m_imports: list[str] | None
m_inc_output_dir: str | None
m_include_libs: list[str] | None
m_local_include_files: list[str]
m_module_name: str | None
m_output_file: str | None
m_output_file_ext: str | None
m_replace_strings: list[list[str]]
m_resolved_input_file: str | None
m_src_output_dir: str | None
m_typemaps: list[str]
process_param() None

Process the command line parameters.

replace_all_strings() None

Replace all strings in Swig generated wrapper file

replace_strings_in_line(line: str) str
run_swig() int

Run swig on the newly generated files

set_all_warnings(all_warnings: bool = True) None

Turn on or off all warnings

set_copy_shadow_dir(copy_shadow_dir: str) None

Set the folder where the shadow class is copied to if any

set_imports(imports: list[str]) None
set_inc_output_dir(inc_output_dir: str) None

Set the output directory for include files

set_include_libs(include_libs: list[str] | None) None
set_language(language: str) None

Set the language that the wrapper Swig should create

set_module_name(module_name: str) None

Set the Swig module name

set_output_file(output_file: str) None

Set the outfile for Swig

set_output_file_ext(ext: str) None

Set the extension that the generated files input to Swig should have

set_process_cpp(process_cpp: bool = True) None

Turn on of off the processing of C++

set_src_output_dir(src_output_dir: str) None

Set the output directory for source file

set_threads_enabled(are_threads_enabled: bool = True) None

Turn on or off thread support

set_use_director(use_director: bool) None

Set if the director feature of Swig should be used or not

set_verbose(verbose: bool) None

Set the verbosity level

exception pyswig.PySwigError

Raised when PySwig configuration or generation fails.

class pyswig.Swig

Swig helper class

LANGUAGES = ['python', 'csharp', 'xml']
SWIG_EXE_NAME = ['swig.exe', 'swig', 'swigwin.exe']
SWIG_SEARCV_ENV = ['SWIG', 'ESYS_SWIG']
add_include_lib(include_lib: str) None

Add one path where to search for Swig include libraries

detect() bool

Detect Swig

detect_in_env() bool

Try to find the swig executable using environment variable

detect_in_exe_path() bool

Try to find the swig executable hoping it’s found in the path

detect_version() int

Detect swig version

found_dir(path: str) bool

Called when swig was found on some path

get_all_warnings() bool
get_exe_path() str | None

Get the path to Swig executable

get_include_libs() list[str] | None

Get the pathes where to search for Swig include libraries

get_input_file() str | None
get_language() str | None
get_process_cpp() bool
get_threads_enabled() bool
get_verbose() bool
get_version() str | None

Get Swig version

log(msg: str) None
m_exe_path: str | None
m_include_libs: list[str] | None
m_input_file: str | None
m_language: str | None
m_path: str | None
m_version: str | None
run(cwd: str | None = None) int

Run swig with the configured parameters

set_all_warnings(all_warnings: bool = True) None

Turn on or off all warnings

set_exe_path(exe_path: str) None

Set the path to Swig executable

set_include_libs(include_libs: list[str] | None) None

Set the pathes where to search for Swig include libraries

set_input_file(input_file: str) None
set_language(language: str) None
set_process_cpp(process_cpp: bool = True) None

Turn on of off the processing of C++

set_threads_enabled(are_threads_enabled: bool = True) None

Turn on or off thread support

set_verbose(verbose: bool) None
set_version(version: str) None

Set Swig version