Skip to content

feat: make pysam an optional dependency #270

Draft
nh13 wants to merge 2 commits into
mainfrom
feat/optional-pysam-dependency
Draft

feat: make pysam an optional dependency #270
nh13 wants to merge 2 commits into
mainfrom
feat/optional-pysam-dependency

Conversation

@nh13

@nh13 nh13 commented Dec 17, 2025

Copy link
Copy Markdown
Member

Makes pysam an optional dependency so users who only need pure Python utilities can avoid the heavyweight pysam install.

  • pip install fgpyo — core modules only (sequence, read_structure, collections, io, util)
  • pip install fgpyo[pysam] — full functionality (sam, vcf, fastx, fasta)

Modules that require pysam will raise a clear error message:

ImportError: Missing optional dependency 'pysam'. The sam, vcf, fastx, and fasta modules require pysam. Install with: pip install fgpyo[pysam]

Packaging notes:*

  • PyPI: no changes needed
  • Bioconda: recipe should update to pip install .[pysam] so users get full functionality by default

Users can now install fgpyo without pysam for pure Python utilities:
- `pip install fgpyo` - core only
- `pip install fgpyo[pysam]` - full functionality

Modules that require pysam provide clear error messages guiding users
to install the pysam extra.
@clintval

Copy link
Copy Markdown
Member

pysam is a lot easier to install these days and is also load-bearing for some important features of fgpyo. I'm 50/50 on if this is still a good idea.

@msto

msto commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Hey! Noticed this covers the same ground as #238. Were there things about the approach in #238 you wanted to go a different direction on? I'd love to understand your thinking here.

Also curious whether it makes sense to consolidate efforts on one PR so we're not duplicating work. Happy to fold anything useful from #238 into this one, or vice versa, just let me know how you'd like to handle it.

@msto msto assigned nh13 and unassigned msto Apr 8, 2026
@msto

msto commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Going to close #238 in favor of this approach, pending Clint's question on whether this is still worth doing. If it does move forward, a few things I picked up while working through it on my end:

  • The Tests-without-pysam job looks like uv run will re-install pysam on the subsequent calls. I hit this too, uv run re-syncs with default groups unless you pass --no-sync.
  • The requires_pysam marker in conftest is a nice pattern. The pysam-dependent test files still import pysam at the top level though, so they'd error rather than skip without pysam. pytest.importorskip("pysam") at the top of those files might be a lighter way to get the skip behavior.
  • For dev ergonomics, adding a pysam dependency group to [tool.uv]'s default-groups means uv sync still installs pysam locally without needing --extra pysam each time.

Happy to open small PRs against this branch with any of these if that's helpful.

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.

3 participants