jenkins-bot has submitted this change and it was merged.
Change subject: Reduce import dependencies around cosmetic_changes
......................................................................
Reduce import dependencies around cosmetic_changes
There are several imports around cosmetic_changes which depended
on each other, causing complications when adding new imports.
pywikibot.cosmetic_changes imported pagegenerators only for
parameterHelp, which is unused since the module was moved into
the pywikibot package in fd1ba1e48e.
As cosmetic_changes imported scripts.isbn for backwards compatibility,
it inherited isbn's dependency on pagegenerators. The import of
scripts.isbn has been moved into the function where it is used
to delay the import until after initialisation.
As pagegenerators depends on wikidataquery, which depends on page,
the wikidataquery dependency has been moved to be a delayed import
within WikidataQueryPageGenerator.
Also move the import of page module in cosmetic_changes down to
where it is used, so that cosmetic_changes doesnt depend on page
during startup.
Change-Id: I5ec082c65247129454b605781210f09c168b4a51
---
M pywikibot/cosmetic_changes.py
M pywikibot/pagegenerators.py
2 files changed, 19 insertions(+), 29 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index e6b5213..1bde3a9 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -65,33 +65,15 @@
try:
import stdnum.isbn as stdnum_isbn
- scripts_isbn = None
except ImportError:
stdnum_isbn = None
- # Old dependency
- try:
- import scripts.isbn as scripts_isbn
- except ImportError:
- scripts_isbn = None
import pywikibot
-from pywikibot import config, textlib, pagegenerators
-from pywikibot.page import url2unicode
+from pywikibot import config, textlib
from pywikibot.tools import deprecate_arg, first_lower, first_upper
from pywikibot.tools import MediaWikiVersion
-
-warning = """
-ATTENTION: You can run this script as a stand-alone for testing purposes.
-However, the changes that are made are only minor, and other users
-might get angry if you fill the version histories and watchlists with such
-irrelevant changes. Some wikis prohibit stand-alone running."""
-
-docuReplacements = {
- '¶ms;': pagegenerators.parameterHelp,
- '&warning;': warning,
-}
# This is from interwiki.py;
# move it to family file and implement global instances
@@ -159,6 +141,20 @@
def _format_isbn_match(match, strict=True):
"""Helper function to validate and format a single matched
ISBN."""
+ scripts_isbn = None
+
+ if not stdnum_isbn:
+ # For backwards compatibility, if stdnum.isbn is not available
+ # attempt loading scripts.isbn as an alternative implementation.
+ try:
+ import scripts.isbn as scripts_isbn
+ except ImportError:
+ raise NotImplementedError(
+ 'ISBN functionality not available. Install stdnum package.')
+
+ warn('package stdnum.isbn not found; using scripts.isbn',
+ ImportWarning)
+
isbn = match.group('code')
if stdnum_isbn:
try:
@@ -194,19 +190,11 @@
@raises Exception: Invalid ISBN encountered when strict enabled
"""
- if not stdnum_isbn:
- if not scripts_isbn:
- raise NotImplementedError(
- 'ISBN functionality not available. Install stdnum package.')
-
- warn('package stdnum.isbn not found; using scripts.isbn',
- ImportWarning)
-
return textlib.reformat_ISBNs(
text, lambda match: _format_isbn_match(match, strict=strict))
-class CosmeticChangesToolkit:
+class CosmeticChangesToolkit(object):
"""Cosmetic changes toolkit."""
@@ -519,6 +507,7 @@
titleLength)
# Convert URL-encoded characters to unicode
+ from pywikibot.page import url2unicode
titleWithSection = url2unicode(titleWithSection,
encodings=self.site)
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 8e42bf5..9f392f5 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -47,7 +47,6 @@
from pywikibot import date, config, i18n
from pywikibot.comms import http
-from pywikibot.data import wikidataquery as wdquery
from pywikibot.exceptions import ArgumentDeprecationWarning
if sys.version_info[0] > 2:
@@ -2367,6 +2366,8 @@
@type site: L{pywikibot.site.BaseSite}
"""
+ from pywikibot.data import wikidataquery as wdquery
+
if site is None:
site = pywikibot.Site()
repo = site.data_repository()
--
To view, visit
https://gerrit.wikimedia.org/r/237537
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5ec082c65247129454b605781210f09c168b4a51
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>