jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
pwb.py: Limit the try clause to the minimum amount of code necessary

This avoids masking bugs and makes the code easier to understand.

Change-Id: Ia16fe15018b0d5adcc8459854b80f54cb6bfe55e
---
M pwb.py
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/pwb.py b/pwb.py
index d6211ef..a542908 100755
--- a/pwb.py
+++ b/pwb.py
@@ -95,7 +95,7 @@
main_mod = types.ModuleType(str('__main__'))
sys.modules['__main__'] = main_mod
main_mod.__file__ = filename
- if sys.version_info[0] > 2:
+ if not PY2:
main_mod.__builtins__ = sys.modules['builtins']
else:
main_mod.__builtins__ = sys.modules['__builtin__']
@@ -166,16 +166,15 @@
args = sys.argv[(2 if filename else 1):]

# Search for user-config.py before creating one.
+# If successful, user-config.py already exists in one of the candidate
+# directories. See config2.py for details on search order.
+# Use env var to communicate to config2.py pwb.py location (bug T74918).
+_pwb_dir = os.path.split(__file__)[0]
+if sys.platform == 'win32' and PY2:
+ _pwb_dir = str(_pwb_dir)
+os.environ['PYWIKIBOT_DIR_PWB'] = _pwb_dir
try:
- # If successful, user-config.py already exists in one of the candidate
- # directories. See config2.py for details on search order.
- # Use env var to communicate to config2.py pwb.py location (bug T74918).
- _pwb_dir = os.path.split(__file__)[0]
- if sys.platform == 'win32' and sys.version_info[0] < 3:
- _pwb_dir = str(_pwb_dir)
- os.environ['PYWIKIBOT_DIR_PWB'] = _pwb_dir
import pywikibot
- pwb = pywikibot
except RuntimeError:
# user-config.py to be created
if filename is not None and not (filename.startswith('generate_')
@@ -189,6 +188,7 @@
# we need to re-start the entire process. Ask the user to do so.
print('Now, you have to re-execute the command to start your script.')
sys.exit(1)
+pwb = pywikibot


def main():

To view, visit change 492303. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia16fe15018b0d5adcc8459854b80f54cb6bfe55e
Gerrit-Change-Number: 492303
Gerrit-PatchSet: 3
Gerrit-Owner: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)