John Vandenberg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151658
Change subject: Allow pywikibot to load without a user-config.py
......................................................................
Allow pywikibot to load without a user-config.py
Set environment variable PYWIKIBOT2_NO_USER_CONFIG
to allow the library to load without a user-config.py
Emits a warning to help triage problems with this
functionality.
Change-Id: I8f77f7634989bef75701ed5cf952844e339c1243
---
M pywikibot/config2.py
1 file changed, 14 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/58/151658/1
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 6103f23..cb14a20 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -137,6 +137,8 @@
'.pywikibot' directory (Unix and similar) under the user's home
directory.
+ Set PYWIKIBOT2_NO_USER_CONFIG to disable loading user-config.py
+
"""
NAME = "pywikibot"
base_dir = ""
@@ -176,11 +178,13 @@
if not os.path.exists(os.path.join(base_dir, "user-config.py")):
exc_text = ("No user-config.py found in directory '%(base_dir)s'.\n"
% locals())
- exc_text += " Please check that user-config.py is stored in the
correct location.\n"
- exc_text += " Directory where user-config.py is searched is
determined as follows:\n\n"
- exc_text += " " + _get_base_dir.__doc__
-
- raise RuntimeError(exc_text)
+ if 'PYWIKIBOT2_NO_USER_CONFIG' in os.environ:
+ print(exc_text)
+ else:
+ exc_text += " Please check that user-config.py is stored in the
correct location.\n"
+ exc_text += " Directory where user-config.py is searched is
determined as follows:\n\n"
+ exc_text += " " + _get_base_dir.__doc__
+ raise RuntimeError(exc_text)
return base_dir
@@ -704,7 +708,11 @@
# Get the user files
_thislevel = 0
-_fns = [os.path.join(_base_dir, "user-config.py")]
+if 'PYWIKIBOT2_NO_USER_CONFIG' in os.environ:
+ print("WARNING: Skipping loading of user-config.py.")
+ _fns = []
+else:
+ _fns = [os.path.join(_base_dir, "user-config.py")]
for _filename in _fns:
_thislevel += 1
if os.path.exists(_filename):
--
To view, visit https://gerrit.wikimedia.org/r/151658
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f77f7634989bef75701ed5cf952844e339c1243
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits