jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[bugfix] fix call of wrapper.py script in pwb.py caller

invoking any scripts from pwb.py caller fails because importing wrapper.py
also imports pywikibot and leads config.py to install user-config.py
even if PYWIKIBOT_NO_USER_CONFIG is set.

- use runpy.run_path to call the wrapper.py script from pwb.py caller
- fix the generate_user_files.py path in wrapper.py
- adjust exc_text in config.get_base_dir()

Bug: T321452
Change-Id: I33ac035ef8b2ea1f2600ff650dff4c3397926bd7
---
M pwb.py
M pywikibot/config.py
M pywikibot/scripts/wrapper.py
3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/pwb.py b/pwb.py
index 0e12919..e515776 100644
--- a/pwb.py
+++ b/pwb.py
@@ -7,7 +7,9 @@
#
# Distributed under the terms of the MIT license.
#
+import runpy
import sys
+from pathlib import Path

VERSIONS_REQUIRED_MESSAGE = """
Pywikibot is not available on:
@@ -28,8 +30,8 @@

def main():
"""Entry point for :func:`tests.utils.execute_pwb`."""
- from pywikibot.scripts import wrapper
- wrapper.main()
+ path = Path().resolve() / 'pywikibot' / 'scripts' / 'wrapper.py'
+ runpy.run_path(str(path), run_name='__main__')


if __name__ == '__main__':
diff --git a/pywikibot/config.py b/pywikibot/config.py
index 11d7b30..ae751f4 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -377,20 +377,22 @@

if not os.path.isabs(base_dir):
base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
+
# make sure this path is valid and that it contains user-config file
if not os.path.isdir(base_dir):
raise RuntimeError(f"Directory '{base_dir}' does not exist.")
+
# check if config_file is in base_dir
if not exists(base_dir):
- exc_text = 'No {} found in directory {!r}.\n'.format(
- config_file, base_dir)
+ exc_text = f'No {config_file} found in directory {base_dir!r}.\n'

if __no_user_config is None:
assert get_base_dir.__doc__ is not None
exc_text += (
- ' Please check that {0} is stored in the correct location.\n'
- ' Directory where {0} is searched is determined as follows:'
- '\n\n '.format(config_file)) + get_base_dir.__doc__
+ '\nPlease check that {0} is stored in the correct location.'
+ '\nDirectory where {0} is searched is determined as follows:'
+ '\n\n '.format(config_file)
+ ) + get_base_dir.__doc__
raise RuntimeError(exc_text)

if __no_user_config != '2':
diff --git a/pywikibot/scripts/wrapper.py b/pywikibot/scripts/wrapper.py
index db59e06..4446ae8 100755
--- a/pywikibot/scripts/wrapper.py
+++ b/pywikibot/scripts/wrapper.py
@@ -308,8 +308,8 @@

print('NOTE: user-config.py was not found!')
print('Please follow the prompts to create it:')
- run_python_file(str(wrapper_dir.joinpath(
- 'pywikibot', 'scripts', 'generate_user_files.py')), [])
+ run_python_file(
+ str(wrapper_dir.joinpath('generate_user_files.py')), [])
# because we have loaded pywikibot without user-config.py loaded,
# 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.')

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I33ac035ef8b2ea1f2600ff650dff4c3397926bd7
Gerrit-Change-Number: 846940
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged