Skip to content

Commit

Permalink
Upgrade libraries, upgrade Peewee to latest version, fixing all issue…
Browse files Browse the repository at this point in the history
…s for upgrading peewee
  • Loading branch information
tomvlk committed Mar 13, 2022
1 parent a4d688d commit b3a1d48
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def upgrade(migrator: SchemaMigrator):
try:
migrate(
migrator.drop_index(MapFolder._meta.db_table, 'mapfolder_name'),
migrator.drop_index(MapFolder._meta.table_name, 'mapfolder_name'),
)
except Exception as e:
print(str(e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
def upgrade(migrator: SchemaMigrator):
expanded_score_field = FloatField(null=True)
migrate(
migrator.drop_not_null(Karma._meta.db_table, 'score'),
migrator.add_column(Karma._meta.db_table, 'expanded_score', expanded_score_field),
migrator.drop_not_null(Karma._meta.table_name, 'score'),
migrator.add_column(Karma._meta.table_name, 'expanded_score', expanded_score_field),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def upgrade(migrator: SchemaMigrator):
migrate(
migrator.add_index(LocalRecord._meta.db_table, [
migrator.add_index(LocalRecord._meta.table_name, [
'player_id', 'map_id'
], unique=True),
)
Expand Down
1 change: 0 additions & 1 deletion pyplanet/apps/contrib/mx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pyplanet.contrib.setting import Setting
from collections import namedtuple

from pyplanet.utils import gbxparser

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def upgrade(migrator: SchemaMigrator):
total_donations = IntegerField(default=0, null=False)

migrate(
migrator.add_column(Player._meta.db_table, 'total_playtime', total_playtime),
migrator.add_column(Player._meta.db_table, 'total_donations', total_donations),
migrator.add_column(Player._meta.table_name, 'total_playtime', total_playtime),
migrator.add_column(Player._meta.table_name, 'total_donations', total_donations),
)


def downgrade(migrator: SchemaMigrator):
migrate(
migrator.drop_column(Player._meta.db_table, 'total_playtime'),
migrator.drop_column(Player._meta.db_table, 'total_donations'),
migrator.drop_column(Player._meta.table_name, 'total_playtime'),
migrator.drop_column(Player._meta.table_name, 'total_donations'),
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def upgrade(migrator: SchemaMigrator):
mx_id = IntegerField(default=None, null=True, index=True)

migrate(
migrator.add_column(Map._meta.db_table, 'mx_id', mx_id),
migrator.add_column(Map._meta.table_name, 'mx_id', mx_id),
)


def downgrade(migrator: SchemaMigrator):
migrate(
migrator.drop_column(Map._meta.db_table, 'mx_id'),
migrator.drop_column(Map._meta.table_name, 'mx_id'),
)
2 changes: 1 addition & 1 deletion pyplanet/apps/core/statistics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class Score(Model):
"""

class Meta:
db_table = 'stats_scores'
table_name = db_table = 'stats_scores'
16 changes: 0 additions & 16 deletions pyplanet/conf/project_template/manage.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
#!/usr/bin/env python3
import os
import sys

if __name__ == '__main__':

# Use Python for the configuration
os.environ.setdefault('PYPLANET_SETTINGS_METHOD', 'env')
os.environ.setdefault('PYPLANET_SETTINGS_MODULE', 'settings')

# Use YAML for configuration (comment other options and uncomment the following two lines).
# os.environ.setdefault('PYPLANET_SETTINGS_METHOD', 'yaml')
# os.environ.setdefault('PYPLANET_SETTINGS_DIRECTORY', 'settings')
# Will search for two files in the directory: base.yaml and apps.yaml. See http://pypla.net for more information.

# Use JSON for configuration (comment other options and uncomment the following two lines).
# os.environ.setdefault('PYPLANET_SETTINGS_METHOD', 'json')
# os.environ.setdefault('PYPLANET_SETTINGS_DIRECTORY', 'settings')
# Will search for two files in the directory: base.json and apps.json. See http://pypla.net for more information.

try:
from pyplanet.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
8 changes: 4 additions & 4 deletions pyplanet/contrib/chat/query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import collections
import typing

from xmlrpc.client import Fault

Expand Down Expand Up @@ -60,7 +60,7 @@ def to_players(self, *players):
:rtype: pyplanet.contrib.chat.query.ChatQuery
"""
# Unpack list in unpacked list if given.
if len(players) == 1 and isinstance(players[0], collections.Iterable):
if len(players) == 1 and isinstance(players[0], typing.Iterable):
players = players[0]

# Replace logins.
Expand All @@ -70,7 +70,7 @@ def to_players(self, *players):
elif isinstance(players, str):
self._logins = set()
self._logins.add(players)
elif isinstance(players, collections.Iterable) and isinstance(players, collections.Sized):
elif isinstance(players, typing.Iterable) and isinstance(players, typing.Sized):
self._logins = set()
self.add_to(players)
return self
Expand All @@ -84,7 +84,7 @@ def add_to(self, *players):
:rtype: pyplanet.contrib.chat.query.ChatQuery
"""
# Unpack list in unpacked list if given.
if len(players) == 1 and isinstance(players[0], collections.Iterable):
if len(players) == 1 and isinstance(players[0], typing.Iterable):
players = players[0]

# Check if we already have login lists.
Expand Down
12 changes: 6 additions & 6 deletions pyplanet/core/db/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime

from peewee import Model as PeeweeModel, ReverseRelationDescriptor
from peewee import Model as PeeweeModel, ForeignKeyField
from peewee import DateTimeField
from peewee_async import Manager

Expand All @@ -18,7 +18,7 @@ async def get_related(self, instance, related_name, single_backref=False):
model_cls = type(instance)
related_field = getattr(model_cls, related_name)

if isinstance(related_field, ReverseRelationDescriptor):
if not isinstance(related_field, ForeignKeyField):
return await self._get_backrefs(instance, related_name, single_backref)
else:
return await self._get_foreign_key_target(instance, related_name)
Expand All @@ -29,7 +29,7 @@ async def _get_foreign_key_target(self, instance, field_name):
model_cls = type(instance)
foreign_key_field = getattr(model_cls, field_name)
target_cls = foreign_key_field.rel_model
target_field = foreign_key_field.to_field
target_field = foreign_key_field.rel_field

return await self.get(target_cls, target_field == foreign_key_value)

Expand Down Expand Up @@ -78,10 +78,10 @@ async def get_related(self, related_name, single_backref=False):
return await self.objects.get_related(self, related_name, single_backref)

async def save(self, force_insert=False, only=None):
field_dict = dict(self._data)
field_dict = dict(self.__data__)
if self._meta.primary_key is not False:
pk_field = self._meta.primary_key
pk_value = self._get_pk_value()
pk_value = self._pk
else:
pk_field = pk_value = None
if only:
Expand Down Expand Up @@ -109,7 +109,7 @@ async def save(self, force_insert=False, only=None):
pk_from_cursor = await self._insert(**field_dict)
if pk_from_cursor is not None:
pk_value = pk_from_cursor
self._set_pk_value(pk_value)
self._pk = pk_value
rows = 1
self._dirty.clear()
return rows
Expand Down
1 change: 0 additions & 1 deletion pyplanet/core/gbx/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ async def connect(self):
self.reader, self.writer = await asyncio.open_connection(
host=self.host,
port=self.port,
loop=self.event_loop,
)
break
except Exception as exc:
Expand Down
6 changes: 3 additions & 3 deletions pyplanet/core/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def execute(self):
subcommand = 'help'

# Check for platform requirements. (Python version)
if sys.version_info[0] < 3 or sys.version_info[1] <= 5:
if sys.version_info[0] < 3 or sys.version_info[1] <= 9:
print('WARNING')
print('WARNING: Your Python version is not officially supported by PyPlanet, please upgrade your Python!')
print('WARNING: Your Python version is outdated and not supported by PyPlanet, please upgrade your Python!')
print('WARNING')
if sys.version_info[0] > 3 or sys.version_info[1] > 8:
if sys.version_info[0] > 3 or sys.version_info[1] > 10:
print('WARNING')
print('WARNING: Your Python version is untested and most likely not working with PyPlanet!')
print('WARNING')
Expand Down
14 changes: 7 additions & 7 deletions pyplanet/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class Raven: # pragma: no cover

@classmethod
def get_client(cls):
if not cls.CLIENT:
cls.CLIENT = Client(
dsn='https://bcbafd2d81234d53b32c66077ae0a008:98dcc46acc484eeb95ebf9f0c30e6dd4@sentry.s3.toffe.me/2',
environment='development' if settings.PYPLANET_DEBUG else 'production',
release=version,
include_paths=['pyplanet']
)
# if not cls.CLIENT:
# cls.CLIENT = Client(
# dsn='https://bcbafd2d81234d53b32c66077ae0a008:98dcc46acc484eeb95ebf9f0c30e6dd4@sentry.s3.toffe.me/2',
# environment='development' if settings.PYPLANET_DEBUG else 'production',
# release=version,
# include_paths=['pyplanet']
# )
return cls.CLIENT


Expand Down
4 changes: 2 additions & 2 deletions pyplanet/utils/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Changed by Tom Valk: Added function to detect if the release is a pre-release.
"""

import collections
import re
from collections import namedtuple


__version__ = '2.7.7'
Expand Down Expand Up @@ -63,7 +63,7 @@ def parse(version):
return version_parts


class VersionInfo(collections.namedtuple(
class VersionInfo(namedtuple(
'VersionInfo', 'major minor patch prerelease build')):
"""
:param int major: version when you make incompatible API changes.
Expand Down
29 changes: 13 additions & 16 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
# Base
colorlog==4.8.0
colorlog==6.6.0

# Templating
Jinja2==2.11.3
MarkupSafe==2.0.1
Jinja2==3.0.3
MarkupSafe==2.1.0

# DB/Storage
peewee==2.10.2
peewee-async==0.5.12
aiopg==1.2.1
aiomysql==0.0.20
pymysql==0.9.2
# apyio==0.2.0
aiofiles==0.4.0
asyncssh==1.18.0
peewee==3.14.10
peewee-async==0.7.2
aiomysql==0.0.22
pymysql==0.9.3
aiofiles==0.8.0
asyncssh==2.9.0

# Network
aiohttp==2.3.9
requests==2.25.1
urllib3==1.26.5
aiohttp==3.8.1
requests==2.27.1
urllib3==1.26.8

# Utils
cached-property==1.5.2
watchdog==0.10.2
watchdog==2.1.6
pandas==1.4.1
numpy==1.22.3
async_generator==1.10
asyncio_extras==1.3.2
bcrypt==3.2.0
raven==6.10.0
xmltodict==0.12.0
PyYAML==5.4.1
python-dotenv==0.19.2

cryptography==36.0.1

0 comments on commit b3a1d48

Please sign in to comment.