Skip to content

Modify global context to prevent --help arg capture - #180

Merged
RyanTheRobothead merged 16 commits into
mainfrom
fix_context_cli_help
Dec 5, 2025
Merged

Modify global context to prevent --help arg capture#180
RyanTheRobothead merged 16 commits into
mainfrom
fix_context_cli_help

Conversation

@RyanTheRobothead

@RyanTheRobothead RyanTheRobothead commented Nov 17, 2025

Copy link
Copy Markdown
Member

PR Info

  • Switch madsci global context to lazy loading so it doesn't capture the --help arg nodes/managers/etc

Developer Checklists

I have:

  • Run Pre-commit and Unit Tests, and ensured that they pass
  • Created or updated documentation relevant to your change
  • Created or updated unit tests relevant to your change

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the global context handling in MADSci by replacing the module-level global_madsci_context variable with a GlobalMadsciContext class that uses lazy loading. The goal is to prevent the --help argument from being captured during module import.

Key Changes:

  • Introduced GlobalMadsciContext class with a class attribute _context instead of a module-level variable
  • Updated all test references from global_madsci_context to GlobalMadsciContext._context
  • Modified context initialization to use lazy loading pattern

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/madsci_common/madsci/common/context.py Replaces module-level global_madsci_context with GlobalMadsciContext class containing attempted property/setter implementations
src/madsci_common/tests/test_context.py Updates all test cases to use GlobalMadsciContext._context instead of global_madsci_context, with verbose copy-modify-reassign pattern

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/madsci_common/madsci/common/context.py
Comment thread src/madsci_common/madsci/common/context.py Outdated
Comment thread src/madsci_common/madsci/common/context.py Outdated
Comment thread src/madsci_common/tests/test_context.py Outdated
@github-actions

github-actions Bot commented Nov 17, 2025

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/madsci_common/madsci/common
  context.py 58
Project Total  

This report was generated by python-coverage-comment-action

claude and others added 2 commits November 17, 2025 18:27
…trings

Addresses all review comments on PR #180:

1. Fixed invalid @property/@classmethod decorator stacking (Comments #1 & #2)
   - Removed incompatible property/classmethod combinations
   - Replaced with proper @classmethod get_context() and set_context() methods
   - Maintains clean API while fixing Python decorator compatibility issues

2. Implemented true lazy loading to prevent --help arg capture
   - Changed _context from MadsciContext() to None as initial value
   - Context is now only created on first access via get_context()
   - This solves the original issue where module imports would capture CLI args

3. Fixed docstring formatting per PEP 257 (Comment #3)
   - Multi-line docstring with summary line
   - Blank line separator
   - Detailed description following PEP 257 standards

4. Updated all tests to use new classmethod API
   - All tests now call GlobalMadsciContext.get_context()
   - All tests now call GlobalMadsciContext.set_context()
   - Reduces verbose copy-modify-reassign patterns
   - All 7 tests pass successfully

The changes maintain backward compatibility while implementing proper
lazy initialization that solves the CLI argument capture issue.
…4zhzx93z2hASDDBBnZQVq

Fix PR #180 review issues: decorator stacking, lazy loading, and docs…
@RyanTheRobothead

Copy link
Copy Markdown
Member Author

@copilot please fix the outstanding issues with the pre-commit checks and pytests

Copilot AI commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

@LuckierDodge I've opened a new pull request, #182, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 5 commits November 17, 2025 19:01
Co-authored-by: LuckierDodge <15006408+LuckierDodge@users.noreply.github.com>
Co-authored-by: LuckierDodge <15006408+LuckierDodge@users.noreply.github.com>
Fix Python 3.9 compatibility and formatting for lazy-loaded global context
@RyanTheRobothead RyanTheRobothead self-assigned this Dec 4, 2025
@RyanTheRobothead
RyanTheRobothead merged commit 3a8b411 into main Dec 5, 2025
4 checks passed
@RyanTheRobothead
RyanTheRobothead deleted the fix_context_cli_help branch December 27, 2025 15:03
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.

4 participants