diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index 05e4e1db7..98e2d70b2 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -672,7 +672,6 @@ def run_pymodules_install(ctx, arch, modules, project_dir=None, # Bail out if no python deps and no setup.py to process: if not modules and ( ignore_setup_py or - project_dir is None or not project_has_setup_py(project_dir) ): 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, "If this fails, it may mean that the module has compiled " "components and needs a recipe." ) - if project_dir is not None and \ - project_has_setup_py(project_dir) and not ignore_setup_py: + if project_has_setup_py(project_dir) and not ignore_setup_py: info( "Will process project install, if it fails then the " "project may not be compatible for Android install." @@ -761,9 +759,7 @@ def run_pymodules_install(ctx, arch, modules, project_dir=None, _env=copy.copy(env)) # Afterwards, run setup.py if present: - if project_dir is not None and ( - project_has_setup_py(project_dir) and not ignore_setup_py - ): + if project_has_setup_py(project_dir) and not ignore_setup_py: run_setuppy_install(ctx, project_dir, env, arch) elif not ignore_setup_py: info("No setup.py found in project directory: " + str(project_dir)) diff --git a/pythonforandroid/pythonpackage.py b/pythonforandroid/pythonpackage.py index 9e4c29bd8..602235cf2 100644 --- a/pythonforandroid/pythonpackage.py +++ b/pythonforandroid/pythonpackage.py @@ -556,11 +556,10 @@ def _extract_info_from_package(dependency, # Get build requirements from pyproject.toml if requested: requirements = [] - if os.path.exists(os.path.join(output_folder, - 'pyproject.toml') - ) and include_build_requirements: + pyproject_toml_path = os.path.join(output_folder, 'pyproject.toml') + if os.path.exists(pyproject_toml_path) and include_build_requirements: # Read build system from pyproject.toml file: (PEP518) - with open(os.path.join(output_folder, 'pyproject.toml')) as f: + with open(pyproject_toml_path) as f: build_sys = toml.load(f)['build-system'] if "requires" in build_sys: requirements += build_sys["requires"] diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py index ff34ac29f..a52abeb02 100644 --- a/pythonforandroid/recipe.py +++ b/pythonforandroid/recipe.py @@ -1169,7 +1169,7 @@ def get_recipe_env(self, arch, with_flags_in_cc=True): class PyProjectRecipe(PythonRecipe): - '''Recipe for projects which containes `pyproject.toml`''' + """Recipe for projects which contain `pyproject.toml`""" # Extra args to pass to `python -m build ...` extra_build_args = [] diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 1347038b8..92d13da86 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -29,7 +29,7 @@ from pythonforandroid import __version__ from pythonforandroid.bootstrap import Bootstrap -from pythonforandroid.build import Context, build_recipes +from pythonforandroid.build import Context, build_recipes, project_has_setup_py from pythonforandroid.distribution import Distribution, pretty_log_dists from pythonforandroid.entrypoints import main from pythonforandroid.graph import get_recipe_order_and_bootstrap @@ -569,18 +569,18 @@ def add_parser(subparsers, *args, **kwargs): args, unknown = parser.parse_known_args(sys.argv[1:]) args.unknown_args = unknown - if hasattr(args, "private") and args.private is not None: + if getattr(args, "private", None) is not None: # Pass this value on to the internal bootstrap build.py: args.unknown_args += ["--private", args.private] - if hasattr(args, "build_mode") and args.build_mode == "release": + if getattr(args, "build_mode", None) == "release": args.unknown_args += ["--release"] - if hasattr(args, "with_debug_symbols") and args.with_debug_symbols: + if getattr(args, "with_debug_symbols", False): args.unknown_args += ["--with-debug-symbols"] - if hasattr(args, "ignore_setup_py") and args.ignore_setup_py: + if getattr(args, "ignore_setup_py", False): args.use_setup_py = False - if hasattr(args, "activity_class_name") and args.activity_class_name != 'org.kivy.android.PythonActivity': + if getattr(args, "activity_class_name", "org.kivy.android.PythonActivity") != 'org.kivy.android.PythonActivity': args.unknown_args += ["--activity-class-name", args.activity_class_name] - if hasattr(args, "service_class_name") and args.service_class_name != 'org.kivy.android.PythonService': + if getattr(args, "service_class_name", "org.kivy.android.PythonService") != 'org.kivy.android.PythonService': args.unknown_args += ["--service-class-name", args.service_class_name] self.args = args @@ -603,21 +603,13 @@ def add_parser(subparsers, *args, **kwargs): args, "with_debug_symbols", False ) - have_setup_py_or_similar = False - if getattr(args, "private", None) is not None: - project_dir = getattr(args, "private") - if (os.path.exists(os.path.join(project_dir, "setup.py")) or - os.path.exists(os.path.join(project_dir, - "pyproject.toml"))): - have_setup_py_or_similar = True - # Process requirements and put version in environ if hasattr(args, 'requirements'): requirements = [] # Add dependencies from setup.py, but only if they are recipes # (because otherwise, setup.py itself will install them later) - if (have_setup_py_or_similar and + if (project_has_setup_py(getattr(args, "private", None)) and getattr(args, "use_setup_py", False)): try: info("Analyzing package dependencies. MAY TAKE A WHILE.") @@ -698,10 +690,7 @@ def warn_on_deprecated_args(self, args): # Output warning if setup.py is present and neither --ignore-setup-py # nor --use-setup-py was specified. - if getattr(args, "private", None) is not None and \ - (os.path.exists(os.path.join(args.private, "setup.py")) or - os.path.exists(os.path.join(args.private, "pyproject.toml")) - ): + if project_has_setup_py(getattr(args, "private", None)): if not getattr(args, "use_setup_py", False) and \ not getattr(args, "ignore_setup_py", False): warning(" **** FUTURE BEHAVIOR CHANGE WARNING ****")