Skip to content

Commit c6f76b9

Browse files
authored
Standardise ensure_dir and rmdir (#2871)
* Standardise ensure_dir and rmdir * Standardise ensure_dir and rmdir * Add libmysqlclient to broken list * Libtorrent failing to be rebuilt * Add boost to broken recipes list
1 parent fa3e5bf commit c6f76b9

29 files changed

+176
-162
lines changed

ci/constants.py

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class TargetPython(Enum):
3333
'twisted',
3434
# genericndkbuild is incompatible with sdl2 (which is build by default when targeting sdl2 bootstrap)
3535
'genericndkbuild',
36+
# libmysqlclient gives a linker failure (See issue #2808)
37+
'libmysqlclient',
38+
# boost gives errors (requires numpy? syntax error in .jam?)
39+
'boost',
40+
# libtorrent gives errors (requires boost. Also, see issue #2809, to start with)
41+
'libtorrent',
42+
3643
])
3744

3845
BROKEN_RECIPES = {

pythonforandroid/bdistapk.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from glob import glob
2+
from os.path import realpath, join, dirname, curdir, basename, split
13
from setuptools import Command
2-
4+
from shutil import copyfile
35
import sys
4-
from os.path import realpath, join, exists, dirname, curdir, basename, split
5-
from os import makedirs
6-
from glob import glob
7-
from shutil import rmtree, copyfile
6+
7+
from pythonforandroid.util import rmdir, ensure_dir
88

99

1010
def argv_contains(t):
@@ -90,9 +90,8 @@ def prepare_build_dir(self):
9090
'that.')
9191

9292
bdist_dir = 'build/bdist.android-{}'.format(self.arch)
93-
if exists(bdist_dir):
94-
rmtree(bdist_dir)
95-
makedirs(bdist_dir)
93+
rmdir(bdist_dir)
94+
ensure_dir(bdist_dir)
9695

9796
globs = []
9897
for directory, patterns in self.distribution.package_data.items():
@@ -107,8 +106,7 @@ def prepare_build_dir(self):
107106
if not argv_contains('--launcher'):
108107
for filen in filens:
109108
new_dir = join(bdist_dir, dirname(filen))
110-
if not exists(new_dir):
111-
makedirs(new_dir)
109+
ensure_dir(new_dir)
112110
print('Including {}'.format(filen))
113111
copyfile(filen, join(bdist_dir, filen))
114112
if basename(filen) in ('main.py', 'main.pyc'):

pythonforandroid/bootstrap.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
from pythonforandroid.logger import (shprint, info, logger, debug)
1212
from pythonforandroid.util import (
13-
current_directory, ensure_dir, temp_directory, BuildInterruptingException)
13+
current_directory, ensure_dir, temp_directory, BuildInterruptingException,
14+
rmdir)
1415
from pythonforandroid.recipe import Recipe
1516

1617

@@ -396,7 +397,7 @@ def fry_eggs(self, sitepackages):
396397
files = [join(rd, f) for f in listdir(rd) if f != 'EGG-INFO']
397398
if files:
398399
shprint(sh.mv, '-t', sitepackages, *files)
399-
shprint(sh.rm, '-rf', d)
400+
rmdir(d)
400401

401402

402403
def expand_dependencies(recipes, ctx):

pythonforandroid/bootstraps/common/build/build.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from fnmatch import fnmatch
2222
import jinja2
2323

24+
from pythonforandroid.util import rmdir, ensure_dir
25+
2426

2527
def get_dist_info_for(key, error_if_missing=True):
2628
try:
@@ -93,11 +95,6 @@ def get_bootstrap_name():
9395
DEFAULT_PYTHON_SERVICE_JAVA_CLASS = 'org.kivy.android.PythonService'
9496

9597

96-
def ensure_dir(path):
97-
if not exists(path):
98-
makedirs(path)
99-
100-
10198
def render(template, dest, **kwargs):
10299
'''Using jinja2, render `template` to the filename `dest`, supplying the
103100
@@ -241,7 +238,7 @@ def make_package(args):
241238
assets_dir = "src/main/assets"
242239

243240
# Delete the old assets.
244-
shutil.rmtree(assets_dir, ignore_errors=True)
241+
rmdir(assets_dir, ignore_errors=True)
245242
ensure_dir(assets_dir)
246243

247244
# Add extra environment variable file into tar-able directory:
@@ -290,7 +287,7 @@ def make_package(args):
290287
not exists(
291288
join(main_py_only_dir, dir_path)
292289
)):
293-
os.mkdir(join(main_py_only_dir, dir_path))
290+
ensure_dir(join(main_py_only_dir, dir_path))
294291
# Copy actual file:
295292
shutil.copyfile(
296293
join(args.private, variant),
@@ -328,17 +325,17 @@ def make_package(args):
328325
)
329326
finally:
330327
for directory in _temp_dirs_to_clean:
331-
shutil.rmtree(directory)
328+
rmdir(directory)
332329

333330
# Remove extra env vars tar-able directory:
334-
shutil.rmtree(env_vars_tarpath)
331+
rmdir(env_vars_tarpath)
335332

336333
# Prepare some variables for templating process
337334
res_dir = "src/main/res"
338335
res_dir_initial = "src/res_initial"
339336
# make res_dir stateless
340337
if exists(res_dir_initial):
341-
shutil.rmtree(res_dir, ignore_errors=True)
338+
rmdir(res_dir, ignore_errors=True)
342339
shutil.copytree(res_dir_initial, res_dir)
343340
else:
344341
shutil.copytree(res_dir, res_dir_initial)

pythonforandroid/bootstraps/sdl2/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from pythonforandroid.toolchain import (
2-
Bootstrap, shprint, current_directory, info, info_main)
3-
from pythonforandroid.util import ensure_dir
41
from os.path import join
2+
53
import sh
64

5+
from pythonforandroid.toolchain import (
6+
Bootstrap, shprint, current_directory, info, info_main)
7+
from pythonforandroid.util import ensure_dir, rmdir
8+
79

810
class SDL2GradleBootstrap(Bootstrap):
911
name = 'sdl2'
@@ -15,8 +17,8 @@ class SDL2GradleBootstrap(Bootstrap):
1517
def assemble_distribution(self):
1618
info_main("# Creating Android project ({})".format(self.name))
1719

20+
rmdir(self.dist_dir)
1821
info("Copying SDL2/gradle build")
19-
shprint(sh.rm, "-rf", self.dist_dir)
2022
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
2123

2224
# either the build use environment variable (ANDROID_HOME)

pythonforandroid/bootstraps/service_only/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from os.path import join
33
from pythonforandroid.toolchain import (
44
Bootstrap, current_directory, info, info_main, shprint)
5-
from pythonforandroid.util import ensure_dir
5+
from pythonforandroid.util import ensure_dir, rmdir
66

77

88
class ServiceOnlyBootstrap(Bootstrap):
@@ -18,7 +18,7 @@ def assemble_distribution(self):
1818
self.name))
1919

2020
info('This currently just copies the build stuff straight from the build dir.')
21-
shprint(sh.rm, '-rf', self.dist_dir)
21+
rmdir(self.dist_dir)
2222
shprint(sh.cp, '-r', self.build_dir, self.dist_dir)
2323
with current_directory(self.dist_dir):
2424
with open('local.properties', 'w') as fileh:

pythonforandroid/bootstraps/webview/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from pythonforandroid.toolchain import Bootstrap, current_directory, info, info_main, shprint
2-
from pythonforandroid.util import ensure_dir
31
from os.path import join
2+
43
import sh
54

5+
from pythonforandroid.toolchain import Bootstrap, current_directory, info, info_main, shprint
6+
from pythonforandroid.util import ensure_dir, rmdir
7+
68

79
class WebViewBootstrap(Bootstrap):
810
name = 'webview'
@@ -15,7 +17,7 @@ def assemble_distribution(self):
1517
info_main('# Creating Android project from build and {} bootstrap'.format(
1618
self.name))
1719

18-
shprint(sh.rm, '-rf', self.dist_dir)
20+
rmdir(self.dist_dir)
1921
shprint(sh.cp, '-r', self.build_dir, self.dist_dir)
2022
with current_directory(self.dist_dir):
2123
with open('local.properties', 'w') as fileh:

pythonforandroid/build.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
from contextlib import suppress
2+
import copy
3+
import glob
4+
import os
5+
from os import environ
16
from os.path import (
27
abspath, join, realpath, dirname, expanduser, exists
38
)
4-
from os import environ
5-
import copy
6-
import os
7-
import glob
89
import re
9-
import sh
1010
import shutil
1111
import subprocess
12-
from contextlib import suppress
1312

14-
from pythonforandroid.util import (
15-
current_directory, ensure_dir,
16-
BuildInterruptingException,
17-
)
18-
from pythonforandroid.logger import (info, warning, info_notify, info_main, shprint)
13+
import sh
14+
15+
from pythonforandroid.androidndk import AndroidNDK
1916
from pythonforandroid.archs import ArchARM, ArchARMv7_a, ArchAarch_64, Archx86, Archx86_64
17+
from pythonforandroid.logger import (info, warning, info_notify, info_main, shprint)
2018
from pythonforandroid.pythonpackage import get_package_name
2119
from pythonforandroid.recipe import CythonRecipe, Recipe
2220
from pythonforandroid.recommendations import (
2321
check_ndk_version, check_target_api, check_ndk_api,
2422
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API)
25-
from pythonforandroid.androidndk import AndroidNDK
23+
from pythonforandroid.util import (
24+
current_directory, ensure_dir,
25+
BuildInterruptingException, rmdir
26+
)
2627

2728

2829
def get_targets(sdk_dir):
@@ -641,7 +642,7 @@ def run_setuppy_install(ctx, project_dir, env=None, arch=None):
641642
for f in set(copied_over_contents + new_venv_additions):
642643
full_path = os.path.join(venv_site_packages_dir, f)
643644
if os.path.isdir(full_path):
644-
shutil.rmtree(full_path)
645+
rmdir(full_path)
645646
else:
646647
os.remove(full_path)
647648
finally:

pythonforandroid/distribution.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from os.path import exists, join
2-
import glob
31
import json
2+
import glob
3+
from os.path import exists, join
44

5-
from pythonforandroid.logger import (debug, info, info_notify, warning, Err_Style, Err_Fore)
6-
from pythonforandroid.util import current_directory, BuildInterruptingException
7-
from shutil import rmtree
5+
from pythonforandroid.logger import (
6+
debug, info, info_notify, warning, Err_Style, Err_Fore)
7+
from pythonforandroid.util import (
8+
current_directory, BuildInterruptingException, rmdir)
89

910

1011
class Distribution:
@@ -201,7 +202,7 @@ def folder_exists(self):
201202
return exists(self.dist_dir)
202203

203204
def delete(self):
204-
rmtree(self.dist_dir)
205+
rmdir(self.dist_dir)
205206

206207
@classmethod
207208
def get_distributions(cls, ctx, extra_dist_dirs=[]):

pythonforandroid/prerequisites.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env python3
22

3-
import sys
4-
import platform
53
import os
6-
import subprocess
4+
import platform
75
import shutil
6+
import subprocess
7+
import sys
8+
89
from pythonforandroid.logger import info, warning, error
10+
from pythonforandroid.util import ensure_dir
911

1012

1113
class Prerequisite(object):
@@ -247,13 +249,7 @@ def darwin_installer(self):
247249
"~/Library/Java/JavaVirtualMachines"
248250
)
249251
info(f"Extracting {filename} to {user_library_java_path}")
250-
subprocess.check_output(
251-
[
252-
"mkdir",
253-
"-p",
254-
user_library_java_path,
255-
],
256-
)
252+
ensure_dir(user_library_java_path)
257253
subprocess.check_output(
258254
["tar", "xzf", f"/tmp/{filename}", "-C", user_library_java_path],
259255
)

pythonforandroid/pythonpackage.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,23 @@
3434

3535

3636
import functools
37+
from io import open # needed for python 2
3738
import os
3839
import shutil
3940
import subprocess
4041
import sys
4142
import tarfile
4243
import tempfile
4344
import time
44-
import zipfile
45-
from io import open # needed for python 2
4645
from urllib.parse import unquote as urlunquote
4746
from urllib.parse import urlparse
47+
import zipfile
4848

4949
import toml
5050
import build.util
5151

52+
from pythonforandroid.util import rmdir, ensure_dir
53+
5254

5355
def transform_dep_for_pip(dependency):
5456
if dependency.find("@") > 0 and (
@@ -113,7 +115,7 @@ def extract_metainfo_files_from_package(
113115

114116
_extract_metainfo_files_from_package_unsafe(package, output_folder)
115117
finally:
116-
shutil.rmtree(temp_folder)
118+
rmdir(temp_folder)
117119

118120

119121
def _get_system_python_executable():
@@ -314,7 +316,7 @@ def get_package_as_folder(dependency):
314316
)
315317

316318
# Create download subfolder:
317-
os.mkdir(os.path.join(venv_path, "download"))
319+
ensure_dir(os.path.join(venv_path, "download"))
318320

319321
# Write a requirements.txt with our package and download:
320322
with open(os.path.join(venv_path, "requirements.txt"),
@@ -394,11 +396,11 @@ def to_unicode(s): # Needed for Python 2.
394396
# Copy result to new dedicated folder so we can throw away
395397
# our entire virtualenv nonsense after returning:
396398
result_path = tempfile.mkdtemp()
397-
shutil.rmtree(result_path)
399+
rmdir(result_path)
398400
shutil.copytree(result_folder_or_file, result_path)
399401
return (dl_type, result_path)
400402
finally:
401-
shutil.rmtree(venv_parent)
403+
rmdir(venv_parent)
402404

403405

404406
def _extract_metainfo_files_from_package_unsafe(
@@ -458,7 +460,7 @@ def _extract_metainfo_files_from_package_unsafe(
458460
shutil.copyfile(metadata_path, os.path.join(output_path, "METADATA"))
459461
finally:
460462
if clean_up_path:
461-
shutil.rmtree(path)
463+
rmdir(path)
462464

463465

464466
def is_filesystem_path(dep):
@@ -576,7 +578,7 @@ def _extract_info_from_package(dependency,
576578

577579
return list(set(requirements)) # remove duplicates
578580
finally:
579-
shutil.rmtree(output_folder)
581+
rmdir(output_folder)
580582

581583

582584
package_name_cache = dict()

0 commit comments

Comments
 (0)