Source code for pywikibot.scripts.version

"""Script to determine the Pywikibot version (tag, revision and date).

.. versionchanged:: 7.0
   version script was moved to the framework scripts folder
# (C) Pywikibot team, 2007-2022
# Distributed under the terms of the MIT license.
import codecs
import os
import sys

import pywikibot
from pywikibot.version import get_toolforge_hostname, getversion

[docs]class DummyModule: """Fake module instance.""" __version__ = 'n/a'
try: import setuptools except ImportError: setuptools = DummyModule() try: import mwparserfromhell except ImportError: mwparserfromhell = DummyModule() try: import wikitextparser except ImportError: wikitextparser = DummyModule() try: import requests except ImportError: requests = DummyModule() WMF_CACERT = 'MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs'
[docs]def main(*args: str) -> None: """Print pywikibot version and important settings."""'Pywikibot: ' + getversion())'Release version: ' + pywikibot.__version__)'setuptools version: ' + setuptools.__version__)'mwparserfromhell version: ' + mwparserfromhell.__version__)'wikitextparser version: ' + wikitextparser.__version__)'requests version: ' + requests.__version__) has_wikimedia_cert = False if (not hasattr(requests, 'certs') or not hasattr(requests.certs, 'where') or not callable(requests.certs.where)):' cacerts: not defined') elif not os.path.isfile(requests.certs.where()):' cacerts: {} (missing)'.format( requests.certs.where())) else:' cacerts: ' + requests.certs.where()) with, 'r', 'utf-8') as cert_file: text = if WMF_CACERT in text: has_wikimedia_cert = True' certificate test: {}' .format('ok' if has_wikimedia_cert else 'not ok')) if not has_wikimedia_cert:' Please reinstall requests!')'Python: ' + sys.version) toolforge_env_hostname = get_toolforge_hostname() if toolforge_env_hostname:'Toolforge hostname: ' + toolforge_env_hostname) # check environment settings settings = {key for key in os.environ if key.startswith('PYWIKIBOT')} settings.update(['PYWIKIBOT_DIR', 'PYWIKIBOT_DIR_PWB', 'PYWIKIBOT_NO_USER_CONFIG']) for environ_name in sorted(settings): '{}: {}'.format(environ_name, os.environ.get(environ_name, 'Not set') or "''"))'Config base dir: ' + pywikibot.config.base_dir) for family, usernames in pywikibot.config.usernames.items(): if not usernames: continue'Usernames for family {family!r}:') for lang, username in usernames.items():'\t{lang}: {username}')
if __name__ == '__main__': main()