sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
951 stars 405 forks source link

version: output file modification date if no version info present for /plugins file #2542

Closed ghost closed 8 months ago

ghost commented 8 months ago

Requested Feature

If a myplugin.py in /plugins doesn't have __version__ = 'whatever' present, perhaps we could fallback to displaying the modification date of the file?

e.g.:

\<user> .version myplugin \<bot> [version] myplugin modified 2023-11-02 @ 01:54UTC

And the timestamp could follow whatever preference order of user's timezone/formatting desired. (prefer default, then user, then channel? something like that)

Problems Solved

Better than:

\<user> .version myplugin \<bot> [version] myplugin (unknown)

in my opinion.

Alternatives

N/A

Notes

For simplicity, I could understand just always using UTC and following ISO 8601.

SnoopJ commented 8 months ago

The modified time depends on the installation process, so that if I do a fresh install of sopel-mastodon today, I will get an mtime (and other stat times) for 1 Nov, but if someone installed it yesterday or installs it tomorrow, they can get 31 Oct or 2 Nov, even if we have exactly the same plugin content. I'm not even sure if this behavior is consistent across platforms, but one counterexample should suffice for my point.

-1 from me, I don't think the potential benefits outweigh the wrinkles, especially when there's an affordance for plugin authors to declare their version.

dgw commented 8 months ago

Oh boy are there a lot of wrinkles.

Logically this would live not in the version plugin, but in the plugins.handlers.PyFilePlugin class as an override of the get_version() method. That part isn't too bad, until you realize that a PyFilePlugin might also be a directory with an __init__.py. Then you really get into the question of "yeah, modification time, but whose modification time?"

There's also another problem: A plugin handler doesn't have access to the bot or any of its user data, so formatting the timestamp (assuming you can pick the right one, out of a folder) according to user/channel/config settings is a no-go.

I'm also leaning toward "Just spend one line from your weekly line budget and write __version__ = 'idk whatever' someplace in your plugin file." As long as the value is (or can be converted to) a string, you're golden.

_For dirty-hack points, you can do __version__ = os.path.getmtime(__file__). For supreme overkill dirty-hack points you can getmtime(), pass it (converted to datetime) through tools.time.format_time(), and assign the result as __version__._

ghost commented 8 months ago

I figured, but no one answered in chat, so GitHub Issue it was! :P

I'm also leaning toward "Just spend one line from your weekly line budget and write __version__ = 'idk whatever' someplace in your plugin file." As long as the value is (or can be converted to) a string, you're golden.

You want me to form a new habit?! What a monster! 😜