-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c7b09b
commit 1d4131f
Showing
8 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ include README* | |
include SECURITY* | ||
include pytest.ini | ||
recursive-include qtpy/tests *.py *.ui | ||
include qtpy/py.typed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import qtpy.cli | ||
|
||
|
||
def main(): | ||
return qtpy.cli.cli() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# -*- coding: utf-8 -*- | ||
# ----------------------------------------------------------------------------- | ||
# Copyright © 2009- The QtPy Contributors | ||
# | ||
# Released under the terms of the MIT License | ||
# (see LICENSE.txt for details) | ||
# ----------------------------------------------------------------------------- | ||
|
||
"""Provide a CLI to allow configuring developer settings, including mypy.""" | ||
|
||
# Standard library imports | ||
import argparse | ||
import sys | ||
import textwrap | ||
|
||
|
||
class RawDescriptionArgumentDefaultsHelpFormatter( | ||
argparse.RawDescriptionHelpFormatter, | ||
argparse.ArgumentDefaultsHelpFormatter, | ||
): | ||
pass | ||
|
||
|
||
def cli(args=sys.argv[1:]): | ||
parser = argparse.ArgumentParser( | ||
description="Features in support of development with QtPy.", | ||
formatter_class=RawDescriptionArgumentDefaultsHelpFormatter, | ||
) | ||
|
||
parser.set_defaults(func=parser.print_help) | ||
|
||
cli_subparsers = parser.add_subparsers() | ||
|
||
mypy_args_parser = cli_subparsers.add_parser( | ||
name='mypy-args', | ||
description=textwrap.dedent( | ||
"""\ | ||
Generate command line arguments for using mypy with QtPy. | ||
This will generate strings similar to the following which help guide mypy | ||
through which library QtPy would have used so that mypy can get the proper | ||
underlying type hints. | ||
--always-false=PYQT5 --always-false=PYQT6 --always-true=PYSIDE2 --always-false=PYSIDE6 | ||
Use such as: | ||
env/bin/mypy --package mypackage $(env/bin/qtpy mypy-args) | ||
""" | ||
), | ||
formatter_class=RawDescriptionArgumentDefaultsHelpFormatter, | ||
) | ||
mypy_args_parser.set_defaults(func=mypy_args) | ||
|
||
arguments = parser.parse_args(args=args) | ||
|
||
reserved_parameters = {'func'} | ||
cleaned = { | ||
k: v | ||
for k, v in vars(arguments).items() | ||
if k not in reserved_parameters | ||
} | ||
|
||
arguments.func(**cleaned) | ||
|
||
|
||
def mypy_args(): | ||
options = {False: '--always-false', True: '--always-true'} | ||
|
||
import qtpy | ||
|
||
apis_active = {name: qtpy.API == name for name in qtpy.API_NAMES} | ||
print(' '.join( | ||
f'{options[is_active]}={name.upper()}' | ||
for name, is_active | ||
in apis_active.items() | ||
)) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import absolute_import | ||
|
||
import subprocess | ||
import sys | ||
|
||
import pytest | ||
|
||
import qtpy | ||
|
||
|
||
subcommands = [ | ||
['mypy'], | ||
['mypy', 'args'], | ||
] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
argnames=['subcommand'], | ||
argvalues=[[subcommand] for subcommand in subcommands], | ||
ids=[' '.join(subcommand) for subcommand in subcommands], | ||
) | ||
def test_cli_help_does_not_fail(subcommand): | ||
# .check_call() over .run(..., check=True) because of py2 | ||
subprocess.check_call( | ||
[sys.executable, '-m', 'qtpy', *subcommand, '--help'], | ||
) | ||
|
||
|
||
def test_cli_mypy_args(): | ||
output = subprocess.check_output( | ||
[sys.executable, '-m', 'qtpy', 'mypy', 'args'], | ||
) | ||
|
||
if qtpy.PYQT5: | ||
expected = b'--always-true=PYQT5 --always-false=PYQT6 --always-false=PYSIDE2 --always-false=PYSIDE6\n' | ||
elif qtpy.PYQT6: | ||
expected = b'--always-false=PYQT5 --always-true=PYQT6 --always-false=PYSIDE2 --always-false=PYSIDE6\n' | ||
elif qtpy.PYSIDE2: | ||
expected = b'--always-false=PYQT5 --always-false=PYQT6 --always-true=PYSIDE2 --always-false=PYSIDE6\n' | ||
elif qtpy.PYSIDE6: | ||
expected = b'--always-false=PYQT5 --always-false=PYQT6 --always-false=PYSIDE2 --always-true=PYSIDE6\n' | ||
else: | ||
assert False, 'No valid API to test' | ||
|
||
assert output == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters