jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631914 )
Change subject: [bugfix] Show help string if argument is -help or starts with -help:
......................................................................
[bugfix] Show help string if argument is -help or starts with -help:
- Show help string if argument is "-help" or starts with "-help:"
like "-help:global" even a required package is missing
- use -help option for script tests to detect scripts which are
member of auto_run_script_list; update test result accordingly
Bug: T264498
Change-Id: I8e8bab1f01a24306eedf810a586dac3817af1128
---
M pwb.py
M tests/script_tests.py
2 files changed, 5 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 19162c7..497f72f 100755
--- a/pwb.py
+++ b/pwb.py
@@ -348,7 +348,9 @@
warn('Parent module %s not found: %s'
% (file_package, e), ImportWarning)
- if check_modules(filename) or '-help' in script_args:
+ help_option = any(arg.startswith('-help:') or arg == 'help'
+ for arg in script_args)
+ if check_modules(filename) or help_option:
run_python_file(filename,
[filename] + script_args,
[Path(filename).stem] + argvu[1:],
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 085a748..2802c12 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -214,7 +214,7 @@
.format(script_name))
def testScript(self):
- global_args = 'Global arguments available for all'
+ global_args = 'For global options use -help:global or run pwb'
cmd = [script_name] + args
data_in = script_input.get(script_name)
@@ -352,7 +352,7 @@
_expected_failures = {'version'}
_allowed_failures = []
- _arguments = '-help:global'
+ _arguments = '-help'
_results = None
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631914
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: I8e8bab1f01a24306eedf810a586dac3817af1128
Gerrit-Change-Number: 631914
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/+/631904 )
Change subject: [bugfix] fix version.get_module_filename()
......................................................................
[bugfix] fix version.get_module_filename()
version.py:
- module.__file__ may be None; check for it in get_module_filename()
- do no longer take compiled python files into account; the files
has been moved to __pycache__
- return the full version string in get_module_version
- deprecate get_module_version because no file has a __version__
variable except it is imported from pywikibot or __metadata__
- also show a FutureWarning for deprecated getfileversion because
it cannot be used anymore due to missing __version__ variables
bot.py:
- remove version information from log because it is always the
framework version
- print the time first to be aligned
- use 'seconds' as timespec because microseconds does not care
(Python 3.6+ only)
Bug: T264235
Change-Id: I18fdd3a33ae1af9af91ee40896e1346699ef1a18
---
M pywikibot/bot.py
M pywikibot/version.py
2 files changed, 21 insertions(+), 14 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 8b5eb15..5668ce3 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -124,6 +124,7 @@
from pywikibot.logging import critical
from pywikibot.tools import (
deprecated, deprecate_arg, deprecated_args, issue_deprecation_warning,
+ PYTHON_VERSION,
)
from pywikibot.tools._logging import LoggingFormatter, RotatingFileHandler
from pywikibot.tools.formatter import color_format
@@ -403,11 +404,16 @@
log('MODULES:')
for module in sys.modules.values():
filename = version.get_module_filename(module)
- ver = version.get_module_version(module)
- mtime = version.get_module_mtime(module)
- if filename and ver and mtime:
- log(' {} {} {}'
- .format(filename, ver[:7], mtime.isoformat(' ')))
+ if not filename:
+ continue
+
+ param = {'sep': ' '}
+ if PYTHON_VERSION >= (3, 6, 0):
+ param['timespec'] = 'seconds'
+ mtime = version.get_module_mtime(module).isoformat(**param)
+
+ log(' {} {}'
+ .format(mtime, filename))
if config.log_pywiki_repo_version:
log('PYWIKI REPO VERSION: {}'.format(version.getversion_onlinerepo()))
diff --git a/pywikibot/version.py b/pywikibot/version.py
index 376c8c5..b9c3196 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -21,6 +21,7 @@
from distutils.sysconfig import get_python_lib
from importlib import import_module
from io import BytesIO
+from typing import Optional
from warnings import warn
import pywikibot
@@ -387,7 +388,7 @@
@deprecated('get_module_version, get_module_filename and get_module_mtime',
- since='20150221')
+ since='20150221', future_warning=True)
def getfileversion(filename):
"""Retrieve revision number of file.
@@ -419,7 +420,8 @@
return None
-def get_module_version(module):
+@deprecated('pywikibot.__version__', since='20201003')
+def get_module_version(module) -> Optional[str]:
"""
Retrieve __version__ variable from an imported module.
@@ -427,14 +429,13 @@
@type module: module
@return: The version hash without the surrounding text. If not present
return None.
- @rtype: str or None
"""
if hasattr(module, '__version__'):
- return module.__version__[5:-1]
+ return module.__version__
return None
-def get_module_filename(module):
+def get_module_filename(module) -> Optional[str]:
"""
Retrieve filename from an imported pywikibot module.
@@ -445,12 +446,12 @@
@param module: The module instance.
@type module: module
@return: The filename if it's a pywikibot module otherwise None.
- @rtype: str or None
"""
- if hasattr(module, '__file__') and os.path.exists(module.__file__):
+ if hasattr(module, '__file__'):
filename = module.__file__
- if filename[-4:-1] == '.py' and os.path.exists(filename[:-1]):
- filename = filename[:-1]
+ if not filename or not os.path.exists(filename):
+ return None
+
program_dir = _get_program_dir()
if filename[:len(program_dir)] == program_dir:
return filename
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631904
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: I18fdd3a33ae1af9af91ee40896e1346699ef1a18
Gerrit-Change-Number: 631904
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631386 )
Change subject: [bugfix] Fix errors which occurred due to missing Family.version()
......................................................................
[bugfix] Fix errors which occurred due to missing Family.version()
- remove family.force_version which was never used and its implementation
is unclear.
- remove force_version call in APISite.version() which always gave None
- remove Family.version() fallback in APISite.version() and raise the
exception
- print an error message and raise the exception if the version info
could not retrieved via api
- use Site.mw_version in favour of Site.version() within bot.py
api_tests.py:
- remove suppress_warnings decorators for removed Family.version() method
- update test_access_denied_no_username and
test_access_denied_notexist_username accordingly
Bug: T264096
Change-Id: I71fb62f52ccd0176280c86b88ac037c3355df3e9
---
M pywikibot/bot.py
M pywikibot/family.py
M pywikibot/site/__init__.py
M tests/api_tests.py
4 files changed, 22 insertions(+), 61 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index da21a7f..abf756f 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1428,15 +1428,14 @@
return
if site not in self._sites:
- log('LOADING SITE %s VERSION: %s'
- % (site, site.version()))
+ log('LOADING SITE {} VERSION: {}'.format(site, site.mw_version))
self._sites.add(site)
if len(self._sites) == 2:
- log('%s uses multiple sites' % self.__class__.__name__)
+ log('{} uses multiple sites'.format(self.__class__.__name__))
if self._site and self._site != site:
- log('%s: changing site from %s to %s'
- % (self.__class__.__name__, self._site, site))
+ log('{}: changing site from {} to {}'
+ .format(self.__class__.__name__, self._site, site))
self._site = site
def run(self):
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 55b77ed..22d3078 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1034,26 +1034,6 @@
"""Return the name of the MySQL database."""
return '%s%s' % (code, self.name)
- def force_version(self, code):
- """
- Return a manual version number.
-
- The site is usually using the version number from the servers'
- siteinfo, but if there is a problem with that it's possible to return
- a non-empty string here representing another version number.
-
- For example, L{pywikibot.tools.MediaWikiVersion} treats version
- numbers ending with 'alpha', 'beta' or 'rc' as newer than any version
- ending with 'wmf<number>'. But if that causes breakage it's possible
- to override it here to a version number which doesn't cause breakage.
-
- @return: A version number which can be parsed using
- L{pywikibot.tools.MediaWikiVersion}. If empty/None it uses the
- version returned via siteinfo.
- @rtype: str
- """
- return None
-
def encoding(self, code):
"""Return the encoding for a specific language wiki."""
return 'utf-8'
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 1f6f804..65b212e 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -2102,24 +2102,20 @@
return self.siteinfo['lang']
def version(self):
- """
- Return live project version number as a string.
+ """Return live project version number as a string.
- This overwrites the corresponding family method for APISite class. Use
- L{pywikibot.site.mw_version} to compare MediaWiki versions.
+ Use L{pywikibot.site.mw_version} to compare MediaWiki versions.
"""
- version = self.force_version()
- if not version:
- try:
- version = self.siteinfo.get('generator',
- expiry=1).split(' ')[1]
- except pywikibot.data.api.APIError:
- # May occur if you are not logged in (no API read permissions).
- pywikibot.exception('You have no API read permissions. Seems '
- 'you are not logged in')
- version = self.family.version(self.code)
+ try:
+ version = self.siteinfo.get('generator', expiry=1).split(' ')[1]
+ except pywikibot.data.api.APIError:
+ msg = 'You have no API read permissions.'
+ if not self.logged_in():
+ msg += ' Seems you are not logged in.'
+ pywikibot.error(msg)
+ raise
- if MediaWikiVersion(version) < MediaWikiVersion('1.19'):
+ if MediaWikiVersion(version) < '1.19':
raise RuntimeError(
'Pywikibot "{}" does not support MediaWiki "{}".\n'
'Use Pywikibot prior to "5.0" or "python2" branch '
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 1774800..9895f52 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -994,33 +994,21 @@
pywikibot.data.api.LoginManager = self.orig_login_manager
super(TestLazyLoginNotExistUsername, self).tearDown()
- # When there is no API access the deprecated family.version is used.
- @suppress_warnings('pywikibot.family.Family.version is deprecated')
@patch.object(pywikibot, 'output')
- @patch.object(pywikibot, 'exception')
@patch.object(pywikibot, 'warning')
@patch.object(pywikibot, 'error')
- def test_access_denied_notexist_username(
- self, error, warning, exception, output
- ):
+ def test_access_denied_notexist_username(self, error, warning, output):
"""Test the query with a username which does not exist."""
self.site._username = 'Not registered username'
req = api.Request(site=self.site, parameters={'action': 'query'})
self.assertRaises(pywikibot.NoUsername, req.submit)
# FIXME: T100965
self.assertRaises(api.APIError, req.submit)
- try:
- error.assert_called_with('Login failed (readapidenied).')
- except AssertionError: # MW version is older than 1.34.0-wmf.13
- try:
- error.assert_called_with('Login failed (FAIL).')
- except AssertionError: # MW version is older than 1.27
- error.assert_called_with('Login failed (Failed).')
warning.assert_called_with(
'API error readapidenied: '
'You need read permission to use this module.')
- exception.assert_called_with(
- 'You have no API read permissions. Seems you are not logged in')
+ error.assert_called_with(
+ 'You have no API read permissions. Seems you are not logged in.')
self.assertIn(
'Logging in to steward:steward as ', output.call_args[0][0])
@@ -1029,12 +1017,10 @@
"""Test no username."""
- # When there is no API access the deprecated family.version is used.
- @suppress_warnings('pywikibot.family.Family.version is deprecated')
@patch.object(pywikibot, 'warning')
- @patch.object(pywikibot, 'exception')
+ @patch.object(pywikibot, 'error')
@patch.object(pywikibot.config, 'usernames', defaultdict(dict))
- def test_access_denied_no_username(self, exception, warning):
+ def test_access_denied_no_username(self, error, warning):
"""Test the query without a username."""
self.site._username = None
req = api.Request(site=self.site, parameters={'action': 'query'})
@@ -1044,8 +1030,8 @@
warning.assert_called_with(
'API error readapidenied: '
'You need read permission to use this module.')
- exception.assert_called_with(
- 'You have no API read permissions. Seems you are not logged in')
+ error.assert_called_with(
+ 'You have no API read permissions. Seems you are not logged in.')
class TestBadTokenRecovery(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631386
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: I71fb62f52ccd0176280c86b88ac037c3355df3e9
Gerrit-Change-Number: 631386
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(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/+/631911 )
Change subject: [cleanup] remove unused epydoc.cfg and epytext doc format hints
......................................................................
[cleanup] remove unused epydoc.cfg and epytext doc format hints
Change-Id: I6d0644a52b573b1b20b643edd87a367a3d5caef2
---
M pywikibot/comms/http.py
M pywikibot/comms/threadedhttp.py
D pywikibot/epydoc.cfg
3 files changed, 0 insertions(+), 89 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index ffd1c48..adcd1eb 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -16,8 +16,6 @@
#
# Distributed under the terms of the MIT license.
#
-__docformat__ = 'epytext'
-
import atexit
import sys
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index b8c3e24..fd19f5d 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -5,9 +5,6 @@
#
# Distributed under the terms of the MIT license.
#
-__docformat__ = 'epytext'
-
-# standard python libraries
import codecs
import re
diff --git a/pywikibot/epydoc.cfg b/pywikibot/epydoc.cfg
deleted file mode 100644
index 0725f98..0000000
--- a/pywikibot/epydoc.cfg
+++ /dev/null
@@ -1,84 +0,0 @@
-[epydoc] # Epydoc section marker (required by ConfigParser)
-
-# modules
-# The list of objects to document. Objects can be named using
-# dotted names, module filenames, or package directory names.
-# Alases for this option include "objects" and "values".
-modules: data.threadedhttp
-
-# output
-# The type of output that should be generated. Should be one
-# of: html, text, latex, dvi, ps, pdf.
-output: html
-
-# target
-# The path to the output directory. May be relative or absolute.
-target: doc/
-
-# css
-# The CSS stylesheet for HTML output. Can be the name of a builtin
-# stylesheet, or the name of a file.
-css: white
-
-# name
-# The documented project's name.
-name: Python Mediawiki Framework
-
-# url
-# The documented project's URL.
-url: https://www.mediawiki.org/wiki/Manual:Pywikibot
-
-# frames
-# Whether or not to include a frames-based table of contents.
-frames: yes
-
-# private
-# Whether or not to include private variables. (Even if included,
-# private variables will be hidden by default.)
-private: yes
-
-# imports
-# Whether or not to list each module's imports.
-imports: yes
-
-# verbosity
-# An integer indicating how verbose epydoc should be. The default
-# value is 0; negative values will suppress warnings and errors;
-# positive values will give more verbose output.
-verbosity: 0
-
-# parse
-# Whether or not parsing should be used to examine objects.
-parse: yes
-
-# introspect
-# Whether or not introspection should be used to examine objects.
-introspect: yes
-
-# graph
-# The list of graph types that should be automatically included
-# in the output. Graphs are generated using the Graphviz "dot"
-# executable. Graph types include: "classtree", "callgraph",
-# "umlclass". Use "all" to include all graph types
-graph: all
-
-# dotpath
-# The path to the Graphviz "dot" executable, used to generate
-# graphs.
-dotpath: /usr/bin/dot
-
-# sourcecode
-# Whether or not to include syntax highlighted source code in
-# the output (HTML only).
-sourcecode: no
-
-# pstat
-# The name of one or more pstat files (generated by the profile
-# or hotshot module). These are used to generate call graphs.
-pstat: profile.out
-
-# separate-classes
-# Whether each class should be listed in its own section when
-# generating LaTeX or PDF output.
-separate-classes: no
-
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631911
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: I6d0644a52b573b1b20b643edd87a367a3d5caef2
Gerrit-Change-Number: 631911
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
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/+/631796 )
Change subject: [IMPR] Derive FlowPage from ABC
......................................................................
[IMPR] Derive FlowPage from ABC
FlowPage is a base class for Board or Topic. FlowPage cannot be used
directly due to the missing _load method.
- derive FlowPage from ABC metaclass because it is a base class for
Board and Topic
- add _load method to FlowPage and use abstractmethod decorator for it
- remove FlowPage._load_uuid() method and use FlowPage._load() in
uuid property instead
- change position for parameters in private method _load for consistency
Change-Id: Ieab9c240f3ee757c7cf525c507909af88cd652b2
---
M pywikibot/flow.py
1 file changed, 20 insertions(+), 18 deletions(-)
Approvals:
Happy5214: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 016d66d..d494666 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -5,6 +5,7 @@
#
# Distributed under the terms of the MIT license.
#
+import abc
import logging
from urllib.parse import urlparse, parse_qs
@@ -18,15 +19,11 @@
# Flow page-like objects (boards and topics)
-class FlowPage(BasePage):
+class FlowPage(BasePage, abc.ABC):
- """
- The base page for the Flow extension.
+ """The base page meta class for the Flow extension.
- There should be no need to instantiate this directly.
-
- Subclasses must provide a _load() method to load and cache
- the object's internal data from the API.
+ It cannot be instantiated directly.
"""
def __init__(self, source, title=''):
@@ -45,9 +42,14 @@
if not self.site.has_extension('Flow'):
raise UnknownExtension('site is not Flow-enabled')
- def _load_uuid(self):
- """Load and save the UUID of the page."""
- self._uuid = self._load()['workflowId']
+ @abc.abstractmethod
+ def _load(self, force: bool = False):
+ """Abstract method to load and cache the Flow data.
+
+ Subclasses must overwrite _load() method to load and cache
+ the object's internal data from the API.
+ """
+ raise NotImplementedError
@property
def uuid(self):
@@ -57,7 +59,7 @@
@rtype: str
"""
if not hasattr(self, '_uuid'):
- self._load_uuid()
+ self._uuid = self._load()['workflowId']
return self._uuid
def get(self, force=False, get_redirect=False):
@@ -151,11 +153,11 @@
"""A Flow discussion topic."""
- def _load(self, content_format: str = 'wikitext', force: bool = False):
+ def _load(self, force: bool = False, content_format: str = 'wikitext'):
"""Load and cache the Topic's data.
- @param content_format: The post format in which to load
@param force: Whether to force a reload if the data is already loaded
+ @param content_format: The post format in which to load
"""
if not hasattr(self, '_data') or force:
self._data = self.site.load_topic(self, content_format)
@@ -382,14 +384,14 @@
assert isinstance(content['content'], str)
self._content[content['format']] = content['content']
- @deprecate_arg('format', 'content_format')
- def _load(self, content_format='wikitext', load_from_topic: bool = False):
+ def _load(self, force: bool = True, content_format: str = 'wikitext',
+ load_from_topic: bool = False):
"""Load and cache the Post's data using the given content format.
@param load_from_topic: Whether to load the post from the whole topic
"""
if load_from_topic:
- data = self.page._load(content_format=content_format, force=True)
+ data = self.page._load(force=force, content_format=content_format)
else:
data = self.site.load_post_current_revision(self.page, self.uuid,
content_format)
@@ -450,7 +452,7 @@
@return: The contents of the post in the given content format
"""
if content_format not in self._content or force:
- self._load(content_format)
+ self._load(content_format=content_format)
return self._content[content_format]
@deprecate_arg('format', 'content_format')
@@ -472,7 +474,7 @@
# load_from_topic workaround due to T106733
# (replies not returned by view-post)
if not hasattr(self, '_current_revision') or force:
- self._load(content_format, load_from_topic=True)
+ self._load(content_format=content_format, load_from_topic=True)
reply_uuids = self._current_revision['replies']
self._replies = [Post(self.page, uuid) for uuid in reply_uuids]
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631796
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: Ieab9c240f3ee757c7cf525c507909af88cd652b2
Gerrit-Change-Number: 631796
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Happy5214 <happy5214(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged