Can anyone recommend best practices around type checking, declaration and enforcement of Pulumi/Python code?
bright-crayon-39468
03/18/2024, 10:44 PM
I know we can introduce pep-0484 type hints and a static analysis type checking tool like mypy... is this the best practice? Are there any pitfalls or other concerns to be aware of?
bright-crayon-39468
03/19/2024, 7:03 AM
I've integrated poetry with taskpi to bootstrap flake8 for linting and mypy for static type checking...
a
adventurous-butcher-54166
03/21/2024, 4:58 PM
After
This is what I've been using in my setup.
• Pyright – Run under the Pylance language server in VScode
• Ruff – with linting and auto formatting on save – btw. it's orders of magnitude faster than Flake8, Pylint etc.
• pre-commit hooks for those as well to ensure type checking and formatting
• Pydantic – For managing and validating basically all provider/stack/resource configurations – I feel like this was the biggest game changer for us in terms of enforcement and validation
If you turn on package type indexing in your IDE for autocompletion and validation you might run into problems with some Pulumi packages as they contain so many symbols. I had to limit indexing to 2 level down (basically leaving out the additional versioned API sub-modules) otherwise VSCode would blow up.
Just be prepared for a pretty steep learning curve on the Pulumi Output and the internal asyncio event loop – I learned it the hard way I guess by reading through the source code after implementing Pydantic validation/serialization in my Pulumi code. Documentation is really lacking there.
🙌 1
👍 1
b
bright-crayon-39468
03/22/2024, 1:54 AM
Thank you @adventurous-butcher-54166 this is great info 🙏
No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.