Skip to content

Commit

Permalink
Merge pull request #3054 from AndreMiras/feature/minor_refactoring
Browse files Browse the repository at this point in the history
♻️ Minor code cleaning
  • Loading branch information
AndreMiras authored Aug 30, 2024
2 parents 851891d + 74b891e commit 08713b3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
8 changes: 2 additions & 6 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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."
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions pythonforandroid/pythonpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
29 changes: 9 additions & 20 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.")
Expand Down Expand Up @@ -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 ****")
Expand Down

0 comments on commit 08713b3

Please sign in to comment.