Skip to content

Commit 08183b1

Browse files
committed
Update Python version handling and add tests. Fixes #27.
- Refactor version retrieval in simplesam.py and pileup.py to use importlib.metadata. - Update GitHub Actions workflow to test against newer Python versions and exclude certain versions on macOS. - Add test for version import functionality.
1 parent e7c2646 commit 08183b1

5 files changed

Lines changed: 35 additions & 8 deletions

File tree

.github/workflows/tests.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,29 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313

1414
strategy:
15+
fail-fast: false
16+
max-parallel: 10
1517
matrix:
16-
python: [3.6.15, 3.7.12, 3.8.12, 3.9.10, 3.10.2]
18+
python-version: ['3.13', '3.12', '3.11', '3.10', '3.9']
1719
os: [ubuntu-latest, macos-latest]
20+
exclude:
21+
# mac os: exclude all but the last two (available) python releases
22+
- os: macos-latest
23+
python-version: 3.11
24+
- os: macos-latest
25+
python-version: 3.10
26+
- os: macos-latest
27+
python-version: 3.9
1828

1929
steps:
2030
- name: Checkout
21-
uses: actions/checkout@v2.3.1
31+
uses: actions/checkout@v3.1.0
2232
with:
2333
persist-credentials: false
2434
fetch-depth: 0
2535

26-
- name: Setup Python
27-
uses: actions/setup-python@v2
36+
- name: Setup python
37+
uses: actions/setup-python@v4.3.0
2838
with:
2939
python-version: ${{ matrix.python }}
3040

scripts/pileup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import sys
44
import argparse
5-
import pkg_resources
5+
try:
6+
from importlib.metadata import version
7+
except ImportError:
8+
import pkg_resources
9+
version = lambda name: pkg_resources.get_distribution(name).version
610
from collections import deque
711
from collections import Counter
812
from collections import OrderedDict
@@ -80,7 +84,7 @@ def pileup(args):
8084

8185
def main():
8286
parser = argparse.ArgumentParser(prog='pileup', description="generate a simple pileup-like file from a sorted/indexed BAM file")
83-
parser.add_argument('--version', action='version', version="%(prog)s version {0}".format(pkg_resources.get_distribution("simplesam").version))
87+
parser.add_argument('--version', action='version', version="%(prog)s version {0}".format(version("simplesam")))
8488

8589
parser.add_argument('bam', type=argparse.FileType('r'), help="sorted/indexed BAM file ")
8690
parser.add_argument('pileup', type=argparse.FileType('w'), help="pileup output file")

simplesam.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@
2020
from io import TextIOWrapper
2121
import re
2222
from six import PY3, string_types
23-
from pkg_resources import get_distribution
23+
try:
24+
from importlib.metadata import version
25+
except ImportError:
26+
from pkg_resources import get_distribution
27+
version = lambda name: get_distribution(name).version
2428

2529
try:
2630
from multiprocessing.dummy.connection import Connection
2731
except ImportError: #python2
2832
from _multiprocessing import Connection
2933

30-
__version__ = get_distribution("simplesam").version
34+
__version__ = version("simplesam")
3135

3236
class DefaultOrderedDict(OrderedDict):
3337
def __init__(self, default, items=[]):

tests/__init__.py

Whitespace-only changes.

tests/test_version.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import simplesam
2+
3+
4+
def test_version_import():
5+
"""Test that simplesam can be imported and has a version."""
6+
# This test ensures that the version retrieval works without pkg_resources errors
7+
assert hasattr(simplesam, '__version__')
8+
assert isinstance(simplesam.__version__, str)
9+
assert len(simplesam.__version__) > 0

0 commit comments

Comments
 (0)