Repository: kivy/buildozer

Issue:
Cannot tell p4a to use/not to use distutils integration
<!--
The issue tracker is a tool to address bugs.
For support questions, please use: https://github.com/kivy/buildozer#support

Before opening a new issue, make sure you do the following:
    * check that your issue isn't already filed: https://github.com/kivy/buildozer/issues
    * prepare a short, runnable example that reproduces the issue
    * make sure to have `log_level = 2` in your `buildozer.spec`
    * reproduce the problem with the latest development version of Kivy
    * double-check that the issue is indeed a bug and not a support request
-->

### Versions

* Python: 3.7
* OS: Ubuntu 20.04 
* Buildozer: git master (and pypi 1.2.0)

### Description

Cannot tell p4a to use distutils support (https://python-for-android.readthedocs.io/en/latest/distutils/) since there
is no way to pass the argument.

Also in the future p4a is going to default to enabling distutils support (now defaults to disabled) so in the future
things will behave differently unless the corresponding option is explicitly passed to p4a



Comments:

Patch:
diff --git a/buildozer/default.spec b/buildozer/default.spec
index 612f79e..b33a62d 100644
--- a/buildozer/default.spec
+++ b/buildozer/default.spec
@@ -256,6 +256,13 @@ android.allow_backup = True
 # (int) port number to specify an explicit --port= p4a argument (eg for bootstrap flask)
 #p4a.port =
 
+# Control passing the --use-setup-py vs --ignore-setup-py to p4a
+# "in the future" --use-setup-py is going to be the default behaviour in p4a, right now it is not
+# Setting this to false will pass --ignore-setup-py, true will pass --use-setup-py
+# NOTE: this is general setuptools integration, having pyproject.toml is enough, no need to generate
+# setup.py if you're using Poetry, but you need to add "toml" to source.include_exts.
+#p4a.setup_py = false
+
 
 #
 # iOS specific
diff --git a/buildozer/targets/android.py b/buildozer/targets/android.py
index 6d9be36..b8738bf 100644
--- a/buildozer/targets/android.py
+++ b/buildozer/targets/android.py
@@ -92,6 +92,12 @@ class TargetAndroid(Target):
         if port is not None:
             self.extra_p4a_args += ' --port={}'.format(port)
 
+        setup_py = self.buildozer.config.getdefault('app', 'p4a.setup_py', False)
+        if setup_py:
+            self.extra_p4a_args += ' --use-setup-py'
+        else:
+            self.extra_p4a_args += ' --ignore-setup-py'
+
         self.warn_on_deprecated_tokens()
 
     def warn_on_deprecated_tokens(self):


Test patch:
diff --git a/tests/targets/test_android.py b/tests/targets/test_android.py
index 09af719..6e127bc 100644
--- a/tests/targets/test_android.py
+++ b/tests/targets/test_android.py
@@ -115,7 +115,7 @@ class TestTargetAndroid:
         assert (
             target_android.extra_p4a_args == (
                 ' --color=always'
-                ' --storage-dir="{buildozer_dir}/android/platform/build-armeabi-v7a" --ndk-api=21'.format(
+                ' --storage-dir="{buildozer_dir}/android/platform/build-armeabi-v7a" --ndk-api=21 --ignore-setup-py'.format(
                 buildozer_dir=buildozer.buildozer_dir)
             )
         )