Feature/719 add workflow update nox session#720
Conversation
|
| * #712: Added basic logging to workflow processing | ||
| * #714: Added logic to modify a workflow using the .workflow-patcher.yml | ||
| * #717: Restricted workflow names in .workflow-patcher.yml to template workflow names | ||
| * #719: Added nox session `workflow:update` to install/update workflows using the .workflow-patcher.yml (if desired) |
There was a problem hiding this comment.
| * #719: Added nox session `workflow:update` to install/update workflows using the .workflow-patcher.yml (if desired) | |
| * #719: Added nox session `workflow:update` to install/update workflows using the `.workflow-patcher.yml` (if desired) |
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--name", # Changed to singular |
There was a problem hiding this comment.
I think as a source comment this isn't too valuable as
- developers of the PTB are only interested in the latest state (= singular) and would look for older implementation states rather via
git diffetc. - users will not look at the source code
Could we move it to the changelog / release notes?
There was a problem hiding this comment.
I also propose renaming the command from workflow:update to workflows:generate.
Rationale
- In general and to my experience most frequent use case it's about plural (default
allworkflows) - To me, "generate" implies updating in case the target already exists. And I also assume we have a default to not overwrite existing files if option
--confirmis not specified.
Additionally:
Could we maybe have the workflow names as simple posargs rather than arguing about whether option "--name" should be singular or plural?
If we want to force users to explicitly agree to generate / update / or overwrite all workflows we could have a cli option --all that avoids mentioning the affected workflows explicitly.
| @nox.session(name="workflow:update", python=False) | ||
| def update_workflow(session: Session) -> None: | ||
| """ | ||
| Update (or install if it's not yet existing) one or all generated GitHub workflow(s) |
There was a problem hiding this comment.
| Update (or install if it's not yet existing) one or all generated GitHub workflow(s) | |
| Generate or update the specified GitHub workflow or all of them. |
| parser = _create_parser() | ||
| args = parser.parse_args(session.posargs) | ||
|
|
||
| # Ensure that the GitHub workflow directory exists |
There was a problem hiding this comment.
| # Ensure that the GitHub workflow directory exists |
| return parser | ||
|
|
||
|
|
||
| @nox.session(name="workflow:update", python=False) |
There was a problem hiding this comment.
| @nox.session(name="workflow:update", python=False) | |
| @nox.session(name="workflows:generate" python=False) |
| ): | ||
| with bound_contextvars(template_file_name=file_path.name): | ||
| logger.info("Load workflow from template") | ||
| logger.info(f"Load workflow template: {file_path.name}") |
There was a problem hiding this comment.
| logger.info(f"Load workflow template: {file_path.name}") | |
| logger.info(f"Load workflow template: %s", file_path.name) |
| workflow = workflow_renderer.render() | ||
| return cls(content=workflow) | ||
| except YamlError as ex: | ||
| except (YamlError, YamlKeyError) as ex: |
There was a problem hiding this comment.
YamlError is the parent class, so maybe this one is sufficient then?
| except (YamlError, YamlKeyError) as ex: | |
| except YamlError as ex: |
| def write_to_file(self, file_path: Path) -> None: | ||
| logger.info(f"Write out workflow: {file_path.name}", file_path=file_path) | ||
| file_path.write_text(self.content + "\n") |
There was a problem hiding this comment.
| def write_to_file(self, file_path: Path) -> None: | |
| logger.info(f"Write out workflow: {file_path.name}", file_path=file_path) | |
| file_path.write_text(self.content + "\n") | |
| def write_to_file(self, path: Path) -> None: | |
| logger.info(f"Writing workflow file %s", path.name) | |
| path.write_text(self.content + "\n") |
| return {workflow_name: WORKFLOW_TEMPLATE_OPTIONS[workflow_name]} | ||
|
|
||
|
|
||
| def update_selected_workflow(workflow_name: WorkflowName, config: BaseConfig) -> None: |
There was a problem hiding this comment.
| def update_selected_workflow(workflow_name: WorkflowName, config: BaseConfig) -> None: | |
| def update_workflow(workflow_name: WorkflowName, config: BaseConfig) -> None: |
| def _select_workflow_template(workflow_name: WorkflowName) -> Mapping[str, Path]: | ||
| """ | ||
| Returns a mapping of a workflow template or of all workflow templates. | ||
| """ | ||
| if workflow_name == ALL: | ||
| return WORKFLOW_TEMPLATE_OPTIONS | ||
| return {workflow_name: WORKFLOW_TEMPLATE_OPTIONS[workflow_name]} |
There was a problem hiding this comment.
I think the more general use case is plural, in rare cases n can be 1.
Could we use a simple dict as return data type?
I also doubt whether indexing the workflow paths by name (uniqueness comes from the OS file system and is based on the assumption that all files are in the same directory.) makes sense.
- Maybe it would be better representing workflows simply as a list of paths?
- I don't know for what we need the name of each workflow?
- instead of storing the name separately (as key) maybe a getter would be more helpful / flexible? The getter could be as simple as
lambda path: path.name.
| def _select_workflow_template(workflow_name: WorkflowName) -> Mapping[str, Path]: | |
| """ | |
| Returns a mapping of a workflow template or of all workflow templates. | |
| """ | |
| if workflow_name == ALL: | |
| return WORKFLOW_TEMPLATE_OPTIONS | |
| return {workflow_name: WORKFLOW_TEMPLATE_OPTIONS[workflow_name]} | |
| def _select_workflow_templates(workflow_name: WorkflowName) -> Mapping[str, Path]: | |
| """ | |
| Returns a mapping of workflow names to paths. | |
| Can be a single item or all workflow templates. | |
| """ | |
| if workflow_name == ALL: | |
| return WORKFLOW_TEMPLATE_OPTIONS | |
| return {workflow_name: WORKFLOW_TEMPLATE_OPTIONS[workflow_name]} |



closes #719
Checklist
Note: If any of the items in the checklist are not relevant to your PR, just check the box.
For any Pull Request
Is the following correct:
When Changes Were Made
Did you:
When Preparing a Release
Have you: