3

I am facing a problem where I have to change a line in a built-in file in a particular library (installed using pip). I have located the file in

app\build\pip\debug\common\<library folder>

But every time I run the Gradle (for installing or creating APK), the entire folder is recreated, and hence, the file is again the same as previous.

Is there any way to make the change permanent?

George
  • 255
  • 8
  • 1
    Try monkey patching. More info here: https://stackoverflow.com/questions/5626193/what-is-monkey-patching – David K. Hess May 24 '23 at 18:29
  • Is it even possible to monkey patch a chaquopy code as Android does not provide a native Python Interface? – George May 24 '23 at 18:36
  • @George: The entire point of Chaquopy is to provide a Python interface for Android, and it supports all the usual Python programming techniques, including monkey patching. However, if monkey patching isn't suitable for your problem, see my answer below. – mhsmith May 24 '23 at 20:27

1 Answers1

1

As mentioned in the comment by David K Hess, monkey patching may be the easiest solution.

If monkey patching isn't suitable for your issue, then assuming the library is pure-Python, you can download it from PyPI, edit your local copy, and then install from that:

  • For example, you could download a .whl file, edit the file inside it, and then add an install line pointing to the .whl.

  • Or you could download an sdist (.tar.gz file), extract it to a directory, edit the file inside it, and then add an install line pointing to the directory.

In both cases, the install line should probably come first in the requirements list, before anything else which may depend on the library.

mhsmith
  • 6,675
  • 3
  • 41
  • 58