Maps Python module paths to Elixir file paths for split layout generation.
This module provides deterministic path mapping from Python module paths to Elixir source file paths, mirroring Python's package structure.
Convention
- Package/submodule directories use
__init__.ex(like Python's__init__.py) - Class modules use
lowercase_name.exfiles - All paths are lowercase with underscores
Examples
iex> PathMapper.module_to_path("examplelib", "lib/gen")
"lib/gen/examplelib/__init__.ex"
iex> PathMapper.module_to_path("examplelib.predict", "lib/gen")
"lib/gen/examplelib/predict/__init__.ex"
iex> PathMapper.class_file_path("examplelib.predict", "Widget", "lib/gen")
"lib/gen/examplelib/predict/widget.ex"
Summary
Functions
Computes all file paths needed for a library's functions and classes.
Returns all ancestor module paths for a given Python module.
Computes the file path for a class module.
Returns the directory path for a Python module.
Computes file path for a Python module's functions.
Converts a Python module path to an Elixir module atom.
Functions
@spec all_files_for_library(String.t(), [map()], [map()], String.t()) :: {[String.t()], [String.t()]}
Computes all file paths needed for a library's functions and classes.
Returns a tuple of {module_files, class_files}. Module files are generated
for the library root and any python modules that have functions or classes.
Parameters
library_python_name- The library's Python module namefunctions- List of function info maps with "python_module" keyclasses- List of class info maps with "python_module" and "name" keysbase_dir- Base directory for generated files
Returns all ancestor module paths for a given Python module.
Examples
iex> ancestor_modules("examplelib")
[]
iex> ancestor_modules("examplelib.predict")
["examplelib"]
iex> ancestor_modules("examplelib.predict.chain.widget")
["examplelib", "examplelib.predict", "examplelib.predict.chain"]
Computes the file path for a class module.
Classes are placed as direct .ex files named after the class.
Examples
iex> class_file_path("examplelib.predict", "Widget", "lib/gen")
"lib/gen/examplelib/predict/widget.ex"
Returns the directory path for a Python module.
Examples
iex> module_to_dir("examplelib", "lib/gen")
"lib/gen/examplelib"
iex> module_to_dir("examplelib.predict", "lib/gen")
"lib/gen/examplelib/predict"
Computes file path for a Python module's functions.
By default, modules are treated as packages and get __init__.ex.
Use type: :leaf for leaf modules that should get direct .ex files.
Parameters
python_module- The Python module path (e.g., "examplelib.predict")base_dir- Base directory for generated filestype-:package(default) or:leaf
Examples
iex> module_to_path("examplelib", "lib/gen")
"lib/gen/examplelib/__init__.ex"
iex> module_to_path("examplelib.predict.widget", "lib/gen", :leaf)
"lib/gen/examplelib/predict/widget.ex"
Converts a Python module path to an Elixir module atom.
Parameters
python_module- The Python module pathlibrary_module- The base Elixir module for the library
Examples
iex> python_module_to_elixir_module("examplelib", Examplelib)
Examplelib
iex> python_module_to_elixir_module("examplelib.predict", Examplelib)
Examplelib.Predict