jenkins-bot merged this change.
[cleanup] Do not import pathlib twice
- import Path from pathlib only once. pathlib is mandatory for pwb anyway.
- Change script's doc string that it can be reused if pwb.py is not used
in directory mode but from side package too which will be implemented
soon.
Change-Id: Ia57f6a437bc8cab4dacbe86cd6ecbb54649e7178
---
M pwb.py
M tests/pwb_tests.py
2 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/pwb.py b/pwb.py
index c1c24a9..f3e7d85 100755
--- a/pwb.py
+++ b/pwb.py
@@ -1,16 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-"""Wrapper script to use Pywikibot in 'directory' mode.
+"""Wrapper script to invoke pywikibot-based scripts.
-Run scripts using:
+Run scripts with pywikibot in directory mode using:
python pwb.py <pwb options> <name_of_script> <options>
-and it will use the package directory to store all user files, will fix up
-search paths so the package does not need to be installed, etc.
+This wrapper script uses the package directory to store all user files,
+will fix up search paths so the package does not need to be installed, etc.
Currently <pwb options> are global options. This can be used for tests
-to set the default site like (see T216825):
+to set the default site (see T216825):
python pwb.py -lang:de bot_tests -v
"""
@@ -33,6 +33,12 @@
PYTHON_VERSION = sys.version_info[:3]
PY2 = (PYTHON_VERSION[0] == 2)
+if not PY2:
+ from pathlib import Path
+else:
+ from pathlib2 import Path
+
+
VERSIONS_REQUIRED_MESSAGE = """
Pywikibot is not available on:
{version}
@@ -162,10 +168,6 @@
import pkg_resources
if script:
from setup import script_deps
- try:
- from pathlib import Path
- except ImportError: # Python 2
- from pathlib2 import Path
dependencies = script_deps.get(Path(script).name, [])
else:
from setup import dependencies
@@ -240,11 +242,6 @@
print('Now, you have to re-execute the command to start your script.')
sys.exit(1)
-try:
- from pathlib import Path
-except ImportError: # Python 2
- from pathlib2 import Path
-
def find_alternates(filename, script_paths):
"""Search for similar filenames in the given script paths."""
diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py
index cac124f..ab653d3 100644
--- a/tests/pwb_tests.py
+++ b/tests/pwb_tests.py
@@ -7,7 +7,7 @@
https://bitbucket.org/ned/coveragepy/src/default/tests/test_execfile.py
"""
#
-# (C) Pywikibot team, 2007-2019
+# (C) Pywikibot team, 2007-2020
#
# Distributed under the terms of the MIT license.
#
@@ -79,9 +79,8 @@
def test_script_found(self):
"""Test pwb.py script call which is found."""
stdout = io.StringIO(execute_pwb(['pwb'])['stdout'])
- self.assertEqual(
- stdout.readline().strip(),
- "Wrapper script to use Pywikibot in 'directory' mode.")
+ self.assertEqual(stdout.readline().strip(),
+ 'Wrapper script to invoke pywikibot-based scripts.')
def test_script_not_found(self):
"""Test pwbot.py script call which is not found."""
To view, visit change 598467. To unsubscribe, or for help writing mail filters, visit settings.