docs(connectors): document command wrapping and parameter filtering best practices #1497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds comprehensive guidance to the connector documentation on proper command wrapping and connector control parameter filtering. This addresses a documentation gap that can lead to
TypeErrorexceptions in custom connectors.What's Added
A new section "Implementing
run_shell_command" that covers:make_unix_command_for_host()for proper shell wrapping (essential for shell operators like&&,||, pipes)extract_control_arguments()utility_success_exit_codes,_timeout,_get_pty,_stdin) must be filtered before callingmake_unix_command_for_host()Why This Matters
Without this guidance, custom connector developers may:
make_unix_command_for_host(), causingTypeError: unexpected keyword argumentextract_control_arguments()utilityThis documentation evolved from debugging and fixing parameter handling bugs in the
pyinfra-orbstackthird-party connector.Real-World Impact
This pattern is already used by PyInfra's built-in connectors (docker, dockerssh, chroot), but isn't documented for third-party connector authors. Making this explicit will help prevent bugs and ensure consistency across the connector ecosystem.
Checklist
3.xat this time)scripts/dev-test.sh) (Will run after PR submission)scripts/dev-lint.sh) (Will run after PR submission)Additional Context
The
extract_control_arguments()utility function already exists inpyinfra.connectors.utiland is used by several built-in connectors, but wasn't documented in the connector development guide. This PR makes that pattern explicit and recommended for all custom connectors.Example of the Problem
Without proper parameter filtering:
With the documented pattern: