Page MenuHomePhabricator

Ability to disable Pywikibot SCM version detection completely
Open, MediumPublic

Description

I run my bots in a fairly constrained and controlled environment (minimal software configuration, constrained permissions and network traffic) and I am running into problems like pywikibot trying to guess the version number.

I have proposed a Gerrit change to override User-Agent. Apparently pywikibot-core has a config.user_agent_format feature but it does not prevent auto-discovery of the bot version.

Overriding User-Agent is not enough since there may be more features checking the version, one of them is writeToCommandLogFile() (see also T98106: writeToCommandLogFile() should be optional).

When git is not available, it tries to fetch the irrelevant changelog, as I usually have some local patches/commits in the code. (Fetching also fails with T98104: Strict SSL certificate checking).

This feature is just not robust enough in my experience.

Event Timeline

saper created this task.May 5 2015, 1:25 AM
saper raised the priority of this task from to Medium.
saper updated the task description. (Show Details)
saper added a project: Pywikibot-General.
saper added a subscriber: saper.
Restricted Application added subscribers: Aklapper, Unknown Object (MLST). · View Herald TranscriptMay 5 2015, 1:25 AM
jayvdb added a subscriber: jayvdb.May 5 2015, 3:47 AM

Core has a config variable log_pywiki_repo_version = False . That could be useful for T98106

Regarding the user-agent, core http layer provides a few values to the user agent formatter, including pywikibot.release (which is not the auto discovered version), but also includes the auto-discovered data in pywikibot.version.cache only if it is set. (see http.py line 184). That implicitly means it doesnt use the git version when log_pywiki_repo_version is False

We could improve the user agent so that it explicitly fetches pywikibot.version data when '{revision}' or '{version}' are in the user agent format string, and explicitly doesnt fetch that version when those are omitted from the user agent string.

XZise added a subscriber: XZise.EditedMay 5 2015, 8:45 AM

But when it generates the user agent string in core it doesn't fetch the version of pwb. So it seems unrelated to the user agent string.

Anyway we could use some classes or so which have a __str__ and lazy load the version number. So if there is no {version} in the string str.format won't do str(…) on that:

>>> class Test:
...     def __str__(self):
...         print('str')
...         return 'version-number'
... 
>>> '{test}'.format(test=Test())
str
'version-number'
>>> '{foo}'.format(test=Test(), foo=42)
'42'
>>> '{test}: {foo}'.format(test=Test(), foo=42)
str
'version-number: 42'
XZise added a comment.May 5 2015, 11:38 PM

Okay with 65450196 merged not adding {version} and {revision} to the user-agent format string it won't query the version number. So the question is what this bug report is about and if it actually did fix this bug (for pywikibot-core).

jayvdb set Security to None.
jayvdb renamed this task from Ability to override Pywikibot version completely to Ability to disable Pywikibot SCM version detection completely.Dec 11 2015, 11:15 AM
jayvdb added a project: Pywikibot.

1241b574 introduced a new usage of version.getversiondict which cant be disabled.

@saper, are you still using compat?

With regards to https://gerrit.wikimedia.org/r/#/c/208842/ , we could merge it and add config.useragent as a deprecated name of config.user_agent_format. Since compats config.useragent is a literal string, without any substitution, it nearly 100% compatible with cores config.user_agent_format (i.e. as long as it doesnt include any substitution parameters, which would be silly in compat anyway as they would be literal).

XZise added a comment.Dec 11 2015, 3:03 PM

Shouldn't it also be possible to have substitution parameters which won't be substituted by doubling the number of brackets (like {{version}} will result in {version}).