Skip to content

Document usethis_config global state management#1100

Merged
nathanjmcdougall merged 3 commits intomainfrom
copilot/document-usethis-config-class
Nov 5, 2025
Merged

Document usethis_config global state management#1100
nathanjmcdougall merged 3 commits intomainfrom
copilot/document-usethis-config-class

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 5, 2025

The usethis._config.usethis_config singleton manages global application state (output verbosity, offline mode, backend selection) to avoid threading parameters through deep call stacks. However, its purpose and usage patterns were undocumented, and there was no guidance on when adding new global state is appropriate.

Changes

CONTRIBUTING.md - Architecture section

  • Documents what usethis_config controls (message suppression, network access, frozen mode, backend, etc.)
  • Shows context manager pattern for temporary overrides
  • Illustrates CLI integration and internal usage patterns
  • Establishes guidelines: only add state that affects application behavior across many commands, not command-specific logic

copilot-instructions.md - Architecture section

  • Adds DO/DO NOT rules for global state usage
  • Specifies requirements before adding new state (must be application-wide, not command-specific)
  • Cross-references CONTRIBUTING.md for examples

Example Usage

# CLI commands apply flags via context manager
def my_command(offline: bool = offline_opt, quiet: bool = quiet_opt):
    with usethis_config.set(offline=offline, quiet=quiet):
        do_work()  # Entire execution uses these settings

# Deep functions access config without parameter threading
def internal_function():
    if usethis_config.quiet:
        return  # Skip output

The documentation emphasizes that usethis_config controls application behavior (how output is displayed, whether network is allowed), not business logic of individual commands.

Original prompt

This section details on the original issue you should resolve

<issue_title>Document the usethis_config class better</issue_title>
<issue_description>In usethis._config.usethis_config we keep global state which changes the application behaviour, e.g. whether some categories of messages are suppressed, whether we should run in offline mode, etc.

This can be used as a context manager to temporarily over-ride the global state.

The command line interface can also set some of these global settings via flags (again, via the context manager).

Discussing this in CONTRIBUTING.md under the architecture section would be good.

The main purpose of this is to avoid pass-through variables. In copilot-instructions.md we need to make it clear that it is not acceptable to add new global state unless there is a very good reason and the state is useful across many different commands, across the whole application. The purpose is to control application behaviour, not the specific behaviour of one command in the CLI.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Document the usethis_config class better Document usethis_config global state management Nov 5, 2025
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review November 5, 2025 12:41
@nathanjmcdougall nathanjmcdougall merged commit 99a5ffb into main Nov 5, 2025
@nathanjmcdougall nathanjmcdougall deleted the copilot/document-usethis-config-class branch November 5, 2025 12:41
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.

Document the usethis_config class better

2 participants