flexlate package¶
A composable, maintainable system for managing templates
Subpackages¶
Submodules¶
flexlate.add_mode module¶
flexlate.adder module¶
- class flexlate.adder.Adder[source]¶
Bases:
object
- add_template_source(repo, template, transaction, target_version=None, out_root=PosixPath('.'), merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', add_mode=AddMode.LOCAL, remote='origin', config_manager=<flexlate.config_manager.ConfigManager object>)[source]¶
- apply_template_and_add(repo, template, transaction, data=None, out_root=PosixPath('.'), add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', no_input=False, remote='origin', config_manager=<flexlate.config_manager.ConfigManager object>, updater=<flexlate.update.main.Updater object>, renderer=<flexlate.render.multi.MultiRenderer object>)[source]¶
- init_project_and_add_to_branches(repo, default_add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', user=False, remote='origin', config_manager=<flexlate.config_manager.ConfigManager object>)[source]¶
- init_project_from_template_source_path(template, transaction, path=PosixPath('.'), target_version=None, data=None, default_folder_name='project', default_add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', remote='origin', no_input=False, config_manager=<flexlate.config_manager.ConfigManager object>, updater=<flexlate.update.main.Updater object>, renderer=<flexlate.render.multi.MultiRenderer object>, syncer=<flexlate.syncer.Syncer object>)[source]¶
- Return type
flexlate.bootstrapper module¶
- class flexlate.bootstrapper.Bootstrapper[source]¶
Bases:
object
- bootstrap_flexlate_init_from_existing_template(repo, template, transaction, target_version=None, data=None, default_add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', remote='origin', no_input=False, adder=<flexlate.adder.Adder object>, config_manager=<flexlate.config_manager.ConfigManager object>, renderer=<flexlate.render.multi.MultiRenderer object>, updater=<flexlate.update.main.Updater object>, user_config_manager=<flexlate.user_config_manager.UserConfigManager object>)[source]¶
flexlate.branch_update module¶
- flexlate.branch_update.abort_merge_and_reset_flexlate_branches(repo, current_branch, merged_branch_sha=None, template_branch_sha=None, merged_branch_name='flexlate-output', template_branch_name='flexlate-templates')[source]¶
- flexlate.branch_update.get_flexlate_branch_name_for_feature_branch(feature_branch, base_branch_name)[source]¶
- Return type
- flexlate.branch_update.modify_files_via_branches_and_temp_repo(file_operation, repo, commit_message, out_root, merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', remote='origin')[source]¶
flexlate.checker module¶
- class flexlate.checker.CheckResults(**data)[source]¶
Bases:
pydantic.main.BaseModel
- results: List[flexlate.checker.CheckResult]¶
- property updates: List[flexlate.checker.CheckResult]¶
- Return type
- class flexlate.checker.CheckResultsRenderable(**data)[source]¶
Bases:
pydantic.main.BaseModel
- results: List[flexlate.checker.CheckResult]¶
flexlate.cli module¶
- flexlate.cli.add_source(path=typer.Argument, name=typer.Argument, version=typer.Option, template_root=typer.Option, add_mode=typer.Option, quiet=typer.Option)¶
Adds a new template source, so that files can be generated from it.
See the [user guide on adding new templates within an existing project]( https://nickderobertis.github.io/flexlate/tutorial/get-started/add-to-project.html ) for more details.
- flexlate.cli.bootstrap(template_path=typer.Argument, path=typer.Argument, version=typer.Option, no_input=typer.Option, quiet=typer.Option, default_add_mode=typer.Option, remote=typer.Option, merged_branch_name=typer.Option, template_branch_name=typer.Option)¶
Sets up a Flexlate project from an existing project that was already generated by another tool such as Cookiecutter or Copier.
See the user guide on [adding Flexlate to a project already generated from a template]( https://nickderobertis.github.io/flexlate/tutorial/get-started/existing-project.html ) for more information.
- flexlate.cli.check(names=typer.Argument, path=typer.Option, quiet=typer.Option)¶
Checks whether there are any updates available for the current template sources
Displays a tabular output of the templates that need to be updated. It will also exist with code 1 when updates are available so that it is easy to use in scripting.
See the user guide on [updating templates]( https://nickderobertis.github.io/flexlate/tutorial/updating.html ), especially [the section about checking for updates]( https://nickderobertis.github.io/flexlate/tutorial/updating.html#checking-for-updates ), for more information.
- flexlate.cli.generate_applied_template(name=typer.Argument, template_root=typer.Argument, add_mode=typer.Option, no_input=typer.Option, quiet=typer.Option)¶
Applies a template to a given location, and stores it in config so it can be updated
See the [user guide on adding new templates within an existing project]( https://nickderobertis.github.io/flexlate/tutorial/get-started/add-to-project.html ) for more details.
- flexlate.cli.init_project(path=typer.Argument, default_add_mode=typer.Option, merged_branch_name=typer.Option, template_branch_name=typer.Option, user=typer.Option, remote=typer.Option, quiet=typer.Option)¶
Initializes a flexlate project. This must be run before other commands
See the user guide on [adding templates within an existing project]( https://nickderobertis.github.io/flexlate/tutorial/get-started/add-to-project.html ) for more details.
- flexlate.cli.init_project_from(template_path=typer.Argument, path=typer.Argument, version=typer.Option, folder_name=typer.Option, no_input=typer.Option, quiet=typer.Option, default_add_mode=typer.Option, remote=typer.Option, merged_branch_name=typer.Option, template_branch_name=typer.Option)¶
Generates a project from a template and sets it up as a Flexlate project.
Note that this will also create a new folder and initialize a git repository in it before adding the Flexlate output.
See the user guide on [creating a new project with Flexlate]( https://nickderobertis.github.io/flexlate/tutorial/get-started/new-project.html ) for more information.
- flexlate.cli.merge(branch_name=typer.Argument, delete=typer.Option, path=typer.Option, quiet=typer.Option)¶
Merges feature flexlate branches into the main flexlate branches
Feature flexlate branches should be merged into main flexlate branches when the corresponding feature branch is merged into the repo’s main branch. This command provides a convenient way to do so.
See the user guide on [saving Flexlate updates]( https://nickderobertis.github.io/flexlate/tutorial/saving.html ), especially [the section about locally merging branches]( https://nickderobertis.github.io/flexlate/tutorial/saving.html#locally-merging-branches ), for more information.
- flexlate.cli.pre_execute(version=typer.Option)¶
- flexlate.cli.push_feature(feature_branch=typer.Argument, remote=typer.Option, path=typer.Option, quiet=typer.Option)¶
Pushes feature Flexlate branches to remote
See the user guide on [saving Flexlate updates]( https://nickderobertis.github.io/flexlate/tutorial/saving.html ), especially [the section about pushing changes with a PR workflow]( https://nickderobertis.github.io/flexlate/tutorial/saving.html#push-your-flexlate-feature-branch-changes ), for more information.
- flexlate.cli.push_main(remote=typer.Option, path=typer.Option, quiet=typer.Option)¶
Pushes main Flexlate branches to remote
See the user guide on [saving Flexlate updates]( https://nickderobertis.github.io/flexlate/tutorial/saving.html ), especially [the section about pushing with a local workflow]( https://nickderobertis.github.io/flexlate/tutorial/saving.html#push-your-flexlate-main-branch-changes ), for more information.
- flexlate.cli.remove_template_output(template_name=typer.Argument, template_root=typer.Argument, quiet=typer.Option)¶
Removes an applied template output
- flexlate.cli.remove_template_source(template_name=typer.Argument, template_root=typer.Option, quiet=typer.Option)¶
Removes a template source, so that files can no longer be generated from it.
- flexlate.cli.sync(path=typer.Argument, prompt=typer.Option, quiet=typer.Option)¶
Syncs manual changes to the flexlate branches, and updates templates accordingly.
This is useful if you want to move or modify flexlate configs after they are created, but there is no command in the CLI for it.
Note: Be sure to commit your changes before running sync
See the user guide on [making arbitrary changes]( https://nickderobertis.github.io/flexlate/tutorial/arbitrary-changes.html ) for more information.
- flexlate.cli.undo(num_operations=typer.Argument, path=typer.Option, quiet=typer.Option)¶
Undoes the last flexlate operation, like ctrl/cmd + z for flexlate. Note that this modifies the git history, discarding the last commits. It has protections against deleting user commits but you should only use this on a feature branch.
See the user guide on [undoing Flexlate operations]( https://nickderobertis.github.io/flexlate/tutorial/undoing.html ) for more information.
- flexlate.cli.update_template_source_target_version(name=typer.Argument, version=typer.Argument, path=typer.Option, add_mode=typer.Option, quiet=typer.Option)¶
Updates a target version for a template source.
If no version is passed, it will remove the targeting so it will always update.
See the user guide on [updating templates]( https://nickderobertis.github.io/flexlate/tutorial/updating.html ), especially [the section about changing target version]( https://nickderobertis.github.io/flexlate/tutorial/updating.html#change-target-version ), for more information.
- flexlate.cli.update_templates(names=typer.Argument, no_input=typer.Option, abort_on_conflict=typer.Option, no_cleanup=typer.Option, quiet=typer.Option, path=typer.Option)¶
Updates applied templates in the project to the newest versions available that still satisfy source target versions
See the user guide on [updating templates]( https://nickderobertis.github.io/flexlate/tutorial/updating.html ) for more information.
flexlate.cli_utils module¶
flexlate.config module¶
- class flexlate.config.AppliedTemplateConfig(*, name: str, data: Dict[str, Any], version: str, add_mode: flexlate.add_mode.AddMode, root: pathlib.Path = PosixPath('.'))[source]¶
Bases:
pydantic.main.BaseModel
- __init__(**kwargs)[source]¶
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- add_mode: flexlate.add_mode.AddMode¶
- root: pathlib.Path¶
- class flexlate.config.AppliedTemplateWithSource(**data)[source]¶
Bases:
pydantic.main.BaseModel
- applied_template: flexlate.config.AppliedTemplateConfig¶
- applied_template_config_path: pathlib.Path¶
- source: flexlate.config.TemplateSource¶
- source_config_path: pathlib.Path¶
- class flexlate.config.FlexlateConfig(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, **values)[source]¶
Bases:
pyappconf.model.BaseConfig
- applied_templates: List[flexlate.config.AppliedTemplateConfig]¶
- property child_configs: List[flexlate.config.FlexlateConfig]¶
- Return type
- move_applied_template(template_name, config_path, new_config_path, render_relative_root_in_output, project_root=PosixPath('.'), out_root=PosixPath('.'), orig_project_root=PosixPath('.'))[source]¶
- remove_applied_template(template_name, config_location, project_root=PosixPath('.'), out_root=PosixPath('.'), orig_project_root=PosixPath('.'))[source]¶
- Return type
- template_sources: List[flexlate.config.TemplateSource]¶
- property template_sources_dict: Dict[str, flexlate.config.TemplateSource]¶
- Return type
- class flexlate.config.FlexlateProjectConfig(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, **values)[source]¶
Bases:
pyappconf.model.BaseConfig
- projects: List[flexlate.config.ProjectConfig]¶
- class flexlate.config.ProjectConfig(**data)[source]¶
Bases:
pydantic.main.BaseModel
- default_add_mode: flexlate.add_mode.AddMode¶
- path: pathlib.Path¶
- class flexlate.config.TemplateSource(**data)[source]¶
Bases:
pydantic.main.BaseModel
- property absolute_local_path: pathlib.Path¶
- Return type
- render_relative_root_in_output: pathlib.Path¶
- render_relative_root_in_template: pathlib.Path¶
- class flexlate.config.TemplateSourceWithTemplates(**data)[source]¶
Bases:
pydantic.main.BaseModel
- source: flexlate.config.TemplateSource¶
- templates: List[flexlate.template.base.Template]¶
flexlate.config_manager module¶
- class flexlate.config_manager.ConfigManager[source]¶
Bases:
object
- add_applied_template(template, config_path, add_mode, data=None, project_root=PosixPath('.'), out_root=PosixPath('.'))[source]¶
- add_project(path=PosixPath('.'), default_add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', user=False, remote='origin')[source]¶
- add_template_source(template, config_path, target_version=None, project_root=PosixPath('.'))[source]¶
- get_all_renderables(relative_to=None, project_root=PosixPath('.'), config=None)[source]¶
- Return type
- get_applied_templates_with_sources(relative_to=None, project_root=PosixPath('.'), config=None)[source]¶
- Return type
- get_renderables_for_updates(updates, project_root=PosixPath('.'), adjust_root=True)[source]¶
- Return type
- get_sources_with_templates(templates, project_root=PosixPath('.'), config=None)[source]¶
- Return type
- move_applied_template(template_name, config_path, new_config_path, render_relative_root_in_output, project_root=PosixPath('.'), out_root=PosixPath('.'), orig_project_root=PosixPath('.'))[source]¶
- move_local_applied_templates_if_necessary_produce_new_updates(updates, project_root=PosixPath('.'), orig_project_root=PosixPath('.'), renderer=<flexlate.render.multi.MultiRenderer object>)[source]¶
- Return type
- move_template_source(template_name, config_path, new_config_path, project_root=PosixPath('.'))[source]¶
- remove_applied_template(template_name, config_path, project_root=PosixPath('.'), out_root=PosixPath('.'), orig_project_root=PosixPath('.'))[source]¶
flexlate.constants module¶
flexlate.error_handler module¶
flexlate.exc module¶
flexlate.ext_git module¶
- flexlate.ext_git.get_commits_between_two_commits(repo, start, end)[source]¶
- Return type
List
[Commit
]
- flexlate.ext_git.reset_branch_to_commit_without_checkout(repo, branch_name, commit_sha=None)[source]¶
flexlate.get_version module¶
flexlate.logger module¶
- class flexlate.logger.LoggingConfig(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, **values)[source]¶
Bases:
pydantic.env_settings.BaseSettings
- level: flexlate.logger.LogLevel¶
flexlate.main module¶
- class flexlate.main.Flexlate(quiet=False, adder=<flexlate.adder.Adder object>, bootstrapper=<flexlate.bootstrapper.Bootstrapper object>, checker=<flexlate.checker.Checker object>, remover=<flexlate.remover.Remover object>, config_manager=<flexlate.config_manager.ConfigManager object>, merger=<flexlate.merger.Merger object>, finder=<flexlate.finder.multi.MultiFinder object>, pusher=<flexlate.pusher.Pusher object>, renderer=<flexlate.render.multi.MultiRenderer object>, syncer=<flexlate.syncer.Syncer object>, undoer=<flexlate.transactions.undoer.Undoer object>, updater=<flexlate.update.main.Updater object>, user_config_manager=<flexlate.user_config_manager.UserConfigManager object>)[source]¶
Bases:
object
- __init__(quiet=False, adder=<flexlate.adder.Adder object>, bootstrapper=<flexlate.bootstrapper.Bootstrapper object>, checker=<flexlate.checker.Checker object>, remover=<flexlate.remover.Remover object>, config_manager=<flexlate.config_manager.ConfigManager object>, merger=<flexlate.merger.Merger object>, finder=<flexlate.finder.multi.MultiFinder object>, pusher=<flexlate.pusher.Pusher object>, renderer=<flexlate.render.multi.MultiRenderer object>, syncer=<flexlate.syncer.Syncer object>, undoer=<flexlate.transactions.undoer.Undoer object>, updater=<flexlate.update.main.Updater object>, user_config_manager=<flexlate.user_config_manager.UserConfigManager object>)[source]¶
- add_template_source(path, name=None, target_version=None, template_root=PosixPath('.'), add_mode=None)[source]¶
- apply_template_and_add(name, data=None, out_root=PosixPath('.'), add_mode=None, no_input=False)[source]¶
- bootstrap_flexlate_init_from_existing_template(template_path, path=PosixPath('.'), template_version=None, data=None, default_add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', remote='origin', no_input=False)[source]¶
- init_project(path=PosixPath('.'), default_add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', user=False, remote='origin')[source]¶
- init_project_from(template_path, path=PosixPath('.'), template_version=None, data=None, default_folder_name='project', no_input=False, default_add_mode=AddMode.LOCAL, remote='origin', merged_branch_name='flexlate-output', template_branch_name='flexlate-templates')[source]¶
- Return type
- push_feature_flexlate_branches(feature_branch=None, remote='origin', project_path=PosixPath('.'))[source]¶
flexlate.merger module¶
flexlate.path_ops module¶
- flexlate.path_ops.location_relative_to_new_parent(path, orig_parent, new_parent, path_is_relative_to=None)[source]¶
- Return type
flexlate.pusher module¶
flexlate.remover module¶
- class flexlate.remover.Remover[source]¶
Bases:
object
- remove_applied_template_and_output(repo, template_name, transaction, out_root=PosixPath('.'), add_mode=AddMode.LOCAL, merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', remote='origin', config_manager=<flexlate.config_manager.ConfigManager object>, updater=<flexlate.update.main.Updater object>, renderer=<flexlate.render.multi.MultiRenderer object>)[source]¶
- remove_template_source(repo, template_name, transaction, out_root=PosixPath('.'), merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', add_mode=AddMode.LOCAL, remote='origin', config_manager=<flexlate.config_manager.ConfigManager object>)[source]¶
flexlate.styles module¶
flexlate.syncer module¶
- class flexlate.syncer.Syncer[source]¶
Bases:
object
- sync_local_changes_to_flexlate_branches(repo, transaction, merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', no_input=False, remote='origin', updater=<flexlate.update.main.Updater object>, renderer=<flexlate.render.multi.MultiRenderer object>, config_manager=<flexlate.config_manager.ConfigManager object>)[source]¶
flexlate.temp_path module¶
- flexlate.temp_path.create_temp_path()[source]¶
Returns a temporary folder path
Use this instead of tempfile.TemporaryDirectory because: 1. That returns a string and not a path 2. On MacOS, the temp directory has a symlink. This resolves the symlink so that
there won’t be any mismatch in resolved paths.
On Windows, the temp directory can fail to delete with a PermissionError. This function will try to delete the temp directory, but if it fails with an error it will just ignore it.
flexlate.template_data module¶
flexlate.template_path module¶
flexlate.types module¶
flexlate.user_config_manager module¶
- class flexlate.user_config_manager.UserConfigManager[source]¶
Bases:
object
A higher-level version of the config manager that also works with flexlate branches
ConfigManager is the lower-level version that does not care about branches
- update_template_source_target_version(name, target_version, repo, transaction, project_path=PosixPath('.'), add_mode=None, merged_branch_name='flexlate-output', base_merged_branch_name='flexlate-output', template_branch_name='flexlate-templates', base_template_branch_name='flexlate-templates', remote='origin', config_manager=<flexlate.config_manager.ConfigManager object>)[source]¶