From c676b0b6d3a888315731c0120258a91bc7f9f034 Mon Sep 17 00:00:00 2001 From: Prajjwal Nijhara Date: Fri, 17 Apr 2020 03:01:17 +0530 Subject: [PATCH] Fix some code quality and bug-risk issues --- .deepsource.toml | 12 ++++++++++++ pythonforandroid/archs.py | 4 +--- pythonforandroid/bootstrap.py | 6 +++--- pythonforandroid/build.py | 14 +++++++++----- pythonforandroid/recipes/matplotlib/__init__.py | 2 +- setup.py | 2 +- 6 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000000..e30c701da6 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,12 @@ +version = 1 + +test_patterns = ["tests/**"] + +exclude_patterns = ["testapps/**"] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" \ No newline at end of file diff --git a/pythonforandroid/archs.py b/pythonforandroid/archs.py index f1c8e1121b..925ac21bac 100644 --- a/pythonforandroid/archs.py +++ b/pythonforandroid/archs.py @@ -143,12 +143,10 @@ def get_env(self, with_flags_in_cc=True): env['LDFLAGS'] = ( ' ' + " ".join( - [ - "-L'" + "-L'" + l.replace("'", "'\"'\"'") + "'" # no shlex.quote in py2 for l in self.extra_global_link_paths - ] ) + ' ' + ' '.join(self.common_ldflags).format( ctx_libs_dir=self.ctx.get_libs_dir(self.arch) diff --git a/pythonforandroid/bootstrap.py b/pythonforandroid/bootstrap.py index 75b82e555f..1a089ccd91 100755 --- a/pythonforandroid/bootstrap.py +++ b/pythonforandroid/bootstrap.py @@ -195,7 +195,7 @@ def get_usable_bootstraps_for_recipes(cls, recipes, ctx): # Check if the bootstap's dependencies have an internal conflict: for recipe in possible_dependencies: recipe = Recipe.get_recipe(recipe, ctx) - if any([conflict in recipes for conflict in recipe.conflicts]): + if any(conflict in recipes for conflict in recipe.conflicts): ok = False break # Check if bootstrap's dependencies conflict with chosen @@ -207,8 +207,8 @@ def get_usable_bootstraps_for_recipes(cls, recipes, ctx): conflicts = [] else: conflicts = recipe.conflicts - if any([conflict in possible_dependencies - for conflict in conflicts]): + if any(conflict in possible_dependencies + for conflict in conflicts): ok = False break if ok and bs not in acceptable_bootstraps: diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index 3d4428573a..feb9296c7c 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -267,7 +267,7 @@ def prepare_build_environment(self, d.endswith(('.bz2', '.gz'))] if possible_dirs: info('Found possible SDK dirs in buildozer dir: {}'.format( - ', '.join([d.split(os.sep)[-1] for d in possible_dirs]))) + ', '.join(d.split(os.sep)[-1] for d in possible_dirs))) info('Will attempt to use SDK at {}'.format(possible_dirs[0])) warning('This SDK lookup is intended for debug only, if you ' 'use python-for-android much you should probably ' @@ -328,7 +328,7 @@ def prepare_build_environment(self, '~', '.buildozer', 'android', 'platform', 'android-ndk-r*'))) if possible_dirs: info('Found possible NDK dirs in buildozer dir: {}'.format( - ', '.join([d.split(os.sep)[-1] for d in possible_dirs]))) + ', '.join(d.split(os.sep)[-1] for d in possible_dirs))) info('Will attempt to use NDK at {}'.format(possible_dirs[0])) warning('This NDK lookup is intended for debug only, if you ' 'use python-for-android much you should probably ' @@ -479,7 +479,7 @@ def set_archs(self, arch_names): if not self.archs: raise BuildInterruptingException('Asked to compile for no Archs, so failing.') info('Will compile for the following archs: {}'.format( - ', '.join([arch.arch for arch in self.archs]))) + ', '.join(arch.arch for arch in self.archs))) def prepare_bootstrap(self, bs): bs.ctx = self @@ -894,7 +894,9 @@ def biglink(ctx, arch): env=env) -def biglink_function(soname, objs_paths, extra_link_dirs=[], env=None): +def biglink_function(soname, objs_paths, extra_link_dirs=None, env=None): + if extra_link_dirs is None: + extra_link_dirs = [] print('objs_paths are', objs_paths) sofiles = [] @@ -941,7 +943,9 @@ def biglink_function(soname, objs_paths, extra_link_dirs=[], env=None): shprint(cc, '-shared', '-O3', '-o', soname, *unique_args, _env=env) -def copylibs_function(soname, objs_paths, extra_link_dirs=[], env=None): +def copylibs_function(soname, objs_paths, extra_link_dirs=None, env=None): + if extra_link_dirs is None: + extra_link_dirs = [] print('objs_paths are', objs_paths) re_needso = re.compile(r'^.*\(NEEDED\)\s+Shared library: \[lib(.*)\.so\]\s*$') diff --git a/pythonforandroid/recipes/matplotlib/__init__.py b/pythonforandroid/recipes/matplotlib/__init__.py index 277dada75f..b48a24c6de 100644 --- a/pythonforandroid/recipes/matplotlib/__init__.py +++ b/pythonforandroid/recipes/matplotlib/__init__.py @@ -85,7 +85,7 @@ def download_web_backend_dependencies(self, arch): jquery_sha = ( 'f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d' ) - url = f'https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip' + url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip" target_file = join(env['XDG_CACHE_HOME'], 'matplotlib', jquery_sha) info_notify(f'Will download into {env["XDG_CACHE_HOME"]}') diff --git a/setup.py b/setup.py index cb95b08ccc..853794ae51 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ def recursively_include(results, directory, patterns): for root, subfolders, files in walk(directory): for fn in files: - if not any([glob.fnmatch.fnmatch(fn, pattern) for pattern in patterns]): + if not any(glob.fnmatch.fnmatch(fn, pattern) for pattern in patterns): continue filename = join(root, fn) directory = 'pythonforandroid'