Skip to content

🚨 Depreciation warning fixes #2227

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

Merged
merged 1 commit into from
Jun 5, 2020
Merged
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
18 changes: 3 additions & 15 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sh
import shutil
import fnmatch
from urllib.request import urlretrieve
from os import listdir, unlink, environ, mkdir, curdir, walk
from sys import stdout
import time
Expand All @@ -17,22 +18,9 @@
except ImportError:
from urllib.parse import urlparse
from pythonforandroid.logger import (logger, info, warning, debug, shprint, info_main)
from pythonforandroid.util import (urlretrieve, current_directory, ensure_dir,
from pythonforandroid.util import (current_directory, ensure_dir,
BuildInterruptingException)


def import_recipe(module, filename):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to pythonforandroid/util.py and renamed to load_source

# Python 3.5+
import importlib.util
if hasattr(importlib.util, 'module_from_spec'):
spec = importlib.util.spec_from_file_location(module, filename)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
else:
# Python 3.3 and 3.4:
from importlib.machinery import SourceFileLoader
return SourceFileLoader(module, filename).load_module()
from pythonforandroid.util import load_source as import_recipe


class RecipeMeta(type):
Expand Down
9 changes: 4 additions & 5 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pythonforandroid.pythonpackage import get_dep_names_of_package
from pythonforandroid.recommendations import (
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API, print_recommendations)
from pythonforandroid.util import BuildInterruptingException
from pythonforandroid.util import BuildInterruptingException, load_source
from pythonforandroid.entrypoints import main


Expand Down Expand Up @@ -81,7 +81,6 @@ def check_python_dependencies():

import argparse
import sh
import imp
from appdirs import user_data_dir
import logging
from distutils.version import LooseVersion
Expand Down Expand Up @@ -752,8 +751,8 @@ def hook(self, name):
return
if not hasattr(self, "hook_module"):
# first time, try to load the hook module
self.hook_module = imp.load_source("pythonforandroid.hook",
self.args.hook)
self.hook_module = load_source(
"pythonforandroid.hook", self.args.hook)
if hasattr(self.hook_module, name):
info("Hook: execute {}".format(name))
getattr(self.hook_module, name)(self)
Expand Down Expand Up @@ -1025,7 +1024,7 @@ def _build_package(self, args, package_type):
with current_directory(dist.dist_dir):
self.hook("before_apk_build")
os.environ["ANDROID_API"] = str(self.ctx.android_api)
build = imp.load_source('build', join(dist.dist_dir, 'build.py'))
build = load_source('build', join(dist.dist_dir, 'build.py'))
build_args = build.parse_args_and_make_package(
args.unknown_args
)
Expand Down
24 changes: 14 additions & 10 deletions pythonforandroid/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@
import shutil
from fnmatch import fnmatch
from tempfile import mkdtemp

from urllib.request import FancyURLopener

from pythonforandroid.logger import (logger, Err_Fore, error, info)


class WgetDownloader(FancyURLopener):
version = ('Wget/1.17.1')


urlretrieve = WgetDownloader().retrieve
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully replaced by simply from urllib.request import urlretrieve



build_platform = '{system}-{machine}'.format(
system=uname()[0], machine=uname()[-1]).lower()
"""the build platform in the format `system-machine`. We use
Expand Down Expand Up @@ -84,6 +74,20 @@ def walk_valid_filens(base_dir, invalid_dir_names, invalid_file_patterns):
yield join(dirn, filen)


def load_source(module, filename):
# Python 3.5+
import importlib.util
if hasattr(importlib.util, 'module_from_spec'):
spec = importlib.util.spec_from_file_location(module, filename)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
else:
# Python 3.3 and 3.4:
from importlib.machinery import SourceFileLoader
return SourceFileLoader(module, filename).load_module()
Comment on lines +85 to +88
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was tempted to completely ditch the Python 3.3/3.4 part, but didn't want to risk it in this one. Let's keep it for later



class BuildInterruptingException(Exception):
def __init__(self, message, instructions=None):
super().__init__(message, instructions)
Expand Down