jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631924 )
Change subject: [bugfix] prevent circular imports in config2.py and http.py
......................................................................
[bugfix] prevent circular imports in config2.py and http.py
http.py:
- import pywikibot and use __version__ and __url__ from it
- use pywikibot.bot.calledModuleName() but don't import calledModuleName
- import config2 as config
config2.py:
- import __version__ from __metadata__
version.py:
- now we can import fetch from pywikibot.comms.http
- simplify warn and debug message
Bug: T264500
Change-Id: I65fc524fa48334f0021073a070fb8ecb878992ee
---
M pywikibot/comms/http.py
M pywikibot/config2.py
M pywikibot/version.py
3 files changed, 23 insertions(+), 26 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index adcd1eb..77351e4 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -27,9 +27,9 @@
import requests
-from pywikibot import __version__, __url__, config
-from pywikibot.bot import calledModuleName
+import pywikibot
from pywikibot.comms import threadedhttp
+from pywikibot import config2 as config
from pywikibot.exceptions import (
FatalServerError, Server504Error, Server414Error
)
@@ -41,7 +41,6 @@
issue_deprecation_warning,
ModuleDeprecationWrapper,
)
-import pywikibot.version
try:
import requests_oauthlib
@@ -85,7 +84,7 @@
USER_AGENT_PRODUCTS = {
'python': 'Python/' + '.'.join(str(i) for i in sys.version_info),
'http_backend': 'requests/' + requests.__version__,
- 'pwb': 'Pywikibot/' + __version__,
+ 'pwb': 'Pywikibot/' + pywikibot.__version__,
}
@@ -98,7 +97,7 @@
# This is the Pywikibot revision; also map it to {version} at present.
if key == 'version' or key == 'revision':
return pywikibot.version.getversiondict()['rev']
- return super(_UserAgentFormatter, self).get_value(key, args, kwargs)
+ return super().get_value(key, args, kwargs)
_USER_AGENT_FORMATTER = _UserAgentFormatter()
@@ -143,7 +142,7 @@
"""
values = USER_AGENT_PRODUCTS.copy()
- script_name = calledModuleName()
+ script_name = pywikibot.bot.calledModuleName()
values['script'] = script_name
@@ -278,8 +277,9 @@
warn('config.authenticate["{path}"] has invalid value.\n'
'It should contain 2 or 4 items, not {length}.\n'
'See {url}/OAuth for more info.'
- .format(path=path, length=len(config.authenticate[path]),
- url=__url__))
+ .format(path=path,
+ length=len(config.authenticate[path]),
+ url=pywikibot.__url__))
return None
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 76768b5..1fe2b53 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -51,7 +51,7 @@
from typing import Dict, List, Tuple
from warnings import warn
-from pywikibot import __version__ as pwb_version
+from pywikibot.__metadata__ import __version__ as pwb_version
from pywikibot.logging import error, output, warning
from pywikibot.tools import issue_deprecation_warning
diff --git a/pywikibot/version.py b/pywikibot/version.py
index b9c3196..6e5557c 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -26,6 +26,7 @@
import pywikibot
+from pywikibot.comms.http import fetch
from pywikibot import config2 as config
from pywikibot.tools import deprecated
@@ -118,14 +119,14 @@
# pywikibot was imported without using version control at all.
tag, rev, date, hsh = (
'', '-1 (unknown)', '0 (unknown)', '(unknown)')
+ warn('Unable to detect version; exceptions raised:\n{!r}'
+ .format(exceptions), UserWarning)
+ exceptions = None
# git and svn can silently fail, as it may be a nightly.
- if getversion_package in exceptions:
- warn('Unable to detect version; exceptions raised:\n%r'
- % exceptions, UserWarning)
- elif exceptions:
- pywikibot.debug('version algorithm exceptions:\n%r'
- % exceptions, _logger)
+ if exceptions:
+ pywikibot.debug('version algorithm exceptions:\n{!r}'
+ .format(exceptions), _logger)
if isinstance(date, str):
datestring = date
@@ -190,23 +191,19 @@
return tag, rev, date
-def github_svn_rev2hash(tag, rev):
+def github_svn_rev2hash(tag: str, rev):
"""Convert a Subversion revision to a Git hash using Github.
@param tag: name of the Subversion repo on Github
@param rev: Subversion revision identifier
@return: the git hash
- @rtype: str
"""
- from pywikibot.comms import http
-
- uri = 'https://github.com/wikimedia/%s/!svn/vcc/default' % tag
- request = http.fetch(uri=uri, method='PROPFIND',
- body="<?xml version='1.0' encoding='utf-8'?>"
- '<propfind xmlns=\"DAV:\"><allprop/></propfind>',
- headers={'label': str(rev),
- 'user-agent': 'SVN/1.7.5 {pwb}'})
-
+ uri = 'https://github.com/wikimedia/{}/!svn/vcc/default'.format(tag)
+ request = fetch(uri=uri, method='PROPFIND',
+ body="<?xml version='1.0' encoding='utf-8'?>"
+ '<propfind xmlns=\"DAV:\"><allprop/></propfind>',
+ headers={'label': str(rev),
+ 'user-agent': 'SVN/1.7.5 {pwb}'})
dom = xml.dom.minidom.parse(BytesIO(request.raw))
hsh = dom.getElementsByTagName('C:git-commit')[0].firstChild.nodeValue
date = dom.getElementsByTagName('S:date')[0].firstChild.nodeValue
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631924
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: I65fc524fa48334f0021073a070fb8ecb878992ee
Gerrit-Change-Number: 631924
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits