Skip to content

Add type stubs to the Python module #1926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions interfaces/cython/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if localenv["example_data"]:
localenv.Command(f"cantera/data/example_data/{yaml.name}", yaml.abspath,
Copy("$TARGET", "$SOURCE"))))

# Add type stubs as dataFiles
for stub_location in ["cantera", "cantera/with_units"]:
for pyifile in multi_glob(localenv, f"#interfaces/cython/{stub_location}", "pyi"):
dataFiles.append(build(localenv.Command(f"{stub_location}/{pyifile.name}", pyifile.abspath, Copy("$TARGET", "$SOURCE"))))

# Install Python samples
install(localenv.RecursiveInstall, "$inst_sampledir/python", "#samples/python")
Expand Down
373 changes: 373 additions & 0 deletions interfaces/cython/cantera/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,373 @@
from cantera import (
_cantera,
_onedim,
_utils,
composite,
constants,
data,
delegator,
drawnetwork,
func1,
kinetics,
liquidvapor,
mixture,
onedim,
reaction,
reactionpath,
reactor,
solutionbase,
speciesthermo,
thermo,
transport,
units,
utils,
yamlwriter,
)
from cantera._cantera import CythonPackageMetaPathFinder
from cantera._onedim import (
AxisymmetricFlow,
Boundary1D,
Domain1D,
FlowBase,
FreeFlow,
Inlet1D,
Outlet1D,
OutletReservoir1D,
ReactingSurface1D,
Sim1D,
Surface1D,
SymmetryPlane1D,
UnstrainedFlow,
)
from cantera._utils import (
AnyMap,
CanteraError,
__git_commit__,
__sundials_version__,
__version__,
add_directory,
appdelete,
debug_mode_enabled,
get_data_directories,
hdf_support,
make_deprecation_warnings_fatal,
print_stack_trace_on_segfault,
suppress_deprecation_warnings,
suppress_thermo_warnings,
use_legacy_rate_constants,
use_sparse,
)
from cantera.composite import DustyGas, Interface, Quantity, Solution, SolutionArray
from cantera.constants import (
avogadro,
boltzmann,
electron_charge,
electron_mass,
epsilon_0,
faraday,
gas_constant,
light_speed,
one_atm,
permeability_0,
planck,
stefan_boltzmann,
)
from cantera.data import list_data_files
from cantera.delegator import extension
from cantera.drawnetwork import (
draw_flow_controllers,
draw_reactor,
draw_reactor_net,
draw_surface,
draw_walls,
)
from cantera.func1 import Func1, Tabulated1
from cantera.interrupts import no_op
from cantera.jacobians import (
AdaptivePreconditioner,
# BandedJacobian,
# EigenSparseDirectJacobian,
# EigenSparseJacobian,
SystemJacobian,
)
from cantera.kinetics import InterfaceKinetics, Kinetics
from cantera.liquidvapor import (
CarbonDioxide,
Heptane,
Hfc134a,
Hydrogen,
Methane,
Nitrogen,
Oxygen,
Water,
)
from cantera.mixture import Mixture
from cantera.onedim import (
BurnerFlame,
CounterflowDiffusionFlame,
CounterflowPremixedFlame,
CounterflowTwinPremixedFlame,
FlameBase,
FreeFlame,
ImpingingJet,
)
from cantera.reaction import (
Arrhenius,
ArrheniusRate,
ArrheniusRateBase,
BlowersMaselRate,
ChebyshevRate,
CustomRate,
ElectronCollisionPlasmaRate,
ExtensibleRate,
ExtensibleRateData,
FalloffRate,
InterfaceArrheniusRate,
InterfaceBlowersMaselRate,
InterfaceRateBase,
LindemannRate,
LinearBurkeRate,
PlogRate,
Reaction,
ReactionRate,
SriRate,
StickingArrheniusRate,
StickingBlowersMaselRate,
StickRateBase,
ThirdBody,
TroeRate,
TsangRate,
TwoTempPlasmaRate,
)
from cantera.reactionpath import ReactionPathDiagram
from cantera.reactor import (
ConnectorNode,
ConstPressureMoleReactor,
ConstPressureReactor,
ExtensibleConstPressureMoleReactor,
ExtensibleConstPressureReactor,
ExtensibleIdealGasConstPressureMoleReactor,
ExtensibleIdealGasConstPressureReactor,
ExtensibleIdealGasMoleReactor,
ExtensibleIdealGasReactor,
ExtensibleMoleReactor,
ExtensibleReactor,
FlowDevice,
FlowReactor,
IdealGasConstPressureMoleReactor,
IdealGasConstPressureReactor,
IdealGasMoleReactor,
IdealGasReactor,
MassFlowController,
MoleReactor,
PressureController,
Reactor,
ReactorBase,
ReactorNet,
ReactorSurface,
Reservoir,
Valve,
Wall,
WallBase,
)
from cantera.solutionbase import SolutionArrayBase
from cantera.speciesthermo import (
ConstantCp,
Mu0Poly,
Nasa9PolyMultiTempRegion,
NasaPoly2,
ShomatePoly2,
SpeciesThermo,
)
from cantera.thermo import (
Element,
InterfacePhase,
PureFluid,
Species,
ThermoModelMethodError,
ThermoPhase,
)
from cantera.transport import DustyGasTransport, GasTransportData, Transport
from cantera.units import Units, UnitStack, UnitSystem
from cantera.utils import add_module_directory, import_phases
from cantera.yamlwriter import YamlWriter

__all__: list[str] = [
"AdaptivePreconditioner",
"AnyMap",
"Arrhenius",
"ArrheniusRate",
"ArrheniusRateBase",
"AxisymmetricFlow",
"BlowersMaselRate",
"Boundary1D",
"BurnerFlame",
"CanteraError",
"CarbonDioxide",
"ChebyshevRate",
"ConnectorNode",
"ConstPressureMoleReactor",
"ConstPressureReactor",
"ConstantCp",
"CounterflowDiffusionFlame",
"CounterflowPremixedFlame",
"CounterflowTwinPremixedFlame",
"CustomRate",
"CythonPackageMetaPathFinder",
"Domain1D",
"DustyGas",
"DustyGasTransport",
"ElectronCollisionPlasmaRate",
"Element",
"ExtensibleConstPressureMoleReactor",
"ExtensibleConstPressureReactor",
"ExtensibleIdealGasConstPressureMoleReactor",
"ExtensibleIdealGasConstPressureReactor",
"ExtensibleIdealGasMoleReactor",
"ExtensibleIdealGasReactor",
"ExtensibleMoleReactor",
"ExtensibleRate",
"ExtensibleRateData",
"ExtensibleReactor",
"FalloffRate",
"FlameBase",
"FlowBase",
"FlowDevice",
"FlowReactor",
"FreeFlame",
"FreeFlow",
"Func1",
"GasTransportData",
"Heptane",
"Hfc134a",
"Hydrogen",
"IdealGasConstPressureMoleReactor",
"IdealGasConstPressureReactor",
"IdealGasMoleReactor",
"IdealGasReactor",
"ImpingingJet",
"Inlet1D",
"Interface",
"InterfaceArrheniusRate",
"InterfaceBlowersMaselRate",
"InterfaceKinetics",
"InterfacePhase",
"InterfaceRateBase",
"Kinetics",
"LindemannRate",
"LinearBurkeRate",
"MassFlowController",
"Methane",
"Mixture",
"MoleReactor",
"Mu0Poly",
"Nasa9PolyMultiTempRegion",
"NasaPoly2",
"Nitrogen",
"Outlet1D",
"OutletReservoir1D",
"Oxygen",
"PlogRate",
"PressureController",
"PureFluid",
"Quantity",
"ReactingSurface1D",
"Reaction",
"ReactionPathDiagram",
"ReactionRate",
"Reactor",
"ReactorBase",
"ReactorNet",
"ReactorSurface",
"Reservoir",
"ShomatePoly2",
"Sim1D",
"Solution",
"SolutionArray",
"SolutionArrayBase",
"Species",
"SpeciesThermo",
"SriRate",
"StickRateBase",
"StickingArrheniusRate",
"StickingBlowersMaselRate",
"Surface1D",
"SymmetryPlane1D",
"SystemJacobian",
"Tabulated1",
"ThermoModelMethodError",
"ThermoPhase",
"ThirdBody",
"Transport",
"TroeRate",
"TsangRate",
"TwoTempPlasmaRate",
"UnitStack",
"UnitSystem",
"Units",
"UnstrainedFlow",
"Valve",
"Wall",
"WallBase",
"Water",
"YamlWriter",
"__git_commit__",
"__sundials_version__",
"__version__",
"_cantera",
"_onedim",
"_utils",
"add_directory",
"add_module_directory",
"appdelete",
"avogadro",
"boltzmann",
"composite",
"constants",
"data",
"debug_mode_enabled",
"delegator",
"draw_flow_controllers",
"draw_reactor",
"draw_reactor_net",
"draw_surface",
"draw_walls",
"drawnetwork",
"electron_charge",
"electron_mass",
"epsilon_0",
"extension",
"faraday",
"func1",
"gas_constant",
"get_data_directories",
"hdf_support",
"import_phases",
"kinetics",
"light_speed",
"liquidvapor",
"list_data_files",
"make_deprecation_warnings_fatal",
"mixture",
"no_op",
"one_atm",
"onedim",
"permeability_0",
"planck",
"print_stack_trace_on_segfault",
"reaction",
"reactionpath",
"reactor",
"solutionbase",
"speciesthermo",
"stefan_boltzmann",
"suppress_deprecation_warnings",
"suppress_thermo_warnings",
"thermo",
"transport",
"units",
"use_legacy_rate_constants",
"use_sparse",
"utils",
"yamlwriter",
]
14 changes: 14 additions & 0 deletions interfaces/cython/cantera/_cantera.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import importlib.abc
from importlib.machinery import ModuleSpec
from types import ModuleType
from typing import Sequence, override

class CythonPackageMetaPathFinder(importlib.abc.MetaPathFinder):
def __init__(self, name_filter: str) -> None: ...
@override
def find_spec(
self,
fullname: str,
path: Sequence[str] | None,
target: ModuleType | None = None,
) -> ModuleSpec | None: ...
Loading