Skip to content

packagedcode: add CondaEnvironmentYmlHandler to parse environment.yml - #4804

Closed
kumarasantosh wants to merge 1 commit into
aboutcode-org:developfrom
kumarasantosh:feature/conda-environment-yml
Closed

kumarasantosh wants to merge 1 commit into
aboutcode-org:developfrom
kumarasantosh:feature/conda-environment-yml

Conversation

@kumarasantosh

@kumarasantosh kumarasantosh commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #3694

Conda environment.yml files were not being parsed by ScanCode at all.
This PR adds CondaEnvironmentYmlHandler in conda.py to fix that.

The handler picks up *environment.yml files and pulls out the
environment name, channels and conda dependencies with their versions.
It also handles the pip section inside dependencies and marks those
packages correctly as pypi type. Channels go into extra_data.

Tested with a real fixture from the multiregex project and a simple
hand-crafted one to cover edge cases like missing name or empty
dependencies.

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled and links the original issue above
  • Tests pass
  • Commits are in uniquely-named feature branch and has no merge conflicts

Add support for parsing Conda environment.yml files which contain
environment name, channels, conda dependencies with versions and
nested pip dependencies.

Fixes aboutcode-org#3694

Signed-off-by: kumarasantosh <santosh.pulikond02@gmail.com>
@kumarasantosh

kumarasantosh commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

@pombredanne

The two failing checks (core_tests misc_and_scancode) look like
a pre-existing issue — #4732 is failing with the same thing.

My changes only touch conda.py, test_conda.py and the fixture files
so shouldn't be related.

I would really appreciate your feedback on this if you have time!

Thanks!

@AyanSinhaMahapatra AyanSinhaMahapatra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Closing this PR as the code is not usable at all as the functionality already exists to some extent and might need updating, not completely new code. Even without that, this code was not mergable.'

Please open a new PR if you have some usable code which improves functionality

Comment thread src/packagedcode/conda.py
return result


class CondaEnvironmentYmlHandler(BaseDependencyFileHandler):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have you actually looked at the code/run a scan on the test file to see this is not already detected somewhat?
See https://github.com/aboutcode-org/scancode-toolkit/blob/develop/src/packagedcode/conda.py#L357 where we already support this (but this needs enhancement of course)

Yes we should have updated/closed #3694 when this was added, but you should always do basic checks and read the code before writing code blindly.

@@ -0,0 +1,63 @@
import os

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not how we run tests, see https://github.com/aboutcode-org/scancode-toolkit/blob/develop/tests/packagedcode/test_conda.py, where we have sample tests, and that is where the new tests will live.

@@ -0,0 +1,9 @@
name: testenv

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to use real examples seen in the wild, not made up examples.
See examples already in https://github.com/aboutcode-org/scancode-toolkit/tree/develop/tests/packagedcode/data/conda/conda-yaml

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.

Add support for Conda environment.yml

2 participants