Skip to content

Fix conditional platforms and logging#475

Merged
marcoesters merged 8 commits into
conda:mainfrom
larsoner:conditional
May 1, 2026
Merged

Fix conditional platforms and logging#475
marcoesters merged 8 commits into
conda:mainfrom
larsoner:conditional

Conversation

@larsoner
Copy link
Copy Markdown
Contributor

Description

Closes #463
Closes #464

Turns out the issue was a gap in testing and logic: current tests were only "all plugins enabled for the same set of platforms" (which could be all platforms, or a subset of platforms). Once I added a test for "some plugins enabled for not all platforms, some enabled for all platforms" the problem became clear.

I also added logging of the menu and menuitem name in the warnings.

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

Related PR also opened for conda in conda/conda#16000

@larsoner larsoner requested a review from a team as a code owner April 30, 2026 19:17
Comment thread tests/test_api.py
# And now some more complete tests:

# No platforms
datafile = str(DATA / "jsons" / "no-platforms.json")
Copy link
Copy Markdown
Contributor Author

@larsoner larsoner Apr 30, 2026

Choose a reason for hiding this comment

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

A git grep no-platforms suggests that this existing file was unused, so I added a little test for it.

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.

I like the tests, but can we write separate functions for each scenario? That would make individual failures easier to spot.

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Apr 30, 2026
Copy link
Copy Markdown
Contributor

@lrandersson lrandersson left a comment

Choose a reason for hiding this comment

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

Thanks for your fix @larsoner (Go blue!), I just have some minor comments and I think in general this looks good!

Comment thread menuinst/platforms/win.py Outdated
settings["profiles"]["list"].append(profile_data)
else:
log.warning(f"Overwriting terminal profile for {name}.")
log.warning(f"{self._log_name}: Overwriting terminal profile for {name}.")
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.

Suggested change
log.warning(f"{self._log_name}: Overwriting terminal profile for {name}.")
log.warning("%s: Overwriting terminal profile for %s.", self._log_name, name)

I see that it was an f-string before your change but just for consistency with above.

Comment thread menuinst/api.py Outdated
Comment on lines +100 to +101
if menu_item.enabled_for_platform():
paths += menu_item.remove()
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.

I think we need to the same logic also in the code below this part where we currently have:

    if not paths and _maybe_try_user(target_prefix, base_prefix):
        menu, menu_items = _load(metadata_or_path, target_prefix, base_prefix, "user")
        for menu_item in menu_items:
            paths += menu_item.remove()
        paths += menu.remove()

It might not be that easy to test either because I think the tests are not running as an admin and user_is_admin needs to be mocked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh I see, I'll at least push the fix

Copy link
Copy Markdown
Contributor

@marcoesters marcoesters Apr 30, 2026

Choose a reason for hiding this comment

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

Alternatively, instead of adding the check everywhere, we could filter out the menu items at the beginning of the function:

menu, menu_items = _load(metadata_or_path, target_prefix, base_prefix, _mode)
menu_items = [item.enabled_for_platform() for item in menu_items]
if not menu_items:
        warnings.warn(f"Metadata for {menu.name} is not enabled for {sys.platform}")
        return []

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's much cleaner!

Copy link
Copy Markdown
Contributor

@marcoesters marcoesters left a comment

Choose a reason for hiding this comment

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

Very nice, thank you for the fix! Just a few minor comments.

Comment thread news/475-platform-conditional Outdated
Comment thread news/475-platform-conditional Outdated
Comment thread menuinst/api.py Outdated
Comment on lines +100 to +101
if menu_item.enabled_for_platform():
paths += menu_item.remove()
Copy link
Copy Markdown
Contributor

@marcoesters marcoesters Apr 30, 2026

Choose a reason for hiding this comment

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

Alternatively, instead of adding the check everywhere, we could filter out the menu items at the beginning of the function:

menu, menu_items = _load(metadata_or_path, target_prefix, base_prefix, _mode)
menu_items = [item.enabled_for_platform() for item in menu_items]
if not menu_items:
        warnings.warn(f"Metadata for {menu.name} is not enabled for {sys.platform}")
        return []

Comment thread tests/test_api.py
# And now some more complete tests:

# No platforms
datafile = str(DATA / "jsons" / "no-platforms.json")
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.

I like the tests, but can we write separate functions for each scenario? That would make individual failures easier to spot.

larsoner and others added 2 commits April 30, 2026 16:54
Co-authored-by: Marco Esters <mesters@anaconda.com>
@larsoner
Copy link
Copy Markdown
Contributor Author

Pushed the suggested changes, thanks for the quick reviews @lrandersson @marcoesters !

Comment thread tests/test_api.py Outdated
Copy link
Copy Markdown
Contributor

@marcoesters marcoesters left a comment

Choose a reason for hiding this comment

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

LGTM, assuming the tests pass.

@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Approved in 🔎 Review Apr 30, 2026
@marcoesters marcoesters merged commit 75da8a5 into conda:main May 1, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from ✅ Approved to 🏁 Done in 🔎 Review May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed [bot] added once the contributor has signed the CLA

Projects

Status: 🏁 Done

Development

Successfully merging this pull request may close these issues.

Add shortcut file name to logging and exception outputs KeyError in Windows install for shortcut only defined for Linux

4 participants