Xqt added a comment.
**Add pwb.py wrapper to pywkibot package** Explanations for https://gerrit.wikimedia.org/r/#/c/pywikibot/core/+/560057/ see also for example - https://setuptools.readthedocs.io/en/latest/setuptools.html - https://amir.rachum.com/blog/2017/07/28/python-entry-points/ The main solution is a console scripts entry point inside setup.py: entry_points={'console_scripts': [ 'pwb=pywikibot.scripts.pwb:run', ]}, This creates an entry_point text file inside pywikibot egg info when creating the package and has this content: [console_scripts] pwb = pywikibot.scripts.pwb:run When installing the pywikibot package Python creates two short files inside his own Scripts folder: - `pwb.exe` (in Windows), a small application file which just calls the bootstrap Python script `pwb_script.py` - `pwb_script.py` a python script which calls the entry point script given above **Entry point script** The script entry Point consist of the script path (`pywikibot.scripts`), the script name (`pwb`) and the entry point function (`run`). The entry point script is located in inside scripts folder inside pywikibot package (the scripts name is inspired from Scripts folder used by Python). The entry point function may be different from default entry point if the script is from `__main__`. The main entry point function is `main()` but the package entry point is `run()`. This ensures that we are able to differentiate between package and directory mode installations which may be slightly different in ist behaviou. Maybe this will be rreplaced by the Path information (scripts starts inside the 'side-package' folder which can be detected too). The Location inside the pywikibot folder is mandatory to ensure to collect the scripts to the package **creating the package** A simple batch does it: @echo ### copy script entry points to pywikibot\scripts copy pwb.py .\pywikibot\scripts\* copy generate*.py .\pywikibot\scripts\* @echo @echo ### create a new package py -3 setup.py sdist @echo @echo ### delete script entry points del pywikibot\scripts\pwb.py del pywikibot\scripts\generate* It is not necessary to change the git repository. **Installing the local package** Having al local package created by the commands above it can be installed as a side package without the pypi index is needed: pip uninstall pywikibot pip install --no-index --find-links=dist pywikibot **Running the pwb wrapper** //create a minimal user-config.py//: mylang = 'en' # the default site code you are working on family = 'wikipedia' # the default family usernames['wikipedia']['en'] = 'Test' # the bot account name user_script_paths = ['c:\\pwb.git.core.scripts'] The user_script_path is important. You can add any path to it including side package paths (but there are some TODOs, e.g. find the absolute side package path. probably a different side package path is appropriate) //run the script// `pwb.exe <global option> <script name> <global and local options>` for example: `pwb.exe touche -page:user:xqt` <-- yes it works with touch**e** and have the full benefit of the pwb script wrapper: - find any script in any folder given by user_scripts_path - add .py ending automatically - similar search for script names, ignore spelling mistakes - enable global options even if the script does not support it - //and in future//: enable scripts installed as side package TASK DETAIL https://phabricator.wikimedia.org/T139143 EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/ To: Xqt Cc: Dvorapa, RhinosF1, Xqt, DrTrigon, jayvdb, pywikibot-bugs-list, Aklapper, Zppix, AbdealiJK, JohnsonLee01, Dijkstra, Zkhalido, Viztor, Wenyi, Tbscho, MayS, Mdupont, JJMC89, Altostratus, Avicennasis, mys_721tx, Masti, Alchimista, Rxy
_______________________________________________ pywikibot-bugs mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs
