jenkins-bot merged this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, but someone else must approve Huji: Looks good to me, approved jenkins-bot: Verified
[IMPR] No longer duplicate absolute_path in sys.path

No longer duplicate absolute_path in sys.path and overwrite
the first occurence later in run_python_file but just insert
and pop os.path.dirname(filename) there.

Change-Id: I84c58cc393165b12bf67bc0696826ae4baa8b258
---
M pwb.py
1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/pwb.py b/pwb.py
index e50d678..22fa3a8 100755
--- a/pwb.py
+++ b/pwb.py
@@ -88,11 +88,10 @@
# Set sys.argv and the first path element properly.
old_argv = sys.argv
old_argvu = pwb.argvu
- old_path0 = sys.path[0]

sys.argv = argv
pwb.argvu = argvu
- sys.path[0] = os.path.dirname(filename)
+ sys.path.insert(0, os.path.dirname(filename))

try:
with open(filename, 'rb') as f:
@@ -105,7 +104,7 @@

# Restore the old argv and path
sys.argv = old_argv
- sys.path[0] = old_path0
+ sys.path.pop(0)
pwb.argvu = old_argvu

# end of snippet from coverage
@@ -200,15 +199,6 @@
return not missing_requirements


-# Establish a normalised path for the directory containing pwb.py.
-# Either it is '.' if the user's current working directory is the same,
-# or it is the absolute path for the directory of pwb.py
-absolute_path = abspath(os.path.dirname(sys.argv[0]))
-
-# add absolute path because sys.path[0] is overridden
-# with os.path.dirname(filename) within run_python_file
-sys.path.insert(1, absolute_path)
-
if not check_modules():
sys.exit()

@@ -362,6 +352,7 @@
# a much more detailed implementation is in coverage's find_module.
# https://bitbucket.org/ned/coveragepy/src/default/coverage/execfile.py
cwd = abspath(os.getcwd())
+ absolute_path = abspath(os.path.dirname(sys.argv[0]))
if absolute_path == cwd:
absolute_filename = abspath(filename)[:len(cwd)]
if absolute_filename == cwd:

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I84c58cc393165b12bf67bc0696826ae4baa8b258
Gerrit-Change-Number: 588152
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Huji <huji.huji@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)