Skip to content

Commit

Permalink
Add version option to QtPy CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
CAM-Gerlach committed Apr 19, 2022
1 parent 200f5f2 commit 83f3cb6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qtpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import textwrap


def print_version():
"""Print the current version of the package."""
import qtpy
print('QtPy version', qtpy.__version__)


def generate_mypy_args():
"""Generate a string with always-true/false args to pass to mypy."""
options = {False: '--always-false', True: '--always-true'}
Expand All @@ -38,6 +44,11 @@ def generate_arg_parser():
description='Features to support development with QtPy.',
)
parser.set_defaults(func=parser.print_help)

parser.add_argument(
'--version', action='store_const', dest='func', const=print_version,
help='If passed, will print the version and exit')

cli_subparsers = parser.add_subparsers(
title='Subcommands', help='Subcommand to run', metavar='Subcommand')

Expand Down
10 changes: 10 additions & 0 deletions qtpy/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ def test_cli_help_does_not_fail(subcommand):
)


def test_cli_version():
output = subprocess.run(
[sys.executable, '-m', 'qtpy', '--version'],
capture_output=True,
check=True,
encoding='utf-8',
)
assert output.stdout.strip().split()[-1] == qtpy.__version__


def test_cli_mypy_args():
output = subprocess.run(
[sys.executable, '-m', 'qtpy', 'mypy-args'],
Expand Down

0 comments on commit 83f3cb6

Please sign in to comment.