fix: make identity_attributes/source_path_attributes classmethods#15
Conversation
These were defined as instance methods (self), but the interface base and the other plugins (conda, container) declare them as @classmethod (cls). As instance methods they broke __hash__ (managed_identity_attributes calls cls.identity_attributes()), so any envmodules spec crashed when used as a dict key -- e.g. in the fallback chain `envmodules(...) or conda(...)`, where get_env() looks the spec up in specs_to_envs. The bodies do not use self, so making them classmethods is a drop-in fix.
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughEnvSpec attribute providers were converted to class methods. Tests were added for EnvSpec formatting, identity, hashing, shell command decoration, hash recording, and software reporting. ChangesEnvSpec and Env behavior
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@jiangyun-fun do you want to add some additional tests to raise the coverage? |
Adds unit tests for EnvSpec (names, __str__, identity_attributes, source_path_attributes, __hash__/__eq__, dict-key usability) and the pure Env methods (decorate_shellcmd, record_hash, report_software). The hash tests guard the classmethod fix. Coverage rises from 64.86% to 83.78%, clearing the fail-under=70 gate. Env.check/__post_init__/contains_executable stay uncovered as they require a live `module` command.
|
Thanks, @johanneskoester! Done as requested — coverage is now ~84% (clears the gate); the hash tests guard the classmethod fix. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_plugin.py`:
- Around line 99-108: The test in test_envspec_hash_and_equality_use_names is
asserting a stronger hash contract than Python guarantees by checking hash(a) !=
hash(c) for unequal objects. Remove that assertion and update the test to
validate distinctness through the existing equality semantics in _spec and
EnvSpec hashing, for example by asserting the set size for a, b, and c instead
of requiring different hash values for non-equal instances.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1d1fde9e-4aba-4bb7-850b-cb2aa54d3b7c
📒 Files selected for processing (2)
src/snakemake_software_deployment_plugin_envmodules/__init__.pytests/test_plugin.py
Removed the test for reporting empty software in the environment.
🤖 I have created a release *beep* *boop* --- ## [0.2.1](v0.2.0...v0.2.1) (2026-06-28) ### Bug Fixes * make identity_attributes/source_path_attributes classmethods ([#15](#15)) ([58af01a](58af01a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Problem
EnvSpec.identity_attributesandEnvSpec.source_path_attributesare defined as instance methods (self), but the interface base (snakemake_interface_software_deployment_plugins.EnvSpecBase) and the sibling plugins (conda, container) declare them as@classmethod(cls).Impact
EnvSpecBase.__hash__->managed_identity_attributes()(a classmethod) callscls.identity_attributes(). Because this plugin'sidentity_attributesis an instance method, that call raises:So every envmodules spec is unhashable. Anywhere a spec is used as a dict key or set member it crashes — in particular
SoftwareDeploymentManager.get_env()doesif env_spec in self.specs_to_envs:, which hashes the spec. This breaks standaloneenvmodules(...)usage and the fallback chainenvmodules(...) or conda(...)(the headline composition form).Fix
Make both methods
@classmethod, matching the interface and the other plugins:Neither body uses
self, so this is a drop-in fix.Verification
After the change, envmodules specs are hashable (
hash(spec)succeeds) andget_env()no longer crashes on the fallback path.Context: snakemake/snakemake#4209; related interface fix: snakemake/snakemake-interface-software-deployment-plugins#58.
Summary by CodeRabbit