jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/496801 )
Change subject: [IMPR] Remove '.py' before matching the string
......................................................................
[IMPR] Remove '.py' before matching the string
- Improve string matching by removing '.py' ending.
See T217195 for further information.
- Also ignore __init__.py scripts
- use set to hold the script names to hold the script path
(used later to let the user the choice to start it)
Bug: T217195
Change-Id: I3952cb77191890cface75bdb5a51e7c2613f63ac
---
M pwb.py
1 file changed, 11 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 9027c8c..164d44c 100755
--- a/pwb.py
+++ b/pwb.py
@@ -196,22 +196,23 @@
print('ERROR: {} not found! Misspelling?'.format(filename),
file=sys.stderr)
- scripts = []
+ scripts = {}
for file_package in script_paths:
path = file_package.split('.')
for script_name in os.listdir(os.path.join(*path)):
- if script_name.endswith('.py'):
- scripts.append(script_name)
+ if (script_name.endswith('.py')
+ and not script_name.startswith('__')):
+ # remove .py for better matching
+ scripts[script_name[:-3]] = os.path.join(
+ *(path + [script_name]))
- similar_scripts = get_close_matches(filename, scripts,
+ similar_scripts = get_close_matches(filename[:-3], scripts,
n=10, cutoff=0.7)
-
if similar_scripts:
- print(
- '\nThe most similar {}:'
- .format('script is' if len(similar_scripts) == 1
- else 'scripts are'))
- print('\t' + '\n\t'.join(similar_scripts))
+ print('\nThe most similar script{}:'
+ .format(' is' if len(similar_scripts) == 1
+ else 's are'))
+ print('\t' + '.py\n\t'.join(similar_scripts) +
'.py')
return True
# When both pwb.py and the filename to run are within the current
--
To view, visit
https://gerrit.wikimedia.org/r/496801
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3952cb77191890cface75bdb5a51e7c2613f63ac
Gerrit-Change-Number: 496801
Gerrit-PatchSet: 8
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)