Skip to content

Users/elebel/context managers - #2259

Open
elebel-emerson wants to merge 3 commits into
ni:masterfrom
elebel-emerson:users/elebel/ContextManagers
Open

elebel-emerson wants to merge 3 commits into
ni:masterfrom
elebel-emerson:users/elebel/ContextManagers

Conversation

@elebel-emerson

@elebel-emerson elebel-emerson commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
  • This contribution adheres to CONTRIBUTING.md.

  • I've updated CHANGELOG.md if applicable.

    Not a client-facing change: generated code for all shipping drivers is unchanged.

  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

Allows a driver to define more than one session context manager (initiate/abort pair) in its metadata.

  • config['context_manager_name'] may now be either a single dict (existing format, unchanged for all current drivers) or a list of dicts.
  • Each entry accepts an optional method_name key for the public method that returns the context manager. It defaults to initiate, so existing behavior is preserved.
  • Added helper.filter_context_managers(config), which normalizes the config to a list and drops empty entries (e.g. nitclk's {}).
  • session.py.mako:
    • Renamed session_context_manager to context_managers, since the old name suggested the context manager returned by Session.__init__().
    • Generates one context manager class per entry.
    • Replaced the two duplicated initiate() blocks (_SessionBase vs. Session, chosen by the initiate function's render_in_session_base) with loops.
  • helper.initiate_function_def_for_doc() now takes a single context manager entry instead of the whole config, and uses its method_name. class.rst.mako and nitclk's class.rst.mako add one doc entry per context manager.
  • nifake now defines two context managers to exercise the list form:
    • The existing acquisition (Initiate/Abort, method initiate(), rendered on Session).
    • A new generation (InitiateGeneration/AbortGeneration, method initiate_generation(), rendered on _SessionBase). These two functions are not included in the proto.

List issues fixed by this Pull Request below, if any.

None.

What testing has been done?

  • niFake has been updated and passing changes
  • No unexpected changes when building with tox
  • No changes to current context managers

elebel-emerson and others added 2 commits November 4, 2026 16:05
context_manager_name may now be a dict or a list of dicts, each with an optional method_name (default: initiate).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@codecov-commenter

codecov-commenter commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.13%. Comparing base (72c2856) to head (b93fae5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
generated/nifake/nifake/_grpc_stub_interpreter.py 50.00% 2 Missing ⚠️
build/helper/documentation_snippets.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2259      +/-   ##
==========================================
+ Coverage   88.12%   88.13%   +0.01%     
==========================================
  Files          88       88              
  Lines       22830    22854      +24     
==========================================
+ Hits        20118    20142      +24     
  Misses       2712     2712              
Flag Coverage Δ
codegenunittests 84.88% <92.30%> (+0.09%) ⬆️
nidcpowersystemtests 94.40% <ø> (+0.04%) ⬆️
nidcpowerunittests 89.53% <ø> (ø)
nidigitalsystemtests 92.04% <ø> (ø)
nidigitalunittests 68.43% <ø> (ø)
nidmmsystemtests 92.33% <ø> (ø)
nifakeunittests 86.14% <90.00%> (+0.05%) ⬆️
nifgensystemtests 94.34% <ø> (ø)
nimodinstsystemtests 73.85% <ø> (ø)
nimodinstunittests 94.20% <ø> (ø)
nirfsasystemtests 82.71% <ø> (ø)
nirfsaunittests 63.37% <ø> (ø)
nirfsgsystemtests 81.22% <ø> (ø)
niscopesystemtests 89.99% <ø> (ø)
niscopeunittests 43.20% <ø> (ø)
nisesystemtests 91.50% <ø> (ø)
niswitchsystemtests 81.66% <ø> (ø)
nitclksystemtests 94.87% <ø> (ø)
nitclkunittests 98.26% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@elebel-emerson

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 2259 in repo ni/nimi-python

@elebel-emerson
elebel-emerson marked this pull request as ready for review November 5, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants