From 00ccace551621d2559f6b24de9cdf7a571b14f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 11 Dec 2024 21:31:09 +0200 Subject: [PATCH 1/4] Add __main__.py for using with python -m This allows easily run the program from source tree after installing dependencies: $ pip install -e . $ python -m subliminal --help --- src/subliminal/__main__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/subliminal/__main__.py diff --git a/src/subliminal/__main__.py b/src/subliminal/__main__.py new file mode 100644 index 00000000..0161ddbe --- /dev/null +++ b/src/subliminal/__main__.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +if len(__package__) == 0: + import sys + + print( + f""" + +The '__main__' module does not seem to have been run in the context of a +runnable package ... did you forget to add the '-m' flag? + +Usage: {sys.executable} -m subliminal {' '.join(sys.argv[1:])} + +""" + ) + sys.exit(2) + +from subliminal.cli import cli + +cli() From a3a6d3249009f25a06967d520a9d17c684efc12f Mon Sep 17 00:00:00 2001 From: getzze Date: Thu, 12 Dec 2024 23:17:42 +0000 Subject: [PATCH 2/4] ruff unfixable T201-print --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 6f63d647..1f3f760a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -208,6 +208,9 @@ ignore = [ "D107", # Missing docstring in `__init__` "D401", # First line should be in imperative mood ] +unfixable = [ + "T201", +] [tool.ruff.lint.per-file-ignores] "docs/conf*.py" = ["ALL"] From 473154111b7ef8db4c1699d162424bb4188937ca Mon Sep 17 00:00:00 2001 From: getzze Date: Thu, 12 Dec 2024 23:18:21 +0000 Subject: [PATCH 3/4] use dedent --- src/subliminal/__main__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/subliminal/__main__.py b/src/subliminal/__main__.py index 0161ddbe..207d3c2b 100644 --- a/src/subliminal/__main__.py +++ b/src/subliminal/__main__.py @@ -1,17 +1,23 @@ +"""Module subliminal.""" + from __future__ import annotations +from textwrap import dedent + if len(__package__) == 0: import sys - print( - f""" + print( # noqa: T201 + dedent( + f""" -The '__main__' module does not seem to have been run in the context of a -runnable package ... did you forget to add the '-m' flag? + The '__main__' module does not seem to have been run in the context + of a runnable package ... did you forget to add the '-m' flag? -Usage: {sys.executable} -m subliminal {' '.join(sys.argv[1:])} + Usage: {sys.executable} -m subliminal {' '.join(sys.argv[1:])} -""" + """ + ) ) sys.exit(2) From adea9887808dd74a4886b9689a83b88d1879e1b5 Mon Sep 17 00:00:00 2001 From: getzze Date: Fri, 13 Dec 2024 10:12:38 +0000 Subject: [PATCH 4/4] only run with the -m flag --- src/subliminal/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subliminal/__main__.py b/src/subliminal/__main__.py index 207d3c2b..80b9d6dc 100644 --- a/src/subliminal/__main__.py +++ b/src/subliminal/__main__.py @@ -4,7 +4,7 @@ from textwrap import dedent -if len(__package__) == 0: +if not (__name__ == '__main__' and __package__ == 'subliminal'): import sys print( # noqa: T201