Skip to content

Upgrading to Piqueserver: Porting scripts to Python 3 #15

Description

@hourai-dev

As you know, we are upgrading to Piqueserver. All current scripts must be made compatible with Python 3 and Piqueserver's script API. Piqueserver's script API is similar to PySnip's, but there are still some changes that need to be taken care of. Here are some tips and recommendations to ease the porting process up:

  • Use the 2to3 python module to convert scripts from python 2 to python 3. I recommend you first run 2to3 script_name.py and review what changes will be made. Once you are sure you want to convert the script, run 2to3 -w script_name.py, this will modify the script file. 2to3 also creates a backup of the converted script when using the -w option, named script_name.py.bak, in case things go wrong or you need the older file back. There's a special situation to keep in mind, for some reason, in scripts which import the commands module, 2to3 replaces this module with the subprocess module, so make sure to change it back after running 2to3 in case your script is affected. Refer to the 2to3 documentation for more info.
  • Read the Piqueserver Porting scripts documentation.
  • Read Piqueserver's source code, including the scripts which are included with piqueserver. There's nothing better than learning what changed straight from the source, right?
  • Please, if you find any trouble with Piqueserver's API, discuss it here. That way we get to know about things that changed with the API. For example, it's worth knowing Piqueserver no longer has the pyspades.types module (actually it does, but the old type classes are gone). This means no more MultikeyDict and etc. This change also affects the server's players variable. In PySnip, the players member of the ServerProtocol class used to be a MultikeyDict. In Piqueserver, it is now a normal python dict, with the player_id as key and the player object as value. Another important thing is that commands now word differently, instead of using the @admin decorator and the name and add functions, now you just use the @command decorator, with the command name, arguments and extra keyword arguments (like admin_only). You need to import command from the piqueserver.commands module. Share your findings in this issue comments.

Progress:

This list may not be exhaustive and will probably be expanded in the near future. Marked items are ported scripts so far.

  • powers
  • rpg_mod
  • foxcatcher
  • infiblocks
  • trollscriptplus
  • ABBS
  • bots2
  • improvedweapons
  • daycycle
  • kraken
  • dep: cbc
  • dep: buildbox
  • dep: easyaos

Also, testing the already ported scripts and searching for bugs would be helpful, if you can. If you are going to work on porting a script, say so in the comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c:scriptsIssues relating to scriptss:needs testingThe issue or feature described in the issue requires further testing.t:help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions