Skip to content

Commit

Permalink
Merge pull request #121 from blurstudio-forks/mikeh/run_module
Browse files Browse the repository at this point in the history
Enable use with `python -m` or `pythonw -m`
  • Loading branch information
altendky committed Jan 17, 2024
2 parents 51fd15b + 5e178e9 commit 4673a59
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ environment variable ``DOT_ENV_DIRECTORY`` will be set to the directory
containing the ``.env`` file. With this extra variable you can specify paths
relative to the ``.env`` location.

There alternative ways to call ``Scripts/pyqt6-tools.exe``, ``python -m pyqt6_tools``
works the same way but allows you to choose the version of python to run the tools
with. On Windows if you create a shortcut to `pyqt6-tools.exe`, it will show a
command prompt that stays open for the duration of the launched application. You
can address this by using ``Scripts/pyqt6-toolsw.exe`` or ``pythonw -m pyqt6_tools``.

.. code-block:: powershell
PYQTDESIGNERPATH=${PYQTDESIGNERPATH};${DOT_ENV_DIRECTORY}/path/to/my/widgets
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def pad_version(v, segment_count=3):
["Qt6", "Qt5"],
["Qt6", "Qt 5"],
["6.4", "5.15"],
["pyuic6", "pyuic5"],
]
for a, b in replacements:
readme = readme.replace(a, b)
Expand Down Expand Up @@ -108,6 +109,9 @@ def pad_version(v, segment_count=3):
entry_points={
'console_scripts': [
'pyqt{major}-tools = pyqt{major}_tools.entrypoints:main'.format(major=pyqt_major_version),
],
'gui_scripts': [
'pyqt{major}-toolsw = pyqt{major}_tools.entrypoints:main'.format(major=pyqt_major_version),
]
}
)
12 changes: 12 additions & 0 deletions src/pyqt_tools/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
""" Enables support for calling entrypoints using `python -m`.
Examples:
Launching PyQt6 designer: `python -m pyqt6_tools designer`
Launching PyQt5 designer: `python -m pyqt5_tools designer`
"""


import sys
from . import entrypoints

sys.exit(entrypoints.main())
26 changes: 19 additions & 7 deletions src/pyqt_tools/tests/test_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@
fspath = getattr(os, 'fspath', str)

scripts_path = pathlib.Path(sysconfig.get_path("scripts"))
executable_path_string = fspath(scripts_path.joinpath("pyqt{}-tools".format(major)))

@pytest.fixture(
name="executable_cmd",
params=[
[fspath(scripts_path.joinpath("pyqt{}-tools".format(major)))],
[fspath(scripts_path.joinpath("pyqt{}-toolsw".format(major)))],
[sys.executable, "-m", "pyqt{}_tools".format(major)],
],
ids=lambda cmd: pathlib.Path(cmd[0]).name,
)
def executable_cmd_fixture(request):
return request.param


vars_to_print = [
*pyqt_plugins.utilities.diagnostic_variables_to_print,
Expand All @@ -41,7 +53,7 @@ def environment_fixture():
return environment


def test_designer_creates_test_widget(tmp_path, environment):
def test_designer_creates_test_widget(tmp_path, environment, executable_cmd):
file_path = tmp_path/'tigger'
environment[pyqt_plugins.tests.testbutton.test_path_env_var] = fspath(file_path)

Expand All @@ -61,7 +73,7 @@ def test_designer_creates_test_widget(tmp_path, environment):
with pytest.raises(subprocess.TimeoutExpired):
subprocess.run(
[
executable_path_string,
*executable_cmd,
'designer',
],
check=True,
Expand Down Expand Up @@ -127,7 +139,7 @@ def test_qmlscene_paints_test_item(tmp_path, environment):
reason="accepting failure until we figure out the problem".format(string_version),
strict=True,
)
def test_qmltestrunner_paints_test_item(tmp_path, environment):
def test_qmltestrunner_paints_test_item(tmp_path, environment, executable_cmd):
file_path = tmp_path/'piglet'
environment[pyqt_plugins.examples.exampleqmlitem.test_path_env_var] = fspath(file_path)

Expand All @@ -139,7 +151,7 @@ def test_qmltestrunner_paints_test_item(tmp_path, environment):

subprocess.run(
[
executable_path_string,
*executable_cmd,
'qmltestrunner',
'--',
'-input',
Expand All @@ -156,12 +168,12 @@ def test_qmltestrunner_paints_test_item(tmp_path, environment):
)


def test_installuic_does_not_fail(environment):
def test_installuic_does_not_fail(environment, executable_cmd):
pyqt_plugins.utilities.print_environment_variables(environment, *vars_to_print)

subprocess.run(
[
executable_path_string,
*executable_cmd,
'installuic',
],
check=True,
Expand Down

0 comments on commit 4673a59

Please sign in to comment.