Skip to content

Commit 9c601cf

Browse files
authored
Merge pull request #2227 from AndreMiras/feature/fix_warnings
🚨 Depreciation warning fixes
2 parents 0c7ee85 + 17f6e1e commit 9c601cf

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

pythonforandroid/recipe.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sh
1010
import shutil
1111
import fnmatch
12+
from urllib.request import urlretrieve
1213
from os import listdir, unlink, environ, mkdir, curdir, walk
1314
from sys import stdout
1415
import time
@@ -17,22 +18,9 @@
1718
except ImportError:
1819
from urllib.parse import urlparse
1920
from pythonforandroid.logger import (logger, info, warning, debug, shprint, info_main)
20-
from pythonforandroid.util import (urlretrieve, current_directory, ensure_dir,
21+
from pythonforandroid.util import (current_directory, ensure_dir,
2122
BuildInterruptingException)
22-
23-
24-
def import_recipe(module, filename):
25-
# Python 3.5+
26-
import importlib.util
27-
if hasattr(importlib.util, 'module_from_spec'):
28-
spec = importlib.util.spec_from_file_location(module, filename)
29-
mod = importlib.util.module_from_spec(spec)
30-
spec.loader.exec_module(mod)
31-
return mod
32-
else:
33-
# Python 3.3 and 3.4:
34-
from importlib.machinery import SourceFileLoader
35-
return SourceFileLoader(module, filename).load_module()
23+
from pythonforandroid.util import load_source as import_recipe
3624

3725

3826
class RecipeMeta(type):

pythonforandroid/toolchain.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pythonforandroid.pythonpackage import get_dep_names_of_package
1212
from pythonforandroid.recommendations import (
1313
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API, print_recommendations)
14-
from pythonforandroid.util import BuildInterruptingException
14+
from pythonforandroid.util import BuildInterruptingException, load_source
1515
from pythonforandroid.entrypoints import main
1616

1717

@@ -81,7 +81,6 @@ def check_python_dependencies():
8181

8282
import argparse
8383
import sh
84-
import imp
8584
from appdirs import user_data_dir
8685
import logging
8786
from distutils.version import LooseVersion
@@ -752,8 +751,8 @@ def hook(self, name):
752751
return
753752
if not hasattr(self, "hook_module"):
754753
# first time, try to load the hook module
755-
self.hook_module = imp.load_source("pythonforandroid.hook",
756-
self.args.hook)
754+
self.hook_module = load_source(
755+
"pythonforandroid.hook", self.args.hook)
757756
if hasattr(self.hook_module, name):
758757
info("Hook: execute {}".format(name))
759758
getattr(self.hook_module, name)(self)
@@ -1025,7 +1024,7 @@ def _build_package(self, args, package_type):
10251024
with current_directory(dist.dist_dir):
10261025
self.hook("before_apk_build")
10271026
os.environ["ANDROID_API"] = str(self.ctx.android_api)
1028-
build = imp.load_source('build', join(dist.dist_dir, 'build.py'))
1027+
build = load_source('build', join(dist.dist_dir, 'build.py'))
10291028
build_args = build.parse_args_and_make_package(
10301029
args.unknown_args
10311030
)

pythonforandroid/util.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@
44
import shutil
55
from fnmatch import fnmatch
66
from tempfile import mkdtemp
7-
8-
from urllib.request import FancyURLopener
9-
107
from pythonforandroid.logger import (logger, Err_Fore, error, info)
118

129

13-
class WgetDownloader(FancyURLopener):
14-
version = ('Wget/1.17.1')
15-
16-
17-
urlretrieve = WgetDownloader().retrieve
18-
19-
2010
build_platform = '{system}-{machine}'.format(
2111
system=uname()[0], machine=uname()[-1]).lower()
2212
"""the build platform in the format `system-machine`. We use
@@ -84,6 +74,20 @@ def walk_valid_filens(base_dir, invalid_dir_names, invalid_file_patterns):
8474
yield join(dirn, filen)
8575

8676

77+
def load_source(module, filename):
78+
# Python 3.5+
79+
import importlib.util
80+
if hasattr(importlib.util, 'module_from_spec'):
81+
spec = importlib.util.spec_from_file_location(module, filename)
82+
mod = importlib.util.module_from_spec(spec)
83+
spec.loader.exec_module(mod)
84+
return mod
85+
else:
86+
# Python 3.3 and 3.4:
87+
from importlib.machinery import SourceFileLoader
88+
return SourceFileLoader(module, filename).load_module()
89+
90+
8791
class BuildInterruptingException(Exception):
8892
def __init__(self, message, instructions=None):
8993
super().__init__(message, instructions)

0 commit comments

Comments
 (0)