Skip to content

Commit 3094feb

Browse files
Add version tracking
Closes #16
1 parent 535687e commit 3094feb

File tree

8 files changed

+35
-7
lines changed

8 files changed

+35
-7
lines changed

bio2zarr/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
from .vcf import explode as explode_vcf
1+
from . provenance import __version__

bio2zarr/__main__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
from . import cli
44

5+
@cli.version
56
@click.group()
6-
def top_level():
7+
def bio2zarr():
78
pass
89

910
# Provide a single top-level interface to all of the functionality.
1011
# This probably isn't the recommended way of interacting, as we
1112
# install individual commands as console scripts. However, this
1213
# is handy for development and for those whose PATHs aren't set
1314
# up in the right way.
14-
top_level.add_command(cli.vcf2zarr)
15-
top_level.add_command(cli.plink2zarr)
15+
bio2zarr.add_command(cli.vcf2zarr)
16+
bio2zarr.add_command(cli.plink2zarr)
1617

1718
if __name__ == "__main__":
18-
top_level()
19+
bio2zarr()

bio2zarr/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from . import vcf
66
from . import plink
7+
from . import provenance
78

89
# Common arguments/options
910
verbose = click.option("-v", "--verbose", count=True, help="Increase verbosity")
@@ -12,6 +13,7 @@
1213
"-p", "--worker-processes", type=int, default=1, help="Number of worker processes"
1314
)
1415

16+
version = click.version_option(version=provenance.__version__)
1517

1618
# Note: logging hasn't been implemented in the code at all, this is just
1719
# a first pass to try out some ways of doing things to see what works.
@@ -111,6 +113,7 @@ def validate(vcfs, out_path):
111113
vcf.validate(vcfs[0], out_path, show_progress=True)
112114

113115

116+
@version
114117
@click.group()
115118
def vcf2zarr():
116119
pass
@@ -145,6 +148,7 @@ def convert_plink(in_path, out_path, worker_processes, chunk_width, chunk_length
145148
)
146149

147150

151+
@version
148152
@click.group()
149153
def plink2zarr():
150154
pass

bio2zarr/provenance.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__version__ = "undefined"
2+
try:
3+
from . import _version
4+
5+
__version__ = _version.version
6+
except ImportError: # pragma: nocover
7+
pass

bio2zarr/vcf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import zarr
2424

2525
from . import core
26+
from . import provenance
2627

2728
logger = logging.getLogger(__name__)
2829

@@ -1287,6 +1288,7 @@ def convert(
12871288

12881289
sgvcf.root.attrs["vcf_zarr_version"] = "0.2"
12891290
sgvcf.root.attrs["vcf_header"] = pcvcf.vcf_header
1291+
sgvcf.root.attrs["source"] = f"bio2zarr-{provenance.__version__}"
12901292

12911293
progress_config = core.ProgressConfig(
12921294
total=pcvcf.total_uncompressed_bytes,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
# The package name along with all the other metadata is specified in setup.cfg
66
# However, GitHub's dependency graph can't see the package unless we put this here.
77
name="bio2zarr",
8-
use_scm_version=True,
8+
use_scm_version={"write_to": "bio2zarr/_version.py"},
99
)

tests/test_cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from unittest import mock
22

3+
import pytest
34
import click.testing as ct
45

56
from bio2zarr import cli
7+
from bio2zarr import __main__ as main
8+
from bio2zarr import provenance
69

710

811
class TestWithMocks:
@@ -117,3 +120,11 @@ def test_convert_plink(self):
117120
chunk_length=None,
118121
show_progress=True,
119122
)
123+
124+
125+
@pytest.mark.parametrize("cmd", [main.bio2zarr, cli.vcf2zarr, cli.plink2zarr])
126+
def test_version(cmd):
127+
runner = ct.CliRunner(mix_stderr=False)
128+
result = runner.invoke(cmd, ["--version"], catch_exceptions=False)
129+
s = f"version {provenance.__version__}\n"
130+
assert result.stdout.endswith(s)

tests/test_vcf_examples.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cyvcf2
77

88
from bio2zarr import vcf
9+
from bio2zarr import provenance
910

1011

1112
class TestSmallExample:
@@ -38,6 +39,9 @@ def test_header(self, ds):
3839
vcf = cyvcf2.VCF(self.data_path)
3940
assert ds.attrs["vcf_header"] == vcf.raw_header
4041

42+
def test_source(self, ds):
43+
assert ds.attrs["source"] == f"bio2zarr-{provenance.__version__}"
44+
4145
def test_contigs(self, ds):
4246
nt.assert_array_equal(ds["contig_id"], ["19", "20", "X"])
4347
assert "contig_length" not in ds

0 commit comments

Comments
 (0)