jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705043 )
Change subject: [doc] Update generate_user_files.py EXTENDED_CONFIG doc
......................................................................
[doc] Update generate_user_files.py EXTENDED_CONFIG doc
Remove old compat wikipedia.py and replace it with Pywikibot.
Change-Id: Id22a91f3fd0ca92ccd8f777d0d01f56de74f6137
---
M generate_user_files.py
1 file changed, 8 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py
index b8e339b..be7a5f5 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -171,15 +171,17 @@
EXTENDED_CONFIG = """\
-# This is an automatically generated file. You can find more configuration
-# parameters in 'config.py' file.
+# This is an automatically generated file. You can find more
+# configuration parameters in 'config.py' file or refer
+# https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.config.html
-# The family of sites we are working on. wikipedia.py will import
-# families/xxx_family.py so if you want to change this variable,
-# you need to write such a file.
+# The family of sites to be working on.
+# Pywikibot will import families/xxx_family.py so if you want to change
+# this variable, you have to ensure that such a file exists. You may use
+# generate_family_file to create one.
family = '{main_family}'
-# The language code of the site we're working on.
+# The language code of the site to be working on.
mylang = '{main_code}'
# The dictionary usernames should contain a username for each site where you
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705043
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: Id22a91f3fd0ca92ccd8f777d0d01f56de74f6137
Gerrit-Change-Number: 705043
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
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/+/705163 )
Change subject: [cleanup] Deprecate OutputOption.output() method
......................................................................
[cleanup] Deprecate OutputOption.output() method
OutputOption.output() method was replaced by the out property
and the userinterfaces system does not use the output() method
anymore.
Change-Id: I19bf5826b6c6fc916dcba0c9acee5021020d07a3
---
M pywikibot/bot_choice.py
1 file changed, 6 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot_choice.py b/pywikibot/bot_choice.py
index 598012a..f6dd49f 100755
--- a/pywikibot/bot_choice.py
+++ b/pywikibot/bot_choice.py
@@ -126,10 +126,14 @@
"""
return ''
+ @deprecated('pywikibot.output(OutputOption.out)', since='6.5')
def output(self) -> None:
- """Output string when selected and possibly before the question.
+ """Output string.
- :Note: This method should never be overridden.
+ .. deprecated:: 6.5
+ This method was replaced by :py:obj:`out` property and is no
+ no longer used by the
+ :py:mod:`userinterfaces <pywikibot.userinterfaces>` system.
"""
pywikibot.output(self.out)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705163
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: I19bf5826b6c6fc916dcba0c9acee5021020d07a3
Gerrit-Change-Number: 705163
Gerrit-PatchSet: 2
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/+/705168 )
Change subject: [IMPR] daemonize.py type hints
......................................................................
[IMPR] daemonize.py type hints
Bug: T286403
Change-Id: I5ab426b54f325ce95c0df757715f8809fcf5a440
---
M pywikibot/daemonize.py
1 file changed, 3 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/daemonize.py b/pywikibot/daemonize.py
index fdecae3..16f3716 100644
--- a/pywikibot/daemonize.py
+++ b/pywikibot/daemonize.py
@@ -8,6 +8,7 @@
import os
import stat
import sys
+from typing import Optional
from pywikibot.tools import deprecated_args
@@ -16,7 +17,8 @@
@deprecated_args(write_pid=True)
-def daemonize(close_fd=True, chdir=True, redirect_std=None):
+def daemonize(close_fd: bool = True, chdir: bool = True,
+ redirect_std: Optional[str] = None) -> None:
"""
Daemonize the current process.
@@ -24,11 +26,8 @@
The process will fork to the background and return control to terminal.
:param close_fd: Close the standard streams and replace them by /dev/null
- :type close_fd: bool
:param chdir: Change the current working directory to /
- :type chdir: bool
:param redirect_std: Filename to redirect stdout and stdin to
- :type redirect_std: str
"""
# Fork away
if not os.fork():
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705168
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: I5ab426b54f325ce95c0df757715f8809fcf5a440
Gerrit-Change-Number: 705168
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/+/705155 )
Change subject: [bugfix] Ignore throttle.pid if a Site object cannot be created
......................................................................
[bugfix] Ignore throttle.pid if a Site object cannot be created
- raise a ValueError if either code or family cannot be found
to create a Site object within pywikibot.Site constructor
- ignore throttle.pid if a Site object cannot be created within
bot.init_handlers
Bug: T286848
Change-Id: I53a7fb5cb2de484bf91d85ab0da14372b12b1eb7
---
M pywikibot/__init__.py
M pywikibot/bot.py
2 files changed, 16 insertions(+), 8 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 305a950..048c92f 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -1148,6 +1148,8 @@
URL. Still requires that the family supporting that URL exists.
:raises ValueError: URL and pair of code and family given
:raises ValueError: Invalid interface name
+ :raises ValueError: Missing Site code
+ :raises ValueError: Missing Site family
"""
_logger = 'wiki'
@@ -1169,6 +1171,10 @@
code = code or _config.mylang
fam = fam or _config.family
+ if not (code and fam):
+ raise ValueError('Missing Site {}'
+ .format('code' if not code else 'family'))
+
if not isinstance(fam, Family):
fam = Family.load(fam)
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index e49315f..d189610 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -366,14 +366,16 @@
# if user has enabled file logging, configure file handler
if module_name in config.log or '*' in config.log:
- if pywikibot.Site.__doc__ == 'TEST': # set by aspects.DisableSiteMixin
- pid = ''
- else:
- # get PID
- throttle = pywikibot.Site().throttle # initialize a Throttle obj
- pid = throttle.get_pid(module_name) # get the global PID if needed
- pid = str(pid) + '-' if pid > 1 else ''
-
+ pid = ''
+ if pywikibot.Site.__doc__ != 'TEST': # set by aspects.DisableSiteMixin
+ try: # T286848
+ site = pywikibot.Site()
+ except ValueError:
+ pass
+ else: # get PID
+ throttle = site.throttle # initialize a Throttle obj
+ pid = throttle.get_pid(module_name) # get the global PID
+ pid = str(pid) + '-' if pid > 1 else ''
if config.logfilename:
# keep config.logfilename unchanged
logfile = config.datafilepath('logs', config.logfilename)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705155
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: I53a7fb5cb2de484bf91d85ab0da14372b12b1eb7
Gerrit-Change-Number: 705155
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705041 )
Change subject: [IMPR] add type hints
......................................................................
[IMPR] add type hints
Bug: T286403
Change-Id: I77eb4c6bd0160f7fdc5078de701dc02a55d8edcf
---
M pywikibot/config.py
1 file changed, 61 insertions(+), 38 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config.py b/pywikibot/config.py
index 426f39d..c6bbe26 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -44,16 +44,21 @@
from os import environ, getenv
from pathlib import Path
from textwrap import fill
-from typing import Optional, Union
+from typing import Optional, TypeVar, Union
from warnings import warn
from zipfile import ZipFile, is_zipfile
from pywikibot.__metadata__ import __version__ as pwb_version
-from pywikibot.backports import Dict, List, Tuple, removesuffix
+from pywikibot.backports import (DefaultDict, Dict, FrozenSet, List, Mapping,
+ Tuple, removesuffix)
from pywikibot.logging import error, output, warning
from pywikibot.tools import deprecated, issue_deprecation_warning
+_DabComDict = DefaultDict[str, Dict[str, str]]
+_ValueType = TypeVar('_ValueType')
+
+
OSWIN32 = (sys.platform == 'win32')
if OSWIN32:
@@ -143,7 +148,7 @@
# You may use '*' for family name in a similar manner.
#
usernames = collections.defaultdict(dict) # type: Dict[str, Dict[str, str]]
-disambiguation_comment = collections.defaultdict(dict)
+disambiguation_comment = collections.defaultdict(dict) # type: _DabComDict
# User agent format.
# For the meaning and more help in customization see:
@@ -168,7 +173,7 @@
# True for enabling, False for disabling, str to hardcode a UA.
# Example: {'problematic.site.example': True,
# 'prefers.specific.ua.example': 'snakeoil/4.2'}
-fake_user_agent_exceptions = {}
+fake_user_agent_exceptions = {} # type: Dict[str, Union[bool, str]]
# This following option is deprecated in favour of finer control options above.
fake_user_agent = False
@@ -218,7 +223,7 @@
# 'access_key', 'access_secret')
#
# Note: the target wiki site must install OAuth extension
-authenticate = {}
+authenticate = {} # type: Dict[str, Tuple[str, ...]]
# By default you are asked for a password on the terminal.
# A password file may be used, e.g. password_file = '.passwd'
@@ -271,7 +276,7 @@
#
# Note that these headers will be sent with all requests,
# not just MediaWiki API calls.
-extra_headers = {}
+extra_headers = {} # type: Mapping[str, str]
# Set to True to override the {{bots}} exclusion protocol (at your own risk!)
ignore_bot_templates = False
@@ -279,7 +284,7 @@
# #############################################
-def user_home_path(path):
+def user_home_path(path: str) -> str:
"""Return a file path to a file in the user home."""
return os.path.join(os.path.expanduser('~'), path)
@@ -308,7 +313,7 @@
directory. Used to test whether placing a user config file in this
directory will cause it to be selected as the base directory.
"""
- def exists(directory):
+ def exists(directory: str) -> bool:
directory = os.path.abspath(directory)
if directory == test_directory:
return True
@@ -342,20 +347,22 @@
elif win_version in (6, 10):
sub_dir = ['AppData', 'Roaming']
else:
- raise WindowsError('Windows version {} not supported yet.'
- .format(win_version))
+ raise WindowsError( # type: ignore[name-defined]
+ 'Windows version {} not supported yet.'
+ .format(win_version)
+ )
base_dir_cand.extend([[home] + sub_dir + ['Pywikibot'],
[home] + sub_dir + ['pywikibot']])
else:
base_dir_cand.append([home, '.pywikibot'])
- for dir in base_dir_cand:
- dir = os.path.join(*dir)
+ for dir_ in base_dir_cand:
+ dir_s = os.path.join(*dir_)
try:
- os.makedirs(dir, mode=private_files_permission)
+ os.makedirs(dir_s, mode=private_files_permission)
except OSError: # PermissionError or already exists
- if exists(dir):
- base_dir = dir
+ if exists(dir_s):
+ base_dir = dir_s
break
if not os.path.isabs(base_dir):
@@ -369,6 +376,7 @@
base_dir)
if __no_user_config is None:
+ assert get_base_dir.__doc__ is not None
exc_text += (
' Please check that user-config.py is stored in the correct '
'location.\n'
@@ -393,7 +401,7 @@
@deprecated('family_files[family_name] = file_path', since='20210305')
-def register_family_file(family_name, file_path):
+def register_family_file(family_name: str, file_path: str) -> None:
"""Register a single family class file.
Parameter file_path may be a path or an url.
@@ -402,7 +410,7 @@
family_files[family_name] = file_path
-def register_families_folder(folder_path: str):
+def register_families_folder(folder_path: str) -> None:
"""Register all family class files contained in a directory.
:param folder_path: The path of a folder containing family files.
@@ -554,9 +562,9 @@
# log = []
# Per default, no logging is enabled.
# This setting can be overridden by the -log or -nolog command-line arguments.
-log = []
+log = [] # type: List[str]
# filename defaults to modulename-bot.log
-logfilename = None
+logfilename = None # type: Optional[str]
# maximal size of a logfile in kilobytes. If the size reached that limit the
# logfile will be renamed (if logfilecount is not 0) and the old file is filled
# again. logfilesize must be an integer value
@@ -574,7 +582,7 @@
log_pywiki_repo_version = False
# if True, include a lot of debugging info in logfile
# (overrides log setting above)
-debug_log = []
+debug_log = [] # type: List[str]
# ############# EXTERNAL SCRIPT PATH SETTINGS ##############
# Set your own script path to lookup for your script files.
@@ -815,7 +823,7 @@
# Set simulate to True or use -simulate option to block all actions given
# above.
-simulate = False
+simulate = False # type: Union[bool, str]
# How many pages should be put to a queue in asynchronous mode.
# If maxsize is <= 0, the queue size is infinite.
@@ -840,7 +848,7 @@
# #############################################
-def makepath(path: str, create: bool = True):
+def makepath(path: str, create: bool = True) -> str:
"""Return a normalized absolute version of the path argument.
If the given path already exists in the filesystem or create is False
@@ -861,7 +869,7 @@
return os.path.normpath(os.path.abspath(path))
-def datafilepath(*filename, **kwargs):
+def datafilepath(*filename: str, create: bool = True) -> str:
"""Return an absolute path to a data file in a standard location.
Argument(s) are zero or more directory names, optionally followed by a
@@ -869,24 +877,21 @@
directories in the path that do not already exist are created if create
is True, otherwise the filesystem keeps unchanged.
- :param path: path in the filesystem
- :type path: str
- :keyword create: create the directory if it is True. Otherwise don't change
+ :param filename: path in the filesystem
+ :param create: create the directory if it is True. Otherwise don't change
the filesystem. Default is True.
- :type create: bool
"""
- create = kwargs.get('create', True)
return makepath(os.path.join(base_dir, *filename), create=create)
-def shortpath(path):
+def shortpath(path: str) -> str:
"""Return a file path relative to config.base_dir."""
if path.startswith(base_dir):
return path[len(base_dir) + len(os.path.sep):]
return path
-def _win32_extension_command(extension):
+def _win32_extension_command(extension: str) -> Optional[str]:
"""Get the command from the Win32 registry for an extension."""
fileexts_key = \
r'Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts'
@@ -896,7 +901,7 @@
_prog_id = winreg.EnumValue(key1, 0)[0]
_key2 = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT,
r'{}\shell\open\command'.format(_prog_id))
- _cmd = winreg.QueryValueEx(_key2, None)[0]
+ _cmd = winreg.QueryValueEx(_key2, '')[0]
# See T102465 for issues relating to using this value.
cmd = _cmd
if cmd.find('%1'):
@@ -904,13 +909,14 @@
# Remove any trailing character, which should be a quote or space
# and then remove all whitespace.
return cmd[:-1].strip()
- except WindowsError as e:
+ except WindowsError as e: # type: ignore[name-defined]
# Catch any key lookup errors
output('Unable to detect program for file extension "{}": {!r}'
.format(extension, e))
+ return None
-def _detect_win32_editor():
+def _detect_win32_editor() -> Optional[str]:
"""Detect the best Win32 editor."""
# Notepad is even worse than our Tkinter editor.
unusable_exes = ['notepad.exe',
@@ -962,7 +968,12 @@
"""An error when the required type doesn't match the actual type."""
- def __init__(self, name, actual_type, allowed_types):
+ def __init__(
+ self,
+ name: str,
+ actual_type: type,
+ allowed_types: Tuple[type, ...],
+ ) -> None:
super().__init__(
'Configuration variable "{}" is defined as "{}" in '
'your user-config.py but expected "{}".'
@@ -970,17 +981,25 @@
'", "'.join(t.__name__ for t in allowed_types)))
-def _assert_default_type(name, value, default_value):
+def _assert_default_type(
+ name: str,
+ value: _ValueType,
+ default_value: object,
+) -> Union[_ValueType, float, None]:
"""Return the value if the old or new is None or both same type."""
if (value is None or default_value is None
or isinstance(value, type(default_value))):
return value
if isinstance(value, int) and isinstance(default_value, float):
return float(value)
- raise _DifferentTypeError(name, type(value), [type(default_value)])
+ raise _DifferentTypeError(name, type(value), (type(default_value),))
-def _assert_types(name, value, types):
+def _assert_types(
+ name: str,
+ value: _ValueType,
+ types: Tuple[type, ...],
+) -> _ValueType:
"""Return the value if it's one of the types."""
if isinstance(value, types):
return value
@@ -993,7 +1012,11 @@
'maintainers if you depend on it.')
-def _check_user_config_types(user_config, default_values, skipped):
+def _check_user_config_types(
+ user_config: Dict[str, object],
+ default_values: Dict[str, object],
+ skipped: FrozenSet[str],
+) -> None:
"""Check the types compared to the default values."""
for name, value in user_config.items():
if name in default_values:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/705041
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: I77eb4c6bd0160f7fdc5078de701dc02a55d8edcf
Gerrit-Change-Number: 705041
Gerrit-PatchSet: 4
Gerrit-Owner: JJMC89 <JJMC89.Wikimedia(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/+/704629 )
Change subject: [bugfix] OutputProxyOption's 'out' could return None
......................................................................
[bugfix] OutputProxyOption's 'out' could return None
OutputOption has a string 'out' property and an 'output()' method that prints
(returning None).
When OutputProxyOption lacked its 'out' property it returned output() instead.
The 'out' type hint says this returns a string, not None. As such mypy
rightfully warns about this with...
pywikibot/bot_choice.py:188: error: "output" of "OutputOption" does not
return a value
Simply returning an empty string instead.
Bug: T286403
Change-Id: Iab31d5f6cff4d4b67c75611c36ba614f9cd8e658
---
M pywikibot/bot_choice.py
1 file changed, 3 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot_choice.py b/pywikibot/bot_choice.py
index 89daa17..5dd3df8 100755
--- a/pywikibot/bot_choice.py
+++ b/pywikibot/bot_choice.py
@@ -182,12 +182,13 @@
@property
def out(self) -> str:
- """Return te contents."""
+ """Return the contents."""
if not hasattr(self._outputter, 'out'):
issue_deprecation_warning('{} without "out" property'
.format(self.__class__.__name__),
since='6.2.0')
- return self._outputter.output()
+ self._outputter.output()
+ return ''
return self._outputter.out
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/704629
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: Iab31d5f6cff4d4b67c75611c36ba614f9cd8e658
Gerrit-Change-Number: 704629
Gerrit-PatchSet: 4
Gerrit-Owner: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged