Repository navigation
use ContextFromEnv() as the base context when args are passed - #466
Merged
Merged
Conversation
Commit 4e7ac7a restored pre-0.23.0 behaviour for the zero-args call path, but the with-args path still starts from context.TODO() and silently drops environment variables like GHW_CHROOT, GHW_DISABLE_WARNINGS, and GHW_DISABLE_TOOLS. In pre-0.23.0 ghw, option.Merge always called EnvOrDefaultChroot() (and its siblings) as defaults regardless of which options the caller passed, so e.g. `block.New(WithDisableTools())` still picked up GHW_CHROOT. The 0.23.0 refactor lost that, breaking downstream callers that set the env var and expected it to compose with other options. A common pattern is test mocks that export GHW_CHROOT and rely on consumers (including indirect ones via libraries that call block.New with a couple of modifiers) to honour it. Use ContextFromEnv() as the base inside ContextFromArgs so env-derived values survive unless overridden by an explicit Modifier, Option, or context.Context arg. Includes regression tests covering each of: Modifier-only args, WithChroot override of env, old-style option.WithChroot override of env, and explicit context.Context replacement of the env-derived base. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
jaypipes
approved these changes
May 14, 2026
jaypipes
left a comment
Owner
There was a problem hiding this comment.
@jimmykarily heyo! thank you very much for this submission (and the corresponding unit test). much appreciated! :)
dims
added a commit
to dims/rdma_topo
that referenced
this pull request
May 14, 2026
PR jaypipes/ghw#466 ("use ContextFromEnv() as the base context when args are passed") fixes a regression where pci.New(opts...) silently dropped GHW_CHROOT and similar env vars. Bump ghw to the merge commit and switch our own ctx construction to start from ghw.ContextFromEnv() so the same env vars survive into the ctx we hand to BuildTopology for VPD reads. main.go now builds one ctx (ContextFromEnv -> optional --chroot -> WithDisableTopology) and threads it through both pci.New and BuildTopology, removing the parallel option.WithChroot path in loadPCI. The pre-flight sysfs stat resolves the effective root with the same precedence ghw uses internally: --chroot beats GHW_CHROOT beats "/sys". Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit 4e7ac7a restored pre-0.23.0 behaviour for the zero-args call path, but the with-args path still starts from context.TODO() and silently drops environment variables like GHW_CHROOT, GHW_DISABLE_WARNINGS, and GHW_DISABLE_TOOLS.
In pre-0.23.0 ghw, option.Merge always called EnvOrDefaultChroot() (and its siblings) as defaults regardless of which options the caller passed, so e.g.
block.New(WithDisableTools())still picked up GHW_CHROOT. The 0.23.0 refactor lost that, breaking downstream callers that set the env var and expected it to compose with other options. A common pattern is test mocks that export GHW_CHROOT and rely on consumers (including indirect ones via libraries that call block.New with a couple of modifiers) to honour it.Use ContextFromEnv() as the base inside ContextFromArgs so env-derived values survive unless overridden by an explicit Modifier, Option, or context.Context arg.
Includes regression tests covering each of: Modifier-only args, WithChroot override of env, old-style option.WithChroot override of env, and explicit context.Context replacement of the env-derived base.
NOTE: debugged and co-authored with Claude AI