Skip to content

Commit 08713b3

Browse files
authored
Merge pull request #3054 from AndreMiras/feature/minor_refactoring
♻️ Minor code cleaning
2 parents 851891d + 74b891e commit 08713b3

File tree

4 files changed

+15
-31
lines changed

4 files changed

+15
-31
lines changed

pythonforandroid/build.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ def run_pymodules_install(ctx, arch, modules, project_dir=None,
672672
# Bail out if no python deps and no setup.py to process:
673673
if not modules and (
674674
ignore_setup_py or
675-
project_dir is None or
676675
not project_has_setup_py(project_dir)
677676
):
678677
info('No Python modules and no setup.py to process, skipping')
@@ -688,8 +687,7 @@ def run_pymodules_install(ctx, arch, modules, project_dir=None,
688687
"If this fails, it may mean that the module has compiled "
689688
"components and needs a recipe."
690689
)
691-
if project_dir is not None and \
692-
project_has_setup_py(project_dir) and not ignore_setup_py:
690+
if project_has_setup_py(project_dir) and not ignore_setup_py:
693691
info(
694692
"Will process project install, if it fails then the "
695693
"project may not be compatible for Android install."
@@ -761,9 +759,7 @@ def run_pymodules_install(ctx, arch, modules, project_dir=None,
761759
_env=copy.copy(env))
762760

763761
# Afterwards, run setup.py if present:
764-
if project_dir is not None and (
765-
project_has_setup_py(project_dir) and not ignore_setup_py
766-
):
762+
if project_has_setup_py(project_dir) and not ignore_setup_py:
767763
run_setuppy_install(ctx, project_dir, env, arch)
768764
elif not ignore_setup_py:
769765
info("No setup.py found in project directory: " + str(project_dir))

pythonforandroid/pythonpackage.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,10 @@ def _extract_info_from_package(dependency,
556556

557557
# Get build requirements from pyproject.toml if requested:
558558
requirements = []
559-
if os.path.exists(os.path.join(output_folder,
560-
'pyproject.toml')
561-
) and include_build_requirements:
559+
pyproject_toml_path = os.path.join(output_folder, 'pyproject.toml')
560+
if os.path.exists(pyproject_toml_path) and include_build_requirements:
562561
# Read build system from pyproject.toml file: (PEP518)
563-
with open(os.path.join(output_folder, 'pyproject.toml')) as f:
562+
with open(pyproject_toml_path) as f:
564563
build_sys = toml.load(f)['build-system']
565564
if "requires" in build_sys:
566565
requirements += build_sys["requires"]

pythonforandroid/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
11691169

11701170

11711171
class PyProjectRecipe(PythonRecipe):
1172-
'''Recipe for projects which containes `pyproject.toml`'''
1172+
"""Recipe for projects which contain `pyproject.toml`"""
11731173

11741174
# Extra args to pass to `python -m build ...`
11751175
extra_build_args = []

pythonforandroid/toolchain.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from pythonforandroid import __version__
3131
from pythonforandroid.bootstrap import Bootstrap
32-
from pythonforandroid.build import Context, build_recipes
32+
from pythonforandroid.build import Context, build_recipes, project_has_setup_py
3333
from pythonforandroid.distribution import Distribution, pretty_log_dists
3434
from pythonforandroid.entrypoints import main
3535
from pythonforandroid.graph import get_recipe_order_and_bootstrap
@@ -569,18 +569,18 @@ def add_parser(subparsers, *args, **kwargs):
569569
args, unknown = parser.parse_known_args(sys.argv[1:])
570570
args.unknown_args = unknown
571571

572-
if hasattr(args, "private") and args.private is not None:
572+
if getattr(args, "private", None) is not None:
573573
# Pass this value on to the internal bootstrap build.py:
574574
args.unknown_args += ["--private", args.private]
575-
if hasattr(args, "build_mode") and args.build_mode == "release":
575+
if getattr(args, "build_mode", None) == "release":
576576
args.unknown_args += ["--release"]
577-
if hasattr(args, "with_debug_symbols") and args.with_debug_symbols:
577+
if getattr(args, "with_debug_symbols", False):
578578
args.unknown_args += ["--with-debug-symbols"]
579-
if hasattr(args, "ignore_setup_py") and args.ignore_setup_py:
579+
if getattr(args, "ignore_setup_py", False):
580580
args.use_setup_py = False
581-
if hasattr(args, "activity_class_name") and args.activity_class_name != 'org.kivy.android.PythonActivity':
581+
if getattr(args, "activity_class_name", "org.kivy.android.PythonActivity") != 'org.kivy.android.PythonActivity':
582582
args.unknown_args += ["--activity-class-name", args.activity_class_name]
583-
if hasattr(args, "service_class_name") and args.service_class_name != 'org.kivy.android.PythonService':
583+
if getattr(args, "service_class_name", "org.kivy.android.PythonService") != 'org.kivy.android.PythonService':
584584
args.unknown_args += ["--service-class-name", args.service_class_name]
585585

586586
self.args = args
@@ -603,21 +603,13 @@ def add_parser(subparsers, *args, **kwargs):
603603
args, "with_debug_symbols", False
604604
)
605605

606-
have_setup_py_or_similar = False
607-
if getattr(args, "private", None) is not None:
608-
project_dir = getattr(args, "private")
609-
if (os.path.exists(os.path.join(project_dir, "setup.py")) or
610-
os.path.exists(os.path.join(project_dir,
611-
"pyproject.toml"))):
612-
have_setup_py_or_similar = True
613-
614606
# Process requirements and put version in environ
615607
if hasattr(args, 'requirements'):
616608
requirements = []
617609

618610
# Add dependencies from setup.py, but only if they are recipes
619611
# (because otherwise, setup.py itself will install them later)
620-
if (have_setup_py_or_similar and
612+
if (project_has_setup_py(getattr(args, "private", None)) and
621613
getattr(args, "use_setup_py", False)):
622614
try:
623615
info("Analyzing package dependencies. MAY TAKE A WHILE.")
@@ -698,10 +690,7 @@ def warn_on_deprecated_args(self, args):
698690

699691
# Output warning if setup.py is present and neither --ignore-setup-py
700692
# nor --use-setup-py was specified.
701-
if getattr(args, "private", None) is not None and \
702-
(os.path.exists(os.path.join(args.private, "setup.py")) or
703-
os.path.exists(os.path.join(args.private, "pyproject.toml"))
704-
):
693+
if project_has_setup_py(getattr(args, "private", None)):
705694
if not getattr(args, "use_setup_py", False) and \
706695
not getattr(args, "ignore_setup_py", False):
707696
warning(" **** FUTURE BEHAVIOR CHANGE WARNING ****")

0 commit comments

Comments
 (0)