Skip to content

Commit

Permalink
Use setuptools_scm for easier version handling (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed authored Jul 8, 2018
1 parent 79009bf commit c8461d9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
covimerage/__version__.py
5 changes: 5 additions & 0 deletions covimerage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
RE_SNR_PREFIX = re.compile(r'^<SNR>\d+_')


def get_version():
from covimerage.__version__ import version
return version


@attr.s
class Line(object):
"""A source code line."""
Expand Down
1 change: 0 additions & 1 deletion covimerage/__version__.py

This file was deleted.

5 changes: 2 additions & 3 deletions covimerage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import click

from . import DEFAULT_COVERAGE_DATA_FILE, MergedProfiles, Profile
from .__version__ import __version__
from . import DEFAULT_COVERAGE_DATA_FILE, MergedProfiles, Profile, get_version
from .coveragepy import CoverageWrapper
from .exceptions import CustomClickException
from .logger import logger
Expand All @@ -16,7 +15,7 @@ def default_loglevel():


@click.group(context_settings={'help_option_names': ['-h', '--help']})
@click.version_option(__version__, '-V', '--version', prog_name='covimerage')
@click.version_option(get_version(), '-V', '--version', prog_name='covimerage')
@click.option('-v', '--verbose', count=True, help='Increase verbosity.')
@click.option('-q', '--quiet', count=True, help='Decrease verbosity.')
@click.option('-l', '--loglevel', show_default=True,
Expand Down
13 changes: 6 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ def read(fname):
return f.read()


# Load the package's __version__.py module as a dictionary.
about = {}
with open(os.path.join(here, 'covimerage', '__version__.py')) as f:
exec(f.read(), about)


class PublishCommand(Command):
"""Support setup.py publish."""

Expand Down Expand Up @@ -72,7 +66,6 @@ def run(self):

setup(
name='covimerage',
version=about['__version__'],
description='Generate coverage information for Vim scripts.',
long_description=read('README.md'),
long_description_content_type='text/markdown',
Expand All @@ -82,6 +75,12 @@ def run(self):
entry_points={
'console_scripts': ['covimerage=covimerage.cli:main'],
},
use_scm_version={
'write_to': 'covimerage/__version__.py',
},
setup_requires=[
'setuptools_scm',
],
install_requires=[
'attrs',
'click',
Expand Down
9 changes: 4 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import pytest

from covimerage import DEFAULT_COVERAGE_DATA_FILE, cli
from covimerage.__version__ import __version__
from covimerage import DEFAULT_COVERAGE_DATA_FILE, cli, get_version
from covimerage._compat import StringIO


Expand All @@ -18,7 +17,7 @@ def test_dunder_main_run(capfd):
def test_dunder_main_run_help(capfd):
assert call([sys.executable, '-m', 'covimerage', '--version']) == 0
out, err = capfd.readouterr()
assert out == 'covimerage, version %s\n' % __version__
assert out == 'covimerage, version %s\n' % get_version()


def test_cli(runner, tmpdir):
Expand All @@ -38,7 +37,7 @@ def test_cli(runner, tmpdir):
@pytest.mark.parametrize('arg', ('-V', '--version'))
def test_cli_version(arg, runner):
result = runner.invoke(cli.main, [arg])
assert result.output == 'covimerage, version %s\n' % __version__
assert result.output == 'covimerage, version %s\n' % get_version()
assert result.exit_code == 0


Expand Down Expand Up @@ -238,7 +237,7 @@ def test_cli_run_report_fd(capfd, tmpdir, devnull):
def test_cli_call(capfd):
assert call(['covimerage', '--version']) == 0
out, err = capfd.readouterr()
assert out == 'covimerage, version %s\n' % __version__
assert out == 'covimerage, version %s\n' % get_version()

assert call(['covimerage', '--help']) == 0
out, err = capfd.readouterr()
Expand Down

0 comments on commit c8461d9

Please sign in to comment.