jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1198323?usp=email )

Change subject: Move Python deprecation warning from pywikibot library to pwb 
wrapper
......................................................................

Move Python deprecation warning from pywikibot library to pwb wrapper

When Pywikibot is used as a side package, the deprecation warning is not
necessary because pip already installs the correct version. Otherwise,
the pwb wrapper script is the appropriate place for such a warning, as
it serves as the frontend entry point of Pywikibot.

Change-Id: I8818e2a0667e56622084a1f49388c278faa0d876
---
M pwb.py
M pywikibot/__init__.py
M tests/utils.py
3 files changed, 21 insertions(+), 11 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pwb.py b/pwb.py
index 9c4af3b..07debd3 100755
--- a/pwb.py
+++ b/pwb.py
@@ -18,6 +18,12 @@

 This version of Pywikibot only supports Python 3.8+.
 """
+DEPRECATED_PYTHON_MESSAGE = """
+
+Python {version} will be dropped soon with Pywikibot 11.
+It is recommended to use Python 3.9 or above.
+See phab: T401802 for further information.
+"""


 def python_is_supported():
@@ -25,9 +31,21 @@
     return sys.version_info[:3] >= (3, 8)


+def python_is_deprecated():
+    """Check that Python is deprecated."""
+    return sys.version_info[:3] < (3, 9)
+
+
 if not python_is_supported():  # pragma: no cover
     sys.exit(VERSIONS_REQUIRED_MESSAGE.format(version=sys.version))

+if python_is_deprecated():
+    import warnings
+    msg = DEPRECATED_PYTHON_MESSAGE.format(
+        version=sys.version.split(maxsplit=1)[0])
+    warnings.warn(msg, FutureWarning)  # adjust this line no in utils.execute()
+    del warnings
+

 def main() -> None:
     """Entry point for :func:`tests.utils.execute_pwb`."""
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 4ddaf22..9b35fde 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -59,7 +59,7 @@
 )
 from pywikibot.site import BaseSite as _BaseSite
 from pywikibot.time import Timestamp
-from pywikibot.tools import PYTHON_VERSION, normalize_username
+from pywikibot.tools import normalize_username


 if TYPE_CHECKING:
@@ -87,15 +87,6 @@

 _sites: dict[str, APISite] = {}

-if PYTHON_VERSION < (3, 9):
-    __version = sys.version.split(maxsplit=1)[0]
-    warnings.warn(f"""
-
-    Python {__version} will be dropped soon with Pywikibot 11.
-    It is recommended to use Python 3.9 or above.
-    See phab: T401802 for further information.
-""", FutureWarning)  # adjust warnings.warn line no in utils.execute()
-
 
 @cache
 def _code_fam_from_url(url: str, name: str | None = None) -> tuple[str, str]:
diff --git a/tests/utils.py b/tests/utils.py
index 870ca14..bba040a 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -476,7 +476,8 @@
     :param command: executable to run and arguments to use
     """
     if PYTHON_VERSION < (3, 9):
-        command.insert(1, '-W ignore::FutureWarning:pywikibot:92')
+        command.insert(1, '-W ignore::FutureWarning:pwb:46')
+        command.insert(1, '-W ignore::FutureWarning:__main__:46')

     env = os.environ.copy()


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1198323?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I8818e2a0667e56622084a1f49388c278faa0d876
Gerrit-Change-Number: 1198323
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to