jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/709252 )
Change subject: [IMPR] editor.py type hints
......................................................................
[IMPR] editor.py type hints
Bug: T286403
Change-Id: Ife94069f4b65bc14dd19af314205be3661ec15f8
---
M pywikibot/editor.py
1 file changed, 12 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index dfb6cff..db627e1 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -15,19 +15,22 @@
import pywikibot
from pywikibot import config
+from pywikibot.backports import List, Sequence
try:
- from pywikibot.userinterfaces import gui
+ from pywikibot.userinterfaces import gui # noqa
+ GUI_ERROR = None
except ImportError as e:
- gui = e
+ GUI_ERROR = e
class TextEditor:
"""Text editor."""
- def _command(self, file_name, text, jump_index=None):
+ def _command(self, file_name: str, text: str,
+ jump_index: Optional[int] = None) -> List[str]:
"""Return editor selected in user-config.py."""
if jump_index:
# Some editors make it possible to mark occurrences of substrings,
@@ -40,6 +43,7 @@
line = column = 0
# Linux editors. We use startswith() because some users might use
# parameters.
+ assert config.editor is not None
if config.editor.startswith('kate'):
command = ['-l', str(line + 1), '-c', str(column + 1)]
elif config.editor.startswith('gedit'):
@@ -64,7 +68,7 @@
return command
@staticmethod
- def _concat(command):
+ def _concat(command: Sequence[str]) -> str:
return ' '.join("'{}'".format(part) if ' ' in part else part
for part in command)
@@ -105,13 +109,15 @@
os.close(handle)
os.unlink(tempFilename)
- if isinstance(gui, ImportError):
+ if GUI_ERROR:
raise ImportError(fill(
'Could not load GUI modules: {}. No editor available. '
'Set your favourite editor in user-config.py "editor", '
'or install python packages tkinter and idlelib, which '
'are typically part of Python but may be packaged separately '
- 'on your platform.'.format(gui)) + '\n')
+ 'on your platform.'.format(GUI_ERROR)) + '\n')
+
+ assert pywikibot.ui is not None
return pywikibot.ui.editText(text, jumpIndex=jumpIndex,
highlight=highlight)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/709252
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ife94069f4b65bc14dd19af314205be3661ec15f8
Gerrit-Change-Number: 709252
Gerrit-PatchSet: 3
Gerrit-Owner: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/713462 )
Change subject: [IMPR] Show installed setup_tools version if it is too old
......................................................................
[IMPR] Show installed setup_tools version if it is too old
Change-Id: I3d658574ebf10d8744090a5a8a05da490f133e0f
---
M pwb.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 1ab0d74..25fef66 100755
--- a/pwb.py
+++ b/pwb.py
@@ -190,7 +190,8 @@
for num in setuptools.__version__.split('.'))
if setupversion < (20, 8, 1):
# print the minimal requirement
- _print_requirements(['setuptools==20.8.1'], None, 'outdated')
+ _print_requirements(['setuptools==20.8.1'], None,
+ 'outdated ({})'.format(setuptools.__version__))
return
raise e
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/713462
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3d658574ebf10d8744090a5a8a05da490f133e0f
Gerrit-Change-Number: 713462
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/710673 )
Change subject: [IMPR] logging.py type hints
......................................................................
[IMPR] logging.py type hints
This removes backports.py import of tools because it causes a circular import
if modules like logging.py attempt to use it.
Bug: T286403
Change-Id: Ia249fb9a266c09cda1cdcea97bce85c5d5cfbbb1
---
M pywikibot/backports.py
M pywikibot/logging.py
2 files changed, 45 insertions(+), 29 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index 43abbd4..9ae2e7b 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -4,10 +4,10 @@
#
# Distributed under the terms of the MIT license.
#
+import sys
from typing import Any
-from pywikibot.tools import PYTHON_VERSION
-
+PYTHON_VERSION = sys.version_info[:3]
# functools.cache
if PYTHON_VERSION >= (3, 9):
diff --git a/pywikibot/logging.py b/pywikibot/logging.py
index b91ed5b..31a8726 100644
--- a/pywikibot/logging.py
+++ b/pywikibot/logging.py
@@ -7,26 +7,29 @@
import logging
import os
import sys
+from typing import Any
# logging levels
from logging import CRITICAL, DEBUG, ERROR, INFO, WARNING
-from typing import Optional
+from typing import AnyStr, Optional
+
+from pywikibot.backports import Callable, List
STDOUT = 16
VERBOSE = 18
INPUT = 25
-_init_routines = []
+_init_routines = [] # type: List[Callable[[], Any]]
_inited_routines = set()
-def add_init_routine(routine):
+def add_init_routine(routine: Callable[[], Any]) -> None:
"""Add a routine to be run as soon as possible."""
_init_routines.append(routine)
-def _init():
+def _init() -> None:
"""Init any routines which have not already been called."""
for init_routine in _init_routines:
found = init_routine in _inited_routines # prevent infinite loop
@@ -59,12 +62,12 @@
# string indicating the debugging layer.
-def logoutput(text, decoder=None, newline=True, _level=INFO, _logger='',
- **kwargs):
+def logoutput(text: Any, decoder: Optional[str] = None,
+ newline: bool = True, _level: int = INFO, _logger: str = '',
+ **kwargs: Any) -> None:
"""Format output and send to the logging module.
Helper function used by all the user-output convenience functions.
-
"""
if _logger:
logger = logging.getLogger('pywiki.' + _logger)
@@ -86,23 +89,27 @@
'caller_line': frame.f_lineno,
'newline': ('\n' if newline else '')}
- if decoder:
- text = text.decode(decoder)
+ if isinstance(text, str):
+ decoded_text = text
elif isinstance(text, bytes):
- try:
- text = text.decode('utf-8')
- except UnicodeDecodeError:
- text = text.decode('iso8859-1')
+ if decoder:
+ decoded_text = text.decode(decoder)
+ else:
+ try:
+ decoded_text = text.decode('utf-8')
+ except UnicodeDecodeError:
+ decoded_text = text.decode('iso8859-1')
else:
# looks like text is a non-text object.
# Maybe it has a __str__ builtin ?
# (allows to print Page, Site...)
- text = str(text)
+ decoded_text = str(text)
- logger.log(_level, text, extra=context, **kwargs)
+ logger.log(_level, decoded_text, extra=context, **kwargs)
-def output(text, decoder=None, newline=True, **kwargs):
+def output(text: AnyStr, decoder: Optional[str] = None, newline: bool = True,
+ **kwargs: Any) -> None:
r"""Output a message to the user via the userinterface.
Works like print, but uses the encoding used by the user's console
@@ -126,7 +133,8 @@
logoutput(text, decoder, newline, INFO, **kwargs)
-def stdout(text, decoder=None, newline=True, **kwargs):
+def stdout(text: AnyStr, decoder: Optional[str] = None, newline: bool = True,
+ **kwargs: Any) -> None:
"""Output script results to the user via the userinterface.
The text will be sent to standard output, so that it can be piped to
@@ -143,8 +151,8 @@
logoutput(text, decoder, newline, STDOUT, **kwargs)
-def warning(text: str, decoder: Optional[str] = None,
- newline: bool = True, **kwargs):
+def warning(text: AnyStr, decoder: Optional[str] = None,
+ newline: bool = True, **kwargs: Any) -> None:
"""Output a warning message to the user via the userinterface.
:param text: the message the user wants to display.
@@ -157,7 +165,8 @@
logoutput(text, decoder, newline, WARNING, **kwargs)
-def error(text, decoder=None, newline=True, **kwargs):
+def error(text: AnyStr, decoder: Optional[str] = None, newline: bool = True,
+ **kwargs: Any) -> None:
"""Output an error message to the user via the userinterface.
:param text: the message containing the error which occurred.
@@ -170,7 +179,8 @@
logoutput(text, decoder, newline, ERROR, **kwargs)
-def log(text, decoder=None, newline=True, **kwargs):
+def log(text: AnyStr, decoder: Optional[str] = None, newline: bool = True,
+ **kwargs: Any) -> None:
"""Output a record to the log file.
:param text: the message which is to be logged to the log file.
@@ -183,7 +193,8 @@
logoutput(text, decoder, newline, VERBOSE, **kwargs)
-def critical(text, decoder=None, newline=True, **kwargs):
+def critical(text: AnyStr, decoder: Optional[str] = None, newline: bool = True,
+ **kwargs: Any) -> None:
"""Output a critical record to the user via the userinterface.
:param text: the critical message which is to be displayed to the user.
@@ -196,10 +207,12 @@
logoutput(text, decoder, newline, CRITICAL, **kwargs)
-def debug(text, layer, decoder=None, newline=True, **kwargs):
+def debug(text: AnyStr, layer: str, decoder: Optional[str] = None,
+ newline: bool = True, **kwargs: Any) -> None:
"""Output a debug record to the log file.
:param text: the message of the debug record to be logged to the log file.
+ :param layer: logger to record this message upon
:param decoder: If None, text should be a unicode string else it should
be encoded in the given encoding.
:param newline: If True, a line feed will be added after printing the text.
@@ -210,7 +223,8 @@
logoutput(text, decoder, newline, DEBUG, layer, **kwargs)
-def exception(msg=None, decoder=None, newline=True, tb=False, **kwargs):
+def exception(msg: Optional[Exception] = None, decoder: Optional[str] = None,
+ newline: bool = True, tb: bool = False, **kwargs: Any) -> None:
"""Output an error traceback to the user via the userinterface.
Use directly after an 'except' statement::
@@ -229,7 +243,8 @@
This function should only be called from an Exception handler.
- :param msg: If not None,contains the description of the exception occurred.
+ :param msg: If not None, contains the description of the exception
+ that occurred.
:param decoder: If None, text should be a unicode string else it should
be encoded in the given encoding.
:param newline: If True, a line feed will be added after printing the text.
@@ -238,11 +253,12 @@
:param tb: Set to True in order to output traceback also.
"""
if isinstance(msg, BaseException):
- exc_info = 1
+ exc_info = 1 # type: Any
else:
exc_info = sys.exc_info()
- msg = '{}: {}'.format(repr(exc_info[1]).split('(')[0],
+ msg = '{}: {}'.format(repr(exc_info[1]).split('(')[0], # type: ignore
str(exc_info[1]).strip())
if tb:
kwargs['exc_info'] = exc_info
+ assert msg is not None
logoutput(msg, decoder, newline, ERROR, **kwargs)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/710673
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia249fb9a266c09cda1cdcea97bce85c5d5cfbbb1
Gerrit-Change-Number: 710673
Gerrit-PatchSet: 1
Gerrit-Owner: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/713472 )
Change subject: [3.5.2] Show a FutureWarning for Python 3.5.0-3.5.2
......................................................................
[3.5.2] Show a FutureWarning for Python 3.5.0-3.5.2
Bug: T286867
Change-Id: I5c2d9e04a1cc4e571389690b2ddd44e00a6b0bfc
---
M pywikibot/__init__.py
1 file changed, 10 insertions(+), 1 deletion(-)
Approvals:
Damian: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 9e92d0c..a8493d5 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -69,7 +69,7 @@
)
from pywikibot.tools import classproperty
from pywikibot.tools import deprecate_arg as _deprecate_arg
-from pywikibot.tools import normalize_username
+from pywikibot.tools import normalize_username, PYTHON_VERSION
from pywikibot.tools.formatter import color_format
@@ -103,6 +103,15 @@
argvu = [] # type: List[str]
+if PYTHON_VERSION < (3, 5, 3):
+ warn("""
+Python {version} will be dropped with release 7.0 soon.
+It is recommended to use Python 3.5.3 or above.
+See T286867 for further information.
+""".format(version=sys.version.split(maxsplit=1)[0]),
+ FutureWarning) # probably adjust the line no in utils.execute()
+
+
class Timestamp(datetime.datetime):
"""Class for handling MediaWiki timestamps.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/713472
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5c2d9e04a1cc4e571389690b2ddd44e00a6b0bfc
Gerrit-Change-Number: 713472
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/713685 )
Change subject: add_text: Support -major option
......................................................................
add_text: Support -major option
Ocasionally, it comes handle to save major edits via add_text.
Add an option to support that.
Change-Id: Ia9efb3b4080ae311204978bc48f877ebccd5a8c8
---
M scripts/add_text.py
1 file changed, 6 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py
index 6f5ba3c..63cdfd7 100755
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -21,6 +21,8 @@
-always If used, the bot won't ask if it should add the specified
text
+-major If used, the edit will be saved without the "minor edit" flag
+
-talkpage Put the text onto the talk page instead
-talk
@@ -87,6 +89,7 @@
'summary': '',
'up': False,
'always': False,
+ 'minor': True,
'talk_page': False,
'reorder': True,
'regex_skip_url': '',
@@ -361,7 +364,7 @@
text = textlib.add_text(text, self.opt.text,
site=self.current_page.site)
- self.put_current(text, summary=self.opt.summary)
+ self.put_current(text, summary=self.opt.summary, minor=self.opt.minor)
def main(*argv: Tuple[str, ...]) -> None:
@@ -419,6 +422,8 @@
args['reorder'] = False
elif option == '-excepturl':
args['regex_skip_url'] = value
+ elif option == '-major':
+ args['minor'] = False
else:
raise ValueError("Argument '{}' is unrecognized".format(option))
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/713685
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia9efb3b4080ae311204978bc48f877ebccd5a8c8
Gerrit-Change-Number: 713685
Gerrit-PatchSet: 1
Gerrit-Owner: Urbanecm <martin.urbanec(a)wikimedia.cz>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged