convert module#

generate_python_file_description(component_code)[source]#

Generate a description for the generated Python code written to the file, including instructions on how to import the component.

Return type:

str

Parameters:

component_code (ComponentCode)

extract_subclasses_from_ast_module(ast_module, base_class_name)[source]#
Return type:

Sequence[str]

Parameters:
ast_module_to_string(module_ast, format_pep8=True)[source]#
Return type:

str

Parameters:
rewrite_negative_constants(tree)[source]#
Return type:

Module

Parameters:

tree (Module)

compare_ast_with_ast_from_unparse(ast_module, output_path=None)[source]#
Return type:

bool

Parameters:
  • ast_module (Module)

  • output_path (str | None)

get_namespace_from_source_code(source_code, source_file='dummy')[source]#
Return type:

Mapping[str, object]

Parameters:
  • source_code (str)

  • source_file (str)

compile_class_from_source_code(source_code, class_name, source_file='dummy')[source]#
Return type:

type

Parameters:
  • source_code (str)

  • class_name (str)

  • source_file (str)

get_subclasses_from_namespace(namespace, base_class)[source]#
Return type:

Sequence[type[TypeVar(T)]]

Parameters:
compile_subclasses_from_source_code(source_code, base_class)[source]#
Return type:

Sequence[type[TypeVar(T)]]

Parameters:
  • source_code (str)

  • base_class (type[T])

read_from_file(path)[source]#
Return type:

str

Parameters:

path (str)

compile_subclasses_from_file(source_file, base_class)[source]#
Return type:

Sequence[type[TypeVar(T)]]

Parameters:
  • source_file (str)

  • base_class (type[T])

insert_model3d_dir(component, model3d_dir)[source]#

Modify ComponentCode to place the Model3D files under the model3d_dir folder.

Example

This function would change the filename in a Model3D statement “jitx-01234.stp” to “model3d_dir/jitx-01234.stp”.

Return type:

ComponentCode

Parameters:
  • component (ComponentCode)

  • model3d_dir (str)

convert_component_core(component_code, component_name=None, output_path=None, local_model3d_file=False, use_jitxstd_symbol=None)[source]#
Return type:

type[Component] | None

Parameters:
  • component_code (ComponentCode)

  • component_name (str | None)

  • output_path (str | None)

  • local_model3d_file (bool)

  • use_jitxstd_symbol (StdLibSymbolType | None)

convert_component(component_code, component_name=None, output_path=None, use_jitxstd_symbol=None)[source]#
Return type:

type[Component]

Parameters:
  • component_code (ComponentCode)

  • component_name (str | None)

  • output_path (str | None)

  • use_jitxstd_symbol (StdLibSymbolType | None)

write_marker_file(root_path, rel_path_to_init)[source]#

Write a marker file in root_path that declares the import target folder.

Return type:

None

Parameters:
  • root_path (str)

  • rel_path_to_init (str)

read_import_target_from_marker_file(root_path)[source]#

Read the import_target folder from the marker file if exists.

Returns:

relative path to the package if valid, otherwise None.

Return type:

str | None

Parameters:

root_path (str)

determine_import_target_folder(start_path='.')[source]#

Determine the path to the source package, containing the __init__.py file, to use as the import_target folder.

Perform a breadth-first search from start_path to find the top-most directory that contains an __init__.py file. Use a marker file to cache the result to avoid repeated searches.

Returns:

relative path to the found package directory

Return type:

str

create_component(part_json)[source]#
Return type:

tuple[str, str]

Parameters:

part_json (dict[str, Mapping[str, JSON] | Sequence[JSON] | str | int | float | bool | None])

get_jitxstd_symbol(category)[source]#
Return type:

StdLibSymbolType | None

Parameters:

category (Category | None)