Skip to content

maint: YAML environment specification utilities#4158

Open
jjerphan wants to merge 2 commits intomamba-org:mainfrom
jjerphan:maint/yaml-utils
Open

maint: YAML environment specification utilities#4158
jjerphan wants to merge 2 commits intomamba-org:mainfrom
jjerphan:maint/yaml-utils

Conversation

@jjerphan
Copy link
Member

@jjerphan jjerphan commented Feb 5, 2026

Description

Per-requisite for #4153.

Type of Change

  • Bugfix
  • Feature / enhancement
  • CI / Documentation
  • Maintenance

Checklist

  • My code follows the general style and conventions of the codebase, ensuring consistency
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have run pre-commit run --all locally in the source folder and confirmed that there are no linter errors.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

@github-actions github-actions bot added the release::maintenance For PRs related to maintenance label Feb 5, 2026
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 54.80769% with 141 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.15%. Comparing base (7603af9) to head (c2cea18).

Files with missing lines Patch % Lines
micromamba/src/env.cpp 0.00% 75 Missing ⚠️
libmamba/src/api/environment_yaml.cpp 80.28% 42 Missing ⚠️
libmamba/src/api/export.cpp 0.00% 24 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #4158    +/-   ##
========================================
  Coverage   52.15%   52.15%            
========================================
  Files         239      241     +2     
  Lines       28803    29009   +206     
  Branches     3029     3066    +37     
========================================
+ Hits        15021    15131   +110     
- Misses      13779    13875    +96     
  Partials        3        3            

☔ View full report in Codecov by Sentry.
📢 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.

@jjerphan jjerphan force-pushed the maint/yaml-utils branch 6 times, most recently from 4f44235 to aae4296 Compare February 5, 2026 16:11
@jjerphan jjerphan force-pushed the maint/yaml-utils branch 2 times, most recently from 6cb440d to e1dc8a2 Compare February 23, 2026 11:52
@jjerphan jjerphan marked this pull request as ready for review February 23, 2026 12:06
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Copy link
Member Author

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

Some points of discussions.

Comment on lines +90 to +110
try
{
const auto& channels = channel_context.make_channel(channel_str);
if (!channels.empty())
{
return channels.front().id();
}
}
catch (...)
{
// If resolution fails, try to extract channel name from URL
// e.g., "https://conda.anaconda.org/conda-forge" -> "conda-forge"
if (channel_str.find("conda.anaconda.org/") != std::string::npos)
{
auto parts = util::rsplit(channel_str, '/');
if (parts.size() >= 2)
{
return parts[parts.size() - 1];
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We could benefit from using expected here, but this would be yet another refactor which would impact other files.

What is the best trade-off? Should we open another PR?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that would help with channel_context.make_channel as it is used everywhere as a getter for channel data and it do need to throw as any failure with that call would be a failure.
I prefer to use expected when the error is part of the algorithm, for example as return type for parsing functions (there are other examples).

What I'm not sure of is why is there a try-catch here? "resolution" isnt supposed to happen in make_channel, so I dont get the meaning of the comment in the catch.
Is that why you were thinking of using expected?

Comment on lines +148 to +155
// Helper function: Convert PackageInfo to MatchSpec string
std::string package_to_spec_string(
const specs::PackageInfo& pkg,
ChannelContext& channel_context,
bool no_builds = false,
bool ignore_channels = false,
bool include_md5 = false
)
Copy link
Member Author

Choose a reason for hiding this comment

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

This could be a method on PackageInfo, but it is only used here and there already are similar free functions; so I am not sure that this is worth it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are changes made to this file API breakages?

Comment on lines +311 to +314
catch (nlohmann::json::exception&)
{
// If parsing fails, leave variables empty
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we warn instead here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release::maintenance For PRs related to maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants