Skip to content

Conversation

@dgarros
Copy link
Contributor

@dgarros dgarros commented Apr 7, 2025

Fixes #329

This PR includes a few enhancements and fixes around Python Protocols

  • Move the code and the template into a dedicated directory
  • Add unit tests
  • Fix support for Sync
  • Add support for object Template
  • Add guide to use Protocols

This PR also adds some invoke commands to help with the docs

  • invoke lint-doc
  • invoke lint-vale
  • invoke lint-markdownlint

If vale and/or markdownlint-cli2 are not installed, these commands will be skipped

@github-actions github-actions bot added the type/documentation Improvements or additions to documentation label Apr 7, 2025
@codecov
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/protocols_generator/generator.py 93.10% 1 Missing and 1 partial ⚠️
@@             Coverage Diff             @@
##           develop     #348      +/-   ##
===========================================
+ Coverage    72.45%   73.04%   +0.59%     
===========================================
  Files           91       92       +1     
  Lines         8180     8200      +20     
  Branches      1576     1583       +7     
===========================================
+ Hits          5927     5990      +63     
+ Misses        1841     1797      -44     
- Partials       412      413       +1     
Flag Coverage Δ
integration-tests 22.28% <0.00%> (-0.06%) ⬇️
python-3.10 47.20% <93.93%> (+0.66%) ⬆️
python-3.11 47.20% <93.93%> (+0.69%) ⬆️
python-3.12 47.23% <93.93%> (+0.69%) ⬆️
python-3.13 47.20% <93.93%> (+0.66%) ⬆️
python-3.9 45.55% <93.93%> (+0.67%) ⬆️
python-filler-3.12 25.03% <0.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/cli_commands.py 68.59% <100.00%> (ø)
infrahub_sdk/protocols_generator/constants.py 100.00% <100.00%> (ø)
infrahub_sdk/schema/repository.py 83.33% <ø> (ø)
infrahub_sdk/protocols_generator/generator.py 95.00% <93.10%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dgarros dgarros force-pushed the dga-20250407-protocols branch from fbbef32 to 38b3719 Compare April 13, 2025 11:00
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 13, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: d107906
Status: ✅  Deploy successful!
Preview URL: https://65a2327a.infrahub-sdk-python.pages.dev
Branch Preview URL: https://dga-20250407-protocols.infrahub-sdk-python.pages.dev

View logs

@dgarros dgarros marked this pull request as ready for review April 13, 2025 11:06
@dgarros dgarros requested review from a team April 13, 2025 11:06
@dgarros dgarros force-pushed the dga-20250407-protocols branch from 38b3719 to 785fe6e Compare April 13, 2025 13:37
jinja2_env.filters["syncify"] = self._jinja2_filter_syncify

template = jinja2_env.from_string(PROTOCOLS_TEMPLATE)
template = jinja2_env.from_string(load_template())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to change this in this PR but I think it would make sense to the templating logic we have elsewhere within the SDK to render these templates. Possibly we should come to a final decision regarding #337 first if we should leave it as async by default or not.

@task
def lint_vale(context: Context) -> None:
"""Run vale to check all documentation files."""
if not is_tool_installed("vale"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about these is_tool_installed, it feels like we at some point could get into a situation where we're just running the lint_all command and we move around something so that these tools aren't installed. Then we wouldn't notice it in the pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone doesn't have the right tools installed, the pipeline will still catch the issue right now.

These methods are mainly for us to make it easier to validate a branch locally but since not everyone will need them I would prefer to not require everyone to install vale & markdownlint-cli2

)
async def test_filter_syncify(sync, input, output):
assert CodeGenerator._jinja2_filter_syncify(value=input, sync=sync) == output
assert CodeGenerator._jinja2_filter_syncify(value=input, sync=sync) == output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked this pattern of setting up dataclasses for the test cases, I think it adds clarity with regards to what the expected input fields are along with the possibility to give each test a relevant name.

https://github.com/opsmill/infrahub-sdk-python/blob/v1.10.2/tests/unit/sdk/test_template.py#L45-L81

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point I've updated the test

@dgarros dgarros force-pushed the dga-20250407-protocols branch from 785fe6e to d107906 Compare April 14, 2025 09:40
@dgarros dgarros merged commit de2662a into develop Apr 14, 2025
18 checks passed
@dgarros dgarros deleted the dga-20250407-protocols branch April 14, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants