Best by refactoring into an abstract base class (ABC) that is then inherited for the different outputs (Dockerfile, Apptainer, OCI?, ...).