jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631904 )
Change subject: [bugfix] fix version.get_module_filename() ......................................................................
[bugfix] fix version.get_module_filename()
version.py: - module.__file__ may be None; check for it in get_module_filename() - do no longer take compiled python files into account; the files has been moved to __pycache__ - return the full version string in get_module_version - deprecate get_module_version because no file has a __version__ variable except it is imported from pywikibot or __metadata__ - also show a FutureWarning for deprecated getfileversion because it cannot be used anymore due to missing __version__ variables
bot.py: - remove version information from log because it is always the framework version - print the time first to be aligned - use 'seconds' as timespec because microseconds does not care (Python 3.6+ only)
Bug: T264235 Change-Id: I18fdd3a33ae1af9af91ee40896e1346699ef1a18 --- M pywikibot/bot.py M pywikibot/version.py 2 files changed, 21 insertions(+), 14 deletions(-)
Approvals: Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 8b5eb15..5668ce3 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -124,6 +124,7 @@ from pywikibot.logging import critical from pywikibot.tools import ( deprecated, deprecate_arg, deprecated_args, issue_deprecation_warning, + PYTHON_VERSION, ) from pywikibot.tools._logging import LoggingFormatter, RotatingFileHandler from pywikibot.tools.formatter import color_format @@ -403,11 +404,16 @@ log('MODULES:') for module in sys.modules.values(): filename = version.get_module_filename(module) - ver = version.get_module_version(module) - mtime = version.get_module_mtime(module) - if filename and ver and mtime: - log(' {} {} {}' - .format(filename, ver[:7], mtime.isoformat(' '))) + if not filename: + continue + + param = {'sep': ' '} + if PYTHON_VERSION >= (3, 6, 0): + param['timespec'] = 'seconds' + mtime = version.get_module_mtime(module).isoformat(**param) + + log(' {} {}' + .format(mtime, filename))
if config.log_pywiki_repo_version: log('PYWIKI REPO VERSION: {}'.format(version.getversion_onlinerepo())) diff --git a/pywikibot/version.py b/pywikibot/version.py index 376c8c5..b9c3196 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -21,6 +21,7 @@ from distutils.sysconfig import get_python_lib from importlib import import_module from io import BytesIO +from typing import Optional from warnings import warn
import pywikibot @@ -387,7 +388,7 @@
@deprecated('get_module_version, get_module_filename and get_module_mtime', - since='20150221') + since='20150221', future_warning=True) def getfileversion(filename): """Retrieve revision number of file.
@@ -419,7 +420,8 @@ return None
-def get_module_version(module): +@deprecated('pywikibot.__version__', since='20201003') +def get_module_version(module) -> Optional[str]: """ Retrieve __version__ variable from an imported module.
@@ -427,14 +429,13 @@ @type module: module @return: The version hash without the surrounding text. If not present return None. - @rtype: str or None """ if hasattr(module, '__version__'): - return module.__version__[5:-1] + return module.__version__ return None
-def get_module_filename(module): +def get_module_filename(module) -> Optional[str]: """ Retrieve filename from an imported pywikibot module.
@@ -445,12 +446,12 @@ @param module: The module instance. @type module: module @return: The filename if it's a pywikibot module otherwise None. - @rtype: str or None """ - if hasattr(module, '__file__') and os.path.exists(module.__file__): + if hasattr(module, '__file__'): filename = module.__file__ - if filename[-4:-1] == '.py' and os.path.exists(filename[:-1]): - filename = filename[:-1] + if not filename or not os.path.exists(filename): + return None + program_dir = _get_program_dir() if filename[:len(program_dir)] == program_dir: return filename
pywikibot-commits@lists.wikimedia.org