From d2944ad54c40cb236616bf46dd22e1066c8900a4 Mon Sep 17 00:00:00 2001 From: Ankit Dobhal Date: Thu, 4 Mar 2021 09:34:12 -0500 Subject: [PATCH] Fixed code quality issues using deepsource (#1300) - Added .deepsource.toml to fix bug risks - Remove unnecessary use of comprehension - Use `os.environ.copy()` to copy the environment variables - Remove unnecessary return statement - Use `sys.exit()` calls --- .deepsource.toml | 25 +++++++++++++++++++++++++ buildozer/__init__.py | 7 +++---- buildozer/targets/android.py | 4 ++-- buildozer/targets/osx.py | 12 +++++------- 4 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000..29a28f5 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,25 @@ +version = 1 + +test_patterns = ["tests/**"] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" + + +[[analyzers]] +name = "docker" +enabled = true + + [analyzers.meta] + dockerfile_paths = [ + "dockerfile_dev", + "dockerfile_prod" + ] + +[[analyzers]] +name = "ruby" +enabled = true diff --git a/buildozer/__init__.py b/buildozer/__init__.py index 070b010..84c1ec7 100644 --- a/buildozer/__init__.py +++ b/buildozer/__init__.py @@ -253,7 +253,7 @@ class Buildozer: def cmd(self, command, **kwargs): # prepare the environ, based on the system + our own env - env = copy(environ) + env = environ.copy() env.update(self.environ) # prepare the process @@ -360,7 +360,7 @@ class Buildozer: from pexpect import spawnu # prepare the environ, based on the system + our own env - env = copy(environ) + env = environ.copy() env.update(self.environ) # prepare the process @@ -935,8 +935,7 @@ class Buildozer: if not meth.__doc__: continue - doc = [x for x in - meth.__doc__.strip().splitlines()][0].strip() + doc = list(meth.__doc__.strip().splitlines())[0].strip() print(' {0:<18} {1}'.format(name, doc)) print('') diff --git a/buildozer/targets/android.py b/buildozer/targets/android.py index fbe4ec0..80d665c 100644 --- a/buildozer/targets/android.py +++ b/buildozer/targets/android.py @@ -759,7 +759,7 @@ class TargetAndroid(Target): except IOError: self.buildozer.error('Failed to read python-for-android setup.py at {}'.format( join(self.p4a_dir, 'setup.py'))) - exit(1) + sys.exit(1) pip_deps = [] for dep in deps: pip_deps.append("'{}'".format(dep)) @@ -1287,7 +1287,7 @@ class TargetAndroid(Target): self.buildozer.error( 'Invalid library reference (path not found): {}'.format( cref)) - exit(1) + sys.exit(1) # get a relative path from the project file ref = relpath(ref, realpath(expanduser(dist_dir))) # ensure the reference exists diff --git a/buildozer/targets/osx.py b/buildozer/targets/osx.py index c6313ba..fa4444a 100644 --- a/buildozer/targets/osx.py +++ b/buildozer/targets/osx.py @@ -55,7 +55,7 @@ class TargetOSX(Target): "Unable to download the Kivy App. Check osx.kivy_version in your buildozer.spec, and verify " "Kivy servers are accessible. http://kivy.org/downloads/") check_call(("rm", "Kivy{}.dmg".format(py_branch)), cwd=cwd) - exit(1) + sys.exit(1) self.buildozer.info('Extracting and installing Kivy...') check_call(('hdiutil', 'attach', cwd + '/Kivy{}.dmg'.format(py_branch))) @@ -76,8 +76,6 @@ class TargetOSX(Target): else: self.download_kivy(kivy_app_dir, py_branch) - return - def check_requirements(self): self.ensure_sdk() self.ensure_kivyapp() @@ -90,7 +88,7 @@ class TargetOSX(Target): len(errors))) for error in errors: print(error) - exit(1) + sys.exit(1) # check def build_package(self): @@ -177,7 +175,7 @@ class TargetOSX(Target): if not args: self.buildozer.error('Missing target command') self.buildozer.usage() - exit(1) + sys.exit(1) result = [] last_command = [] @@ -191,7 +189,7 @@ class TargetOSX(Target): if not last_command: self.buildozer.error('Argument passed without a command') self.buildozer.usage() - exit(1) + sys.exit(1) last_command.append(arg) if last_command: result.append(last_command) @@ -202,7 +200,7 @@ class TargetOSX(Target): command, args = item[0], item[1:] if not hasattr(self, 'cmd_{0}'.format(command)): self.buildozer.error('Unknown command {0}'.format(command)) - exit(1) + sys.exit(1) func = getattr(self, 'cmd_{0}'.format(command))