From a4f5ae2c96b93578d2f1d22afd71e5b4ecedec81 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 15 May 2021 23:46:34 +0200 Subject: [PATCH] Add support for latest Twisted and Python 3.9 --- docs/source/Setup/Extended-Installation.md | 50 +++++++++++----------- docs/source/Setup/Setup-Quickstart.md | 39 +++++++++-------- evennia/commands/default/system.py | 3 +- evennia/contrib/awsstorage/tests.py | 11 ++++- evennia/server/portal/mccp.py | 5 +-- evennia/server/portal/mssp.py | 9 ++-- evennia/server/portal/mxp.py | 5 +-- evennia/server/portal/naws.py | 8 ++-- evennia/server/portal/suppress_ga.py | 5 +-- evennia/server/portal/telnet_oob.py | 19 ++++---- evennia/server/portal/ttype.py | 10 ++--- requirements.txt | 3 +- 12 files changed, 85 insertions(+), 82 deletions(-) diff --git a/docs/source/Setup/Extended-Installation.md b/docs/source/Setup/Extended-Installation.md index dfbae66c79..a4cc86eb4f 100644 --- a/docs/source/Setup/Extended-Installation.md +++ b/docs/source/Setup/Extended-Installation.md @@ -25,9 +25,9 @@ more detailed instructions for your platform. 1. Install Python, GIT and python-virtualenv. Start a Console/Terminal. 2. `cd` to some place you want to do your development (like a folder `/home/anna/muddev/` on Linux or a folder in your personal user directory on Windows). -3. `git clone https://github.com/evennia/evennia.git` -4. `virtualenv evenv` -5. `source evenv/bin/activate` (Linux, Mac), `evenv\Scripts\activate` (Windows) +3. `git clone https://github.com/evennia/evennia.git` (a new folder `evennia` is created) +4. `python -m venv evenv` (a new folder `evenv` is created) +5. `source evenv/bin/activate` (Linux, Mac), `evenv\Scripts\activate` (Windows) 6. `pip install -e evennia` 7. `evennia --init mygame` 8. `cd mygame` @@ -48,7 +48,7 @@ everything in the following sections. - Windows (Vista, Win7, Win8, Win10) - Mac OSX (>=10.5 recommended) -- [Python](http://www.python.org) (v3.7, 3.8 are tested) +- [Python](http://www.python.org) (v3.7, 3.8 and 3.9 are tested) - [virtualenv](http://pypi.python.org/pypi/virtualenv) for making isolated Python environments. Installed with `pip install virtualenv`. @@ -104,7 +104,7 @@ contains the source code though, it is not *installed* yet. To isolate the Evennia install and its dependencies from the rest of the system, it is good Python practice to install into a _virtualenv_. If you are unsure about what a virtualenv is and why it's useful, see the [Glossary entry on -virtualenv](Glossary#virtualenv). +virtualenv](Glossary#virtualenv). Run `python -V` to see which version of Python your system defaults to. @@ -112,7 +112,7 @@ Run `python -V` to see which version of Python your system defaults to. # If your Linux defaults to Python3.7+: virtualenv evenv -# If your Linux defaults to Python2 or an older version +# If your Linux defaults to Python2 or an older version # of Python3, you must instead point to Python3.7+ explicitly: virtualenv -p /usr/bin/python3.7 evenv ``` @@ -120,7 +120,7 @@ virtualenv -p /usr/bin/python3.7 evenv A new folder `evenv` will appear (we could have called it anything). This folder will hold a self-contained setup of Python packages without interfering with default Python packages on your system (or the Linux distro lagging behind -on Python package versions). It will also always use the right version of Python. +on Python package versions). It will also always use the right version of Python. Activate the virtualenv: ``` @@ -128,7 +128,7 @@ source evenv/bin/activate ``` The text `(evenv)` should appear next to your prompt to show that the virtual -environment is active. +environment is active. > Remember that you need to activate the virtualenv like this *every time* you > start a new terminal to get access to the Python packages (notably the @@ -196,7 +196,7 @@ here](http://git-scm.com/book/en/Getting-Started-Installing-Git#Installing-on-Ma * If you run into issues with installing `Twisted` later you may need to install gcc and the Python headers. -After this point you should not need `sudo` or any higher privileges to install anything. +After this point you should not need `sudo` or any higher privileges to install anything. Now create a folder where you want to do all your Evennia development: @@ -215,9 +215,9 @@ A new folder `evennia` will appear containing the Evennia library. This only contains the source code though, it is not *installed* yet. To isolate the Evennia install and its dependencies from the rest of the system, it is good Python practice to install into a _virtualenv_. If you are unsure about what a -virtualenv is and why it's useful, see the [Glossary entry on virtualenv](../Glossary#virtualenv). +virtualenv is and why it's useful, see the [Glossary entry on virtualenv](../Glossary#virtualenv). -Run `python -V` to check which Python your system defaults to. +Run `python -V` to check which Python your system defaults to. ``` @@ -237,7 +237,7 @@ source evenv/bin/activate ``` The text `(evenv)` should appear next to your prompt to show the virtual -environment is active. +environment is active. > Remember that you need to activate the virtualenv like this *every time* you > start a new terminal to get access to the Python packages (notably the @@ -292,10 +292,10 @@ created. Check out [where to go next](./Getting-Started#where-to-go-next). ## Windows Install -If you run into any issues during the installation, please check out -[Windows Troubleshooting](./Getting-Started#windows-troubleshooting). +If you run into any issues during the installation, please check out +[Windows Troubleshooting](./Getting-Started#windows-troubleshooting). -> If you are running Windows10, consider using the Windows Subsystem for Linux +> If you are running Windows10, consider using the Windows Subsystem for Linux > ([WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)) instead. > You should then follow the Linux install instructions above. @@ -320,7 +320,7 @@ environment", you should select the second option "Use Git from the Windows Command Prompt", which gives you more freedom as to where you can use the program. * Finally you must install the [Microsoft Visual C++ compiler for -Python](https://aka.ms/vs/16/release/vs_buildtools.exe). Download and run the linked installer and +Python](https://aka.ms/vs/16/release/vs_buildtools.exe). Download and run the linked installer and install the C++ tools. Keep all the defaults. Allow the install of the "Win10 SDK", even if you are on Win7 (not tested on older Windows versions). If you later have issues with installing Evennia due to a failure to build the "Twisted wheels", this is where you are missing things. @@ -348,7 +348,7 @@ A new folder `evennia` will appear containing the Evennia library. This only contains the source code though, it is not *installed* yet. To isolate the Evennia install and its dependencies from the rest of the system, it is good Python practice to install into a _virtualenv_. If you are unsure about what a -virtualenv is and why it's useful, see the [Glossary entry on virtualenv](../Glossary#virtualenv). +virtualenv is and why it's useful, see the [Glossary entry on virtualenv](../Glossary#virtualenv). In your console, try `python -V` to see which version of Python your system defaults to. @@ -380,7 +380,7 @@ evenv\scripts\activate.bat ``` The text `(evenv)` should appear next to your prompt to show the virtual -environment is active. +environment is active. > Remember that you need to activate the virtualenv like this *every time* you > start a new console window if you want to get access to the Python packages @@ -433,16 +433,16 @@ created. Check out [where to go next](./Getting-Started#where-to-go-next). ## Non-interactive setup When you first run `evennia start` after having created the database, you will be asked -to interactively insert the superuser username, email and password. If you need to do +to interactively insert the superuser username, email and password. If you need to do this in an automated faction (such as in an automated build flow), you can supply those values as environment variables, `EVENNIA_SUPERUSER_USERNAME`, `EVENNIA_SUPERUSER_EMAIL` and -`EVENNIA_SUPERUSER_PASSWORD`. The email can be left out and will then be set to be the -empty string. +`EVENNIA_SUPERUSER_PASSWORD`. The email can be left out and will then be set to be the +empty string. Use this to start Evennia (the envvars will be ignored on subsequent starts): ``` -EVENNIA_SUPERUSER_USERNAME=Foo EVENNIA_SUPERUSER_PASSWORD=MygreatPwd evennia start +EVENNIA_SUPERUSER_USERNAME=Foo EVENNIA_SUPERUSER_PASSWORD=MygreatPwd evennia start ``` @@ -460,8 +460,8 @@ tutorial is built. Once done, the `tutorial` exit will have appeared out of Limb Once you get back to `Limbo` from the tutorial (if you get stuck in the tutorial quest you can do `@tel #2` to jump to Limbo), a good idea is to learn how to [start, stop and reload](Start-Stop- -Reload) the Evennia server. You may also want to familiarize yourself with some -[commonly used terms in our Glossary](../Glossary). After that, why not experiment with +Reload) the Evennia server. You may also want to familiarize yourself with some +[commonly used terms in our Glossary](../Glossary). After that, why not experiment with [creating some new items and build some new rooms](../Howto/Starting/Part1/Building-Quickstart) out from Limbo. From here on, you could move on to do one of our [introductory tutorials](../Howto/Howto-Overview) or simply dive @@ -496,7 +496,7 @@ you can run `evennia -l`, or (in the future) start the server with `evennia star ### Linux Troubleshooting - If you get an error when installing Evennia (especially with lines mentioning - failing to include `Python.h`) then try `sudo apt-get install python3-setuptools python3-dev`. + failing to include `Python.h`) then try `sudo apt-get install python3-setuptools python3-dev`. Once installed, run `pip install -e evennia` again. - Under some not-updated Linux distributions you may run into errors with a too-old `setuptools` or missing `functools`. If so, update your environment diff --git a/docs/source/Setup/Setup-Quickstart.md b/docs/source/Setup/Setup-Quickstart.md index 75df89acfc..e3dea0103f 100644 --- a/docs/source/Setup/Setup-Quickstart.md +++ b/docs/source/Setup/Setup-Quickstart.md @@ -1,15 +1,15 @@ # Setup quickstart -The Evennia server is installed, run and maintained from the terminal (console/CMD on Windows). Starting the +The Evennia server is installed, run and maintained from the terminal (console/CMD on Windows). Starting the server doesn't make anything visible online. Once you download everything you can in fact develop your game -in complete isolation if you want, without needing any access to the internet. +in complete isolation if you want, without needing any access to the internet. ## Installation -Evennia requires Python3.7+. As with most Python packages, using a +Evennia supports Python 3.7 to 3.9. As with most Python packages, using a [virtualenv](../Glossary#virtualenv) is recommended in order to keep your -installation independent from the system libraries. It's _not_ recommended -to install Evennia as superuser. +installation independent from the system libraries. It's _not_ recommended +to install Evennia as superuser. ```warning:: @@ -20,16 +20,17 @@ to install Evennia as superuser. Make sure the `evennia` command works. Use `evennia -h` for usage help (or read on). -If you are having trouble, want to install in some other way (like with Docker) or want to contribute to -Evennia itself, check out the [Extended Installation instructions](./Extended-Installation). -It also has a [troubleshooting section](./Extended-Installation#Troubleshooting) for different operating +If you are having trouble, want to install in some other way (like with Docker) +or want to contribute to Evennia itself, check out the [Extended Installation +instructions](./Extended-Installation). It also has a [troubleshooting +section](./Extended-Installation#Troubleshooting) for different operating systems. ## Initialize a new game -Use `cd` to enter a folder where you want to do your game development. Here (and in -the rest of the Evennia documentation) we call this folder `mygame`, but you should of course +Use `cd` to enter a folder where you want to do your game development. Here (and in +the rest of the Evennia documentation) we call this folder `mygame`, but you should of course name your game whatever you like: evennia --init mygame @@ -40,14 +41,14 @@ contains empty templates and all the default settings needed to start the server ## Start the new game -`cd` into your game folder (`mygame` in our case). Next, run +`cd` into your game folder (`mygame` in our case). Next, run evennia migrate This will create the default database (Sqlite3). The database file ends up as `mygame/server/evennia.db3`. If you ever want to start from a fresh database, just delete this file and re-run `evennia migrate` again. - evennia start + evennia start Set your user-name and password when prompted. This will be the "god user" or "superuser" in-game. The email is optional. @@ -57,36 +58,36 @@ a web browser at [http://localhost:4001](http://localhost:4001) to play your new > If `localhost` doesn't work on your computer, use `127.0.0.1`, which is the same thing. -## See server logs +## See server logs This will echol the server logs to the terminal as they come in: evennia --log -or +or - evennia -l + evennia -l You can also start logging immediately when running `evennia` commands, such as - evennia start -l + evennia start -l To exit the log view, enter `Ctrl-C` (`Cmd-C` for Mac). This will not affect the server. -## Restarting and stopping +## Restarting and stopping You can restart the server without disconnecting any connected players: - evennia restart + evennia restart To do a full stop and restart (will disconnect everyone): - evennia reboot + evennia reboot Full stop of the server (will need to use `start` to activate it again): diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index 69b688e7b2..a409b82afc 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -932,7 +932,8 @@ class CmdAbout(COMMAND_DEFAULT_CLASS): |wLicence|n https://opensource.org/licenses/BSD-3-Clause |wWeb|n http://www.evennia.com |wIrc|n #evennia on irc.freenode.net:6667 - |wForum|n http://www.evennia.com/discussions + |wDiscord|n https://discord.gg/SVCkd4cY3q + |wForum|n https://github.com/evennia/evennia/discussions |wMaintainer|n (2010-) Griatch (griatch AT gmail DOT com) |wMaintainer|n (2006-10) Greg Taylor diff --git a/evennia/contrib/awsstorage/tests.py b/evennia/contrib/awsstorage/tests.py index d764262524..6e20a8243f 100644 --- a/evennia/contrib/awsstorage/tests.py +++ b/evennia/contrib/awsstorage/tests.py @@ -8,8 +8,13 @@ from django.utils.timezone import is_aware, utc import datetime, gzip, pickle, threading -from botocore.exceptions import ClientError -from evennia.contrib.awsstorage import aws_s3_cdn as s3boto3 +_SKIP = False +try: + from botocore.exceptions import ClientError + from evennia.contrib.awsstorage import aws_s3_cdn as s3boto3 +except ImportError: + _SKIP = True + try: from django.utils.six.moves.urllib import parse as urlparse @@ -23,12 +28,14 @@ except ImportError: # Python 3.2 and below import mock +@skipIf(_SKIP, "botocore not installed") class S3Boto3TestCase(TestCase): def setUp(self): self.storage = s3boto3.S3Boto3Storage(access_key="foo", secret_key="bar") self.storage._connections.connection = mock.MagicMock() +@skipIf(_SKIP, "botocore not installed") class S3Boto3StorageTests(S3Boto3TestCase): def test_clean_name(self): """ diff --git a/evennia/server/portal/mccp.py b/evennia/server/portal/mccp.py index 2d00e479b6..43390b19bc 100644 --- a/evennia/server/portal/mccp.py +++ b/evennia/server/portal/mccp.py @@ -15,10 +15,9 @@ This protocol is implemented by the telnet protocol importing mccp_compress and calling it from its write methods. """ import zlib -from twisted.python.compat import _bytesChr as chr # negotiations for v1 and v2 of the protocol -MCCP = chr(86) # b"\x56" +MCCP = bytes([86]) # b"\x56" FLUSH = zlib.Z_SYNC_FLUSH @@ -38,7 +37,7 @@ def mccp_compress(protocol, data): return data -class Mccp(object): +class Mccp: """ Implements the MCCP protocol. Add this to a variable on the telnet protocol to set it up. diff --git a/evennia/server/portal/mssp.py b/evennia/server/portal/mssp.py index d939bcc37b..1c953e8559 100644 --- a/evennia/server/portal/mssp.py +++ b/evennia/server/portal/mssp.py @@ -12,17 +12,16 @@ active players and so on. """ from django.conf import settings from evennia.utils import utils -from twisted.python.compat import _bytesChr as bchr -MSSP = bchr(70) # b"\x46" -MSSP_VAR = bchr(1) # b"\x01" -MSSP_VAL = bchr(2) # b"\x02" +MSSP = bytes([70]) # b"\x46" +MSSP_VAR = bytes([1]) # b"\x01" +MSSP_VAL = bytes([2]) # b"\x02" # try to get the customized mssp info, if it exists. MSSPTable_CUSTOM = utils.variable_from_module(settings.MSSP_META_MODULE, "MSSPTable", default={}) -class Mssp(object): +class Mssp: """ Implements the MSSP protocol. Add this to a variable on the telnet protocol to set it up. diff --git a/evennia/server/portal/mxp.py b/evennia/server/portal/mxp.py index 8ff773036d..6c938ab709 100644 --- a/evennia/server/portal/mxp.py +++ b/evennia/server/portal/mxp.py @@ -14,12 +14,11 @@ http://www.gammon.com.au/mushclient/addingservermxp.htm """ import re -from twisted.python.compat import _bytesChr as bchr LINKS_SUB = re.compile(r"\|lc(.*?)\|lt(.*?)\|le", re.DOTALL) # MXP Telnet option -MXP = bchr(91) # b"\x5b" +MXP = bytes([91]) # b"\x5b" MXP_TEMPSECURE = "\x1B[4z" MXP_SEND = MXP_TEMPSECURE + '' + "\\2" + MXP_TEMPSECURE + "" @@ -42,7 +41,7 @@ def mxp_parse(text): return text -class Mxp(object): +class Mxp: """ Implements the MXP protocol. diff --git a/evennia/server/portal/naws.py b/evennia/server/portal/naws.py index caa9f73402..621bbb22bd 100644 --- a/evennia/server/portal/naws.py +++ b/evennia/server/portal/naws.py @@ -11,10 +11,10 @@ client and update it when the size changes """ from codecs import encode as codecs_encode from django.conf import settings -from twisted.python.compat import _bytesChr as bchr -NAWS = bchr(31) # b"\x1f" -IS = bchr(0) # b"\x00" +NAWS = bytes([31]) # b"\x1f" +IS = bytes([0]) # b"\x00" + # default taken from telnet specification DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH DEFAULT_HEIGHT = settings.CLIENT_DEFAULT_HEIGHT @@ -22,7 +22,7 @@ DEFAULT_HEIGHT = settings.CLIENT_DEFAULT_HEIGHT # try to get the customized mssp info, if it exists. -class Naws(object): +class Naws: """ Implements the NAWS protocol. Add this to a variable on the telnet protocol to set it up. diff --git a/evennia/server/portal/suppress_ga.py b/evennia/server/portal/suppress_ga.py index 21332ea070..694f09b73a 100644 --- a/evennia/server/portal/suppress_ga.py +++ b/evennia/server/portal/suppress_ga.py @@ -13,16 +13,15 @@ It is set as the NOGOAHEAD protocol_flag option. http://www.faqs.org/rfcs/rfc858.html """ -from twisted.python.compat import _bytesChr as bchr -SUPPRESS_GA = bchr(3) # b"\x03" +SUPPRESS_GA = bytes([3]) # b"\x03" # default taken from telnet specification # try to get the customized mssp info, if it exists. -class SuppressGA(object): +class SuppressGA: """ Implements the SUPRESS-GO-AHEAD protocol. Add this to a variable on the telnet protocol to set it up. diff --git a/evennia/server/portal/telnet_oob.py b/evennia/server/portal/telnet_oob.py index f541ba4d71..4734b72c95 100644 --- a/evennia/server/portal/telnet_oob.py +++ b/evennia/server/portal/telnet_oob.py @@ -26,23 +26,22 @@ This implements the following telnet OOB communication protocols: import re import json from evennia.utils.utils import is_iter -from twisted.python.compat import _bytesChr as bchr # General Telnet from twisted.conch.telnet import IAC, SB, SE # MSDP-relevant telnet cmd/opt-codes -MSDP = bchr(69) -MSDP_VAR = bchr(1) -MSDP_VAL = bchr(2) -MSDP_TABLE_OPEN = bchr(3) -MSDP_TABLE_CLOSE = bchr(4) +MSDP = bytes([69]) +MSDP_VAR = bytes([1]) +MSDP_VAL = bytes([2]) +MSDP_TABLE_OPEN = bytes([3]) +MSDP_TABLE_CLOSE = bytes([4]) -MSDP_ARRAY_OPEN = bchr(5) -MSDP_ARRAY_CLOSE = bchr(6) +MSDP_ARRAY_OPEN = bytes([5]) +MSDP_ARRAY_CLOSE = bytes([6]) # GMCP -GMCP = bchr(201) +GMCP = bytes([201]) # pre-compiled regexes @@ -69,7 +68,7 @@ EVENNIA_TO_GMCP = { # MSDP/GMCP communication handler -class TelnetOOB(object): +class TelnetOOB: """ Implements the MSDP and GMCP protocols. """ diff --git a/evennia/server/portal/ttype.py b/evennia/server/portal/ttype.py index d74b3ae9db..8125277644 100644 --- a/evennia/server/portal/ttype.py +++ b/evennia/server/portal/ttype.py @@ -9,13 +9,13 @@ etc. If the client does not support TTYPE, this will be ignored. All data will be stored on the protocol's protocol_flags dictionary, under the 'TTYPE' key. + """ -from twisted.python.compat import _bytesChr as bchr # telnet option codes -TTYPE = bchr(24) # b"\x18" -IS = bchr(0) # b"\x00" -SEND = bchr(1) # b"\x01" +TTYPE = bytes([24]) # b"\x18" +IS = bytes([0]) # b"\x00" +SEND = bytes([1]) # b"\x01" # terminal capabilities and their codes MTTS = [ @@ -30,7 +30,7 @@ MTTS = [ ] -class Ttype(object): +class Ttype: """ Handles ttype negotiations. Called and initiated by the telnet protocol. diff --git a/requirements.txt b/requirements.txt index f471f0405c..e6a7678626 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,10 +3,9 @@ # general attrs >= 19.2.0 django >= 3.2, < 3.3 -twisted >= 20.3.0, < 21.0.0 +twisted >= 20.3.0, < 22.0.0 pytz djangorestframework >= 3.10.3, < 3.12 -# django-filter >= 2.2.0, < 2.3 django-filter == 2.4 django-sekizai == 2.0 inflect >= 5.2.0