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
This commit is contained in:
parent
b24b77b36e
commit
d2944ad54c
4 changed files with 35 additions and 13 deletions
25
.deepsource.toml
Normal file
25
.deepsource.toml
Normal file
|
@ -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
|
|
@ -253,7 +253,7 @@ class Buildozer:
|
||||||
|
|
||||||
def cmd(self, command, **kwargs):
|
def cmd(self, command, **kwargs):
|
||||||
# prepare the environ, based on the system + our own env
|
# prepare the environ, based on the system + our own env
|
||||||
env = copy(environ)
|
env = environ.copy()
|
||||||
env.update(self.environ)
|
env.update(self.environ)
|
||||||
|
|
||||||
# prepare the process
|
# prepare the process
|
||||||
|
@ -360,7 +360,7 @@ class Buildozer:
|
||||||
from pexpect import spawnu
|
from pexpect import spawnu
|
||||||
|
|
||||||
# prepare the environ, based on the system + our own env
|
# prepare the environ, based on the system + our own env
|
||||||
env = copy(environ)
|
env = environ.copy()
|
||||||
env.update(self.environ)
|
env.update(self.environ)
|
||||||
|
|
||||||
# prepare the process
|
# prepare the process
|
||||||
|
@ -935,8 +935,7 @@ class Buildozer:
|
||||||
|
|
||||||
if not meth.__doc__:
|
if not meth.__doc__:
|
||||||
continue
|
continue
|
||||||
doc = [x for x in
|
doc = list(meth.__doc__.strip().splitlines())[0].strip()
|
||||||
meth.__doc__.strip().splitlines()][0].strip()
|
|
||||||
print(' {0:<18} {1}'.format(name, doc))
|
print(' {0:<18} {1}'.format(name, doc))
|
||||||
|
|
||||||
print('')
|
print('')
|
||||||
|
|
|
@ -759,7 +759,7 @@ class TargetAndroid(Target):
|
||||||
except IOError:
|
except IOError:
|
||||||
self.buildozer.error('Failed to read python-for-android setup.py at {}'.format(
|
self.buildozer.error('Failed to read python-for-android setup.py at {}'.format(
|
||||||
join(self.p4a_dir, 'setup.py')))
|
join(self.p4a_dir, 'setup.py')))
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
pip_deps = []
|
pip_deps = []
|
||||||
for dep in deps:
|
for dep in deps:
|
||||||
pip_deps.append("'{}'".format(dep))
|
pip_deps.append("'{}'".format(dep))
|
||||||
|
@ -1287,7 +1287,7 @@ class TargetAndroid(Target):
|
||||||
self.buildozer.error(
|
self.buildozer.error(
|
||||||
'Invalid library reference (path not found): {}'.format(
|
'Invalid library reference (path not found): {}'.format(
|
||||||
cref))
|
cref))
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
# get a relative path from the project file
|
# get a relative path from the project file
|
||||||
ref = relpath(ref, realpath(expanduser(dist_dir)))
|
ref = relpath(ref, realpath(expanduser(dist_dir)))
|
||||||
# ensure the reference exists
|
# ensure the reference exists
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TargetOSX(Target):
|
||||||
"Unable to download the Kivy App. Check osx.kivy_version in your buildozer.spec, and verify "
|
"Unable to download the Kivy App. Check osx.kivy_version in your buildozer.spec, and verify "
|
||||||
"Kivy servers are accessible. http://kivy.org/downloads/")
|
"Kivy servers are accessible. http://kivy.org/downloads/")
|
||||||
check_call(("rm", "Kivy{}.dmg".format(py_branch)), cwd=cwd)
|
check_call(("rm", "Kivy{}.dmg".format(py_branch)), cwd=cwd)
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
self.buildozer.info('Extracting and installing Kivy...')
|
self.buildozer.info('Extracting and installing Kivy...')
|
||||||
check_call(('hdiutil', 'attach', cwd + '/Kivy{}.dmg'.format(py_branch)))
|
check_call(('hdiutil', 'attach', cwd + '/Kivy{}.dmg'.format(py_branch)))
|
||||||
|
@ -76,8 +76,6 @@ class TargetOSX(Target):
|
||||||
else:
|
else:
|
||||||
self.download_kivy(kivy_app_dir, py_branch)
|
self.download_kivy(kivy_app_dir, py_branch)
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def check_requirements(self):
|
def check_requirements(self):
|
||||||
self.ensure_sdk()
|
self.ensure_sdk()
|
||||||
self.ensure_kivyapp()
|
self.ensure_kivyapp()
|
||||||
|
@ -90,7 +88,7 @@ class TargetOSX(Target):
|
||||||
len(errors)))
|
len(errors)))
|
||||||
for error in errors:
|
for error in errors:
|
||||||
print(error)
|
print(error)
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
# check
|
# check
|
||||||
|
|
||||||
def build_package(self):
|
def build_package(self):
|
||||||
|
@ -177,7 +175,7 @@ class TargetOSX(Target):
|
||||||
if not args:
|
if not args:
|
||||||
self.buildozer.error('Missing target command')
|
self.buildozer.error('Missing target command')
|
||||||
self.buildozer.usage()
|
self.buildozer.usage()
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
last_command = []
|
last_command = []
|
||||||
|
@ -191,7 +189,7 @@ class TargetOSX(Target):
|
||||||
if not last_command:
|
if not last_command:
|
||||||
self.buildozer.error('Argument passed without a command')
|
self.buildozer.error('Argument passed without a command')
|
||||||
self.buildozer.usage()
|
self.buildozer.usage()
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
last_command.append(arg)
|
last_command.append(arg)
|
||||||
if last_command:
|
if last_command:
|
||||||
result.append(last_command)
|
result.append(last_command)
|
||||||
|
@ -202,7 +200,7 @@ class TargetOSX(Target):
|
||||||
command, args = item[0], item[1:]
|
command, args = item[0], item[1:]
|
||||||
if not hasattr(self, 'cmd_{0}'.format(command)):
|
if not hasattr(self, 'cmd_{0}'.format(command)):
|
||||||
self.buildozer.error('Unknown command {0}'.format(command))
|
self.buildozer.error('Unknown command {0}'.format(command))
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
func = getattr(self, 'cmd_{0}'.format(command))
|
func = getattr(self, 'cmd_{0}'.format(command))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue