Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 9 support #1191

Open
wants to merge 10 commits into
base: legacy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ repos:
hooks:
- id: restore-commit-msg
- repo: https://github.com/jorisroovers/gitlint
rev: v0.13.1
rev: v0.15.1
hooks:
- id: gitlint
- repo: https://github.com/Seeefo/manage-commit-msg.git
rev: 1.0.3
hooks:
- id: save-commit-msg
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
rev: 3.9.2
hooks:
- id: flake8
language_version: python3
additional_dependencies: [flake8-bugbear, flake8-logging-format, flake8-variables-names, pep8-naming, flake8-eradicate]
args: [ --builtins=_ ]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.6.4
rev: v5.9.3
hooks:
- id: isort
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
############################
# MAD
############################
FROM python:3.7-slim AS mad-core
FROM python:3.9-slim AS mad-core
# Working directory for the application
WORKDIR /usr/src/app

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM local_mad_production:latest AS dev_test
# Versions of python to install for pyenv. These are used when tox executes specific
# python versions. The correct versions need to be added to tox.ini under tox/envlist
# 3.7 is the base image so it does not need to be included
ENV PYTHON_VERSIONS 3.8.0
ENV PYTHON_VERSIONS 3.8.0 3.9.0
# User information related to how to run within the shell
ARG USER_NAME=dockeruser
ARG UID=1000
Expand Down
6 changes: 3 additions & 3 deletions mapadroid/madmin/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from . import apiRequest, apiResponse
from .apks import ftr_mad_apks
from .autoconf import ftr_autoconf
from .resources import (
ftr_area, ftr_auth, ftr_device, ftr_devicesetting, ftr_geofence,
ftr_monlist, ftr_pogoauth, ftr_routecalc, ftr_walker, ftr_walkerarea)
from .resources import (ftr_area, ftr_auth, ftr_device, ftr_devicesetting,
ftr_geofence, ftr_monlist, ftr_pogoauth, ftr_routecalc,
ftr_walker, ftr_walkerarea)

BASE_URI = '/api'
valid_resources = {
Expand Down
22 changes: 17 additions & 5 deletions mapadroid/route/RouteManagerBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,28 @@ def _start_check_routepools(self):
def join_threads(self):
self.logger.info("Shutdown Route Threads")
if self._update_prio_queue_thread is not None:
while self._update_prio_queue_thread.isAlive():

if hasattr(self._update_prio_queue_thread, 'isAlive'):
is_alive_func = self._update_prio_queue_thread.isAlive
else:
is_alive_func = self._update_prio_queue_thread.is_alive
while is_alive_func():
time.sleep(1)
self.logger.debug("Shutdown Prio Queue Thread - waiting...")
self._update_prio_queue_thread.join(5)

self.logger.debug("Shutdown Prio Queue Thread - done...")
if self._check_routepools_thread is not None:
while self._check_routepools_thread.isAlive():
time.sleep(1)
self.logger.debug("Shutdown Routepool Thread - waiting...")
self._check_routepools_thread.join(5)
if hasattr(self._check_routepools_thread, 'isAlive'):
while self._check_routepools_thread.isAlive():
time.sleep(1)
self.logger.debug("Shutdown Routepool Thread - waiting...")
self._check_routepools_thread.join(5)
else:
while self._check_routepools_thread.is_alive():
time.sleep(1)
self.logger.debug("Shutdown Routepool Thread - waiting...")
self._check_routepools_thread.join(5)

self._update_prio_queue_thread = None
self._check_routepools_thread = None
Expand Down
29 changes: 13 additions & 16 deletions mapadroid/utils/questGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self, args):

if not args.no_quest_titles:
locale_url = "https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20APK/{0}.txt"
remote_locale_url = "https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20Remote/" \
remote_locale_url = "https://raw.githubusercontent.com/" \
"PokeMiners/pogo_assets/master/Texts/Latest%20Remote/" \
"{0}.txt"

asset_language = QUEST_LANGUAGES.get(args.language, 'English')
Expand All @@ -55,7 +56,8 @@ def __init__(self, args):
if remote_locale is None:
remote_locale = {}
self.locale_resources = {**apk_locale, **remote_locale}
else: self.locale_resources = None
else:
self.locale_resources = None

@staticmethod
def __gen_assets_locale(url):
Expand Down Expand Up @@ -162,13 +164,13 @@ def questtype(self, quest_type):
return "Unknown quest type placeholder: {0}"

def rewarditem(self, itemid):
file = open_json_file('items')
if str(itemid) in file:
return (file[str(itemid)]['name'])
reward_file = open_json_file('items')
if str(itemid) in reward_file:
return (reward_file[str(itemid)]['name'])
return "Item " + str(itemid)

def pokemonname(self, id):
return self.pokemen_file[str(int(id))]["name"]
def pokemonname(self, pokemon_id):
return self.pokemen_file[str(int(pokemon_id))]["name"]

def get_pokemon_type_str(self, pt):
return self.pokemon_types[str(pt)].title() + _('-type')
Expand All @@ -183,7 +185,7 @@ def questtask(self, typeid, condition, target, quest_template, quest_title):
gettext.find('quest', 'locales', all=True)
throw_types = {"10": _("Nice"), "11": _("Great"),
"12": _("Excellent"), "13": _("Curveball")}
buddyLevels = {2: _("Good"), 3: _("Great"), 4: _("Ultra"), 5: _("Best")}
buddy_levels = {2: _("Good"), 3: _("Great"), 4: _("Ultra"), 5: _("Best")}
arr = {'0': target}
text = self.questtype(typeid)
# TODO use the dict instead of regex parsing in all logic
Expand Down Expand Up @@ -234,9 +236,6 @@ def questtask(self, typeid, condition, target, quest_template, quest_title):
elif condition_type == 26:
# Condition type 26 is alignment
alignment = con.get('with_pokemon_alignment', {}).get('alignment', [])
# POKEMON_ALIGNMENT_UNSET = 0;
# POKEMON_ALIGNMENT_SHADOW = 1;
# POKEMON_ALIGNMENT_PURIFIED = 2;
if len(alignment) == 1 and alignment[0] == 1:
arr['different'] = _(" shadow")
elif len(alignment) == 1 and alignment[0] == 2:
Expand Down Expand Up @@ -305,7 +304,6 @@ def questtask(self, typeid, condition, target, quest_template, quest_title):
if con.get('type', 0) == 11:
text = _("Use an item to {mega}evolve {0} Pokemon")
# Try to find the exact evolution item needed
# [{"type": 11, "with_item": {"item": 1106}}]
with_item = con.get('with_item', {}).get('item', None)
if with_item is not None:
text = _('Use {item} to {mega}evolve {0} Pokemon')
Expand Down Expand Up @@ -431,7 +429,6 @@ def questtask(self, typeid, condition, target, quest_template, quest_title):
cur += 1
text = _("Take {0} snapshots of {poke}")
elif re.search(r'"type": 1', condition) is not None:
# [{"type": 1, "with_pokemon_type": {"pokemon_type": [6]}}]
text = _("Take {0} snapshots of wild {type} Pokemon")
arr['wb'] = ""
arr['type'] = ""
Expand Down Expand Up @@ -473,7 +470,7 @@ def questtask(self, typeid, condition, target, quest_template, quest_title):
for con in condition_dict:
if con.get('type', 0) == 28:
level = con.get('with_buddy', {}).get('min_buddy_level', 0)
arr['level'] = buddyLevels.get(level, level)
arr['level'] = buddy_levels.get(level, level)
elif typeid == 53:
# type 53 is to do charged attacks (any kind of way gym/pvp/rocket)
arr['type'] = ''
Expand All @@ -500,8 +497,8 @@ def questtask(self, typeid, condition, target, quest_template, quest_title):
text = text.replace(_('PVP Battle(s)'), _('PVP Battle'))
arr['0'] = _("a")

for key, val in arr.items():
text = text.replace('{' + key + '}', str(val))
for key, text_replacement in arr.items():
text = text.replace('{' + key + '}', str(text_replacement))

text = text.replace(' ', ' ').strip()
return text
21 changes: 15 additions & 6 deletions mapadroid/worker/WorkerQuests.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,14 @@ def _post_move_location_routine(self, timestamp: float):

def _cleanup(self):
if self.clear_thread is not None:
while self.clear_thread.isAlive():
self.clear_thread.join()
time.sleep(1)
if hasattr(self.clear_thread, 'isAlive'):
while self.clear_thread.isAlive():
self.clear_thread.join()
time.sleep(1)
else:
while self.clear_thread.is_alive():
self.clear_thread.join()
time.sleep(1)

def _clear_thread(self):
self.logger.info('Starting clear Quest Thread')
Expand Down Expand Up @@ -589,11 +594,15 @@ def _try_to_open_pokestop(self, timestamp: float) -> LatestReceivedType:
return type_received
elif stop_type in (PositionStopType.STOP_CLOSED, PositionStopType.STOP_COOLDOWN,
PositionStopType.STOP_DISABLED):
self.logger.info("Stop at {}, {} is not spinnable at the moment ({})", self.current_location.lat,
self.current_location.lng, stop_type)
self.logger.info("Stop at {}, {} is not spinnable at the moment ({})",
self.current_location.lat,
self.current_location.lng,
stop_type)
return type_received
elif stop_type == PositionStopType.VISITED_STOP_IN_LEVEL_MODE_TO_IGNORE:
self.logger.info("Stop at {}, {} has been spun before and is to be ignored in the next round.")
self.logger.info("Stop at {}, {} has been spun before and is to be ignored in the next round.",
self.current_location.lat,
self.current_location.lng)
self._mapping_manager.routemanager_add_coords_to_be_removed(self._routemanager_name,
self.current_location.lat,
self.current_location.lng)
Expand Down
17 changes: 8 additions & 9 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
apkmirror-search
apkutils==0.8.3
apkutils==0.11.0
bitstring~=3.1
cachetools
ConfigArgParse~=0.14
dataclasses>=0.6
Flask~=1.1.4
Flask-Caching~=1.8.0
Flask~=2.0.2
Flask-Caching~=1.10.1
geopy~=1.20
gevent==1.4.0
gevent~=21.8.0
gpxdata~=1.2
greenlet<0.4.17
greenlet~=1.1
ImageHash~=4.0
imutils~=0.5
loguru~=0.4.0
markupsafe==2.0.1
matplotlib~=3.1
mysqlclient~=1.4
mysqlclient~=2.0.3
mysql-connector~=2.2
numpy~=1.18.0
opencv-python>=4.1,<4.3
numpy==1.21.4
opencv-python~=4.4
psutil~=5.6
pytesseract~=0.3
requests~=2.22
Expand Down
Loading